Added Packer::checkAlreadyPacked().
committer: mfx <mfx> 977427988 +0000
This commit is contained in:
parent
facca7b891
commit
046df6da76
@ -72,14 +72,13 @@ bool PackCom::canPack()
|
||||
{
|
||||
unsigned char buf[128];
|
||||
|
||||
fi->readx(buf,128);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
if (memcmp(buf,"MZ",2) == 0 || memcmp(buf,"ZM",2) == 0 // .exe
|
||||
|| memcmp (buf,"\xff\xff\xff\xff",4) == 0) // .sys
|
||||
return false;
|
||||
if (!fn_has_ext(fi->getName(),"com"))
|
||||
return false;
|
||||
if (find_le32(buf,128,UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
if (file_size < 1024)
|
||||
throwCantPack("file is too small");
|
||||
if (file_size > 0xFF00)
|
||||
|
||||
@ -264,8 +264,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
fi->seek(ih.headsize16*16,SEEK_SET);
|
||||
fi->readx(ibuf,imagesize);
|
||||
|
||||
if (find_le32(ibuf, UPX_MIN(imagesize, 127u), UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
checkAlreadyPacked(ibuf, UPX_MIN(imagesize, 127u));
|
||||
|
||||
// relocations
|
||||
has_9a = false;
|
||||
|
||||
@ -45,13 +45,12 @@ bool PackSys::canPack()
|
||||
{
|
||||
unsigned char buf[128];
|
||||
|
||||
fi->readx(buf,128);
|
||||
fi->readx(buf, sizeof(buf));
|
||||
if (memcmp (buf,"\xff\xff\xff\xff",4) != 0)
|
||||
return false;
|
||||
if (!fn_has_ext(fi->getName(),"sys"))
|
||||
return false;
|
||||
if (find_le32(buf,128,UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
if (file_size < 1024)
|
||||
throwCantPack("file is too small");
|
||||
if (file_size > 0x10000)
|
||||
|
||||
@ -295,9 +295,8 @@ bool PackTos::canPack()
|
||||
return false;
|
||||
|
||||
unsigned char buf[512];
|
||||
fi->readx(buf,sizeof(buf));
|
||||
if (find_le32(buf,sizeof(buf),UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
fi->readx(buf, sizeof(buf));
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
|
||||
if (!checkFileHeader())
|
||||
throwCantPack("unsupported header flags");
|
||||
|
||||
@ -68,9 +68,8 @@ bool PackUnix::canPack()
|
||||
// info: currently the header is 36 (32+4) bytes before EOF
|
||||
unsigned char buf[256];
|
||||
fi->seek(-(long)sizeof(buf), SEEK_END);
|
||||
fi->readx(buf,sizeof(buf));
|
||||
if (find_le32(buf,sizeof(buf),UPX_MAGIC_LE32) >= 0) // note: always le32
|
||||
throwAlreadyPacked();
|
||||
fi->readx(buf, sizeof(buf));
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -123,8 +123,7 @@ int PackVmlinuzI386::uncompressKernel()
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(obuf, file_size);
|
||||
|
||||
if (find_le32(obuf + setup_size, UPX_MIN(file_size - setup_size, 1024), UPX_MAGIC_LE32) >= 0)
|
||||
throwAlreadyPacked();
|
||||
checkAlreadyPacked(obuf + setup_size, UPX_MIN(file_size - setup_size, 1024));
|
||||
|
||||
// estimate gzip-uncompressed kernel size & alloc buffer
|
||||
ibuf.alloc((file_size - setup_size) * 3);
|
||||
|
||||
@ -643,6 +643,27 @@ bool Packer::readPackHeader(int len)
|
||||
}
|
||||
|
||||
|
||||
void Packer::checkAlreadyPacked(void *b, int blen)
|
||||
{
|
||||
int boff = find_le32(b, blen, UPX_MAGIC_LE32);
|
||||
if (boff < 0)
|
||||
return;
|
||||
|
||||
// FIXME: could add some more checks to verify that this
|
||||
// is a real PackHeader, e.g.
|
||||
//
|
||||
//PackHeader tmp;
|
||||
//tmp.magic = UPX_MAGIC_LE32;
|
||||
//if (!tmp.fillPackHeader((unsigned char *)b + boff, blen - boff))
|
||||
// return;
|
||||
//
|
||||
// This also would require that the buffer in `b' holds
|
||||
// the full PackHeader, and not only the magic.
|
||||
|
||||
throwAlreadyPacked();
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// patch util for loader
|
||||
**************************************************************************/
|
||||
|
||||
@ -182,6 +182,7 @@ protected:
|
||||
virtual int patchPackHeader(void *b, int blen);
|
||||
virtual bool getPackHeader(void *b, int blen);
|
||||
virtual bool readPackHeader(int len);
|
||||
virtual void checkAlreadyPacked(void *b, int blen);
|
||||
|
||||
// filter handling
|
||||
virtual bool isValidFilter(int filter_id) const;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user