I have the code that checks whether the file is zipped with the password "infected or not"? It works fine when the file is a single or standalone executable/application that is zipped with password infected.
It doesn't work properly when there is a lot of files and zipped together with password "infected".
const verifyZip = async (file, password, id) => {
let reader;
try {
reader = new zip.ZipReader(new zip.BlobReader(file), { password });
const entries = await reader.getEntries();
if (entries[0].encrypted) {
for (const entry of entries) {
try {
// await entry.getData(new zip.BlobWriter(),
await entry.getData(new zip.BlobWriter(),
{
onprogress: (index, max)=>{
zip.BlobWriter.$cancel()
reader.close()
}
});
} catch (error) {
if (error.message === zip.ERR_ENCRYPTED ||
error.message === zip.ERR_INVALID_PASSWORD) {
alert(file.name +" incorrect password, zip file will not be uploaded.")
// myFunction(file,id)
uploader.removeFile(id)
map.remove(id);
// $('#' + file.id).find('td.zip').text('zip file is invalid');
return false;
} else {
throw error;
}
}
}
}else{
alert(file.name + " zip file does not have a password please enter the appropriate password and upload again.")
uploader.removeFile(id)
map.remove(id);
// myFunction(file,id)
}} finally {
// await reader.close();
reader.close();
}
return true;
};
if (fileSuffix==="zip"){
verifyZip(file.source.source, "infected",file.id)
}