Added Packer::checkFinalCompressionRatio().
committer: mfx <mfx> 976775892 +0000
This commit is contained in:
@@ -221,6 +221,10 @@ void PackCom::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// verify
|
// verify
|
||||||
verifyOverlappingDecompression(&obuf, overlapoh);
|
verifyOverlappingDecompression(&obuf, overlapoh);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -368,6 +368,10 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||||||
// handle overlay
|
// handle overlay
|
||||||
// FIXME: only Allegro pakfiles are supported
|
// FIXME: only Allegro pakfiles are supported
|
||||||
handle_allegropak(fi,fo);
|
handle_allegropak(fi,fo);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -516,6 +516,10 @@ void PackExe::pack(OutputFile *fo)
|
|||||||
// copy the overlay
|
// copy the overlay
|
||||||
copyOverlay(fo, overlay, &obuf);
|
copyOverlay(fo, overlay, &obuf);
|
||||||
//fprintf (stderr,"%x %x\n",relocsize,ph.u_len);
|
//fprintf (stderr,"%x %x\n",relocsize,ph.u_len);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -360,8 +360,8 @@ void PackLinuxI386elf::pack(OutputFile *fo)
|
|||||||
|
|
||||||
updateLoader(fo);
|
updateLoader(fo);
|
||||||
|
|
||||||
// finally check compression ratio
|
// finally check the compression ratio
|
||||||
if (!super::checkCompressionRatio(ph.u_len, fo->getBytesWritten()))
|
if (!checkFinalCompressionRatio(fo))
|
||||||
throwNotCompressible();
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -263,6 +263,10 @@ void PackTmt::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// copy the overlay
|
// copy the overlay
|
||||||
copyOverlay(fo, overlay, &obuf);
|
copyOverlay(fo, overlay, &obuf);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -542,6 +542,10 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// copy the overlay
|
// copy the overlay
|
||||||
copyOverlay(fo, overlay, &obuf);
|
copyOverlay(fo, overlay, &obuf);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -196,8 +196,8 @@ void PackUnix::pack(OutputFile *fo)
|
|||||||
|
|
||||||
updateLoader(fo);
|
updateLoader(fo);
|
||||||
|
|
||||||
// finally check compression ratio
|
// finally check the compression ratio
|
||||||
if (!Packer::checkCompressionRatio(ph.u_len, fo->getBytesWritten()))
|
if (!checkFinalCompressionRatio(fo))
|
||||||
throwNotCompressible();
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+29
-20
@@ -71,11 +71,17 @@ const int *PackVmlinuzI386::getFilters() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PackVmlinuzI386::canPack()
|
||||||
|
{
|
||||||
|
return readFileHeader() == getFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// common routines
|
// common util routines
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int PackVmlinuzI386::readHeader()
|
int PackVmlinuzI386::readFileHeader()
|
||||||
{
|
{
|
||||||
boot_sect_t h;
|
boot_sect_t h;
|
||||||
|
|
||||||
@@ -95,7 +101,7 @@ int PackVmlinuzI386::readHeader()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read kernel into obuf, gzip-uncompress into ibuf,
|
// read full kernel into obuf, gzip-uncompress into ibuf,
|
||||||
// return uncompressed size
|
// return uncompressed size
|
||||||
int PackVmlinuzI386::uncompressKernel()
|
int PackVmlinuzI386::uncompressKernel()
|
||||||
{
|
{
|
||||||
@@ -147,8 +153,9 @@ void PackVmlinuzI386::readKernel()
|
|||||||
if (klen <= 0)
|
if (klen <= 0)
|
||||||
throwCantPack("kernel decompression failed");
|
throwCantPack("kernel decompression failed");
|
||||||
|
|
||||||
// OutputFile::dump("kernel.img", ibuf, ulen);
|
//OutputFile::dump("kernel.img", ibuf, klen);
|
||||||
|
|
||||||
|
// copy the setup boot code
|
||||||
setup_buf.alloc(setup_size);
|
setup_buf.alloc(setup_size);
|
||||||
memcpy(setup_buf, obuf, setup_size);
|
memcpy(setup_buf, obuf, setup_size);
|
||||||
|
|
||||||
@@ -163,12 +170,6 @@ void PackVmlinuzI386::readKernel()
|
|||||||
// vmlinuz specific
|
// vmlinuz specific
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackVmlinuzI386::canPack()
|
|
||||||
{
|
|
||||||
return readHeader() == UPX_F_VMLINUZ_i386;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PackVmlinuzI386::pack(OutputFile *fo)
|
void PackVmlinuzI386::pack(OutputFile *fo)
|
||||||
{
|
{
|
||||||
readKernel();
|
readKernel();
|
||||||
@@ -203,9 +204,15 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
|||||||
fo->write(setup_buf, setup_buf.getSize());
|
fo->write(setup_buf, setup_buf.getSize());
|
||||||
fo->write(loader, lsize);
|
fo->write(loader, lsize);
|
||||||
fo->write(obuf, clen);
|
fo->write(obuf, clen);
|
||||||
|
#if 0
|
||||||
|
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||||
|
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||||
|
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) clen);
|
||||||
|
#endif
|
||||||
|
|
||||||
//if (!checkCompressionRatio(file_size, fo->getBytesWritten()))
|
// finally check the compression ratio
|
||||||
// throwNotCompressible();
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -213,12 +220,6 @@ void PackVmlinuzI386::pack(OutputFile *fo)
|
|||||||
// bvmlinuz specific
|
// bvmlinuz specific
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackBvmlinuzI386::canPack()
|
|
||||||
{
|
|
||||||
return readHeader() == UPX_F_BVMLINUZ_i386;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PackBvmlinuzI386::pack(OutputFile *fo)
|
void PackBvmlinuzI386::pack(OutputFile *fo)
|
||||||
{
|
{
|
||||||
readKernel();
|
readKernel();
|
||||||
@@ -277,12 +278,19 @@ void PackBvmlinuzI386::pack(OutputFile *fo)
|
|||||||
fo->write(loader, e_len);
|
fo->write(loader, e_len);
|
||||||
fo->write(obuf, clen);
|
fo->write(obuf, clen);
|
||||||
fo->write(loader + e_len, lsize - e_len);
|
fo->write(loader + e_len, lsize - e_len);
|
||||||
|
#if 0
|
||||||
|
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||||
|
printf("%-13s: entry : %8ld bytes\n", getName(), (long) e_len);
|
||||||
|
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) clen);
|
||||||
|
printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) (lsize - e_len));
|
||||||
|
#endif
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
verifyOverlappingDecompression(&obuf, overlapoh);
|
verifyOverlappingDecompression(&obuf, overlapoh);
|
||||||
|
|
||||||
//if (!checkCompressionRatio(file_size, fo->getBytesWritten()))
|
// finally check the compression ratio
|
||||||
// throwNotCompressible();
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -295,6 +303,7 @@ int PackVmlinuzI386::canUnpack()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PackVmlinuzI386::unpack(OutputFile *)
|
void PackVmlinuzI386::unpack(OutputFile *)
|
||||||
{
|
{
|
||||||
// no uncompression support for this format, so that
|
// no uncompression support for this format, so that
|
||||||
|
|||||||
+1
-3
@@ -52,7 +52,7 @@ public:
|
|||||||
virtual int canUnpack();
|
virtual int canUnpack();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int readHeader();
|
virtual int readFileHeader();
|
||||||
virtual int uncompressKernel();
|
virtual int uncompressKernel();
|
||||||
virtual void readKernel();
|
virtual void readKernel();
|
||||||
|
|
||||||
@@ -98,8 +98,6 @@ public:
|
|||||||
virtual const char *getName() const { return "bvmlinuz/386"; }
|
virtual const char *getName() const { return "bvmlinuz/386"; }
|
||||||
|
|
||||||
virtual void pack(OutputFile *fo);
|
virtual void pack(OutputFile *fo);
|
||||||
|
|
||||||
virtual bool canPack();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1902,8 +1902,8 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||||||
// copy the overlay
|
// copy the overlay
|
||||||
copyOverlay(fo, overlay, &obuf);
|
copyOverlay(fo, overlay, &obuf);
|
||||||
|
|
||||||
// finally check compresion ratio
|
// finally check the compression ratio
|
||||||
if (!checkCompressionRatio(file_size, fo->getBytesWritten()))
|
if (!checkFinalCompressionRatio(fo))
|
||||||
throwNotCompressible();
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -544,6 +544,10 @@ void PackWcle::pack(OutputFile *fo)
|
|||||||
const unsigned overlay = file_size - overlaystart - ih.non_resident_name_table_length;
|
const unsigned overlay = file_size - overlaystart - ih.non_resident_name_table_length;
|
||||||
checkOverlay(overlay);
|
checkOverlay(overlay);
|
||||||
copyOverlay(fo, overlay, &oimage);
|
copyOverlay(fo, overlay, &oimage);
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+18
-3
@@ -260,9 +260,9 @@ bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const
|
|||||||
//assert((off_t)u_len < file_size);
|
//assert((off_t)u_len < file_size);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
if (c_len >= u_len - u_len / 8) // min. 12.5% gain
|
if (c_len + 512 >= u_len) // min. 512 bytes gain
|
||||||
return false;
|
return false;
|
||||||
if (c_len + 512 >= u_len) // min. 512 bytes gain
|
if (c_len >= u_len - u_len / 8) // min. 12.5% gain
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
if (c_len >= u_len)
|
if (c_len >= u_len)
|
||||||
@@ -272,6 +272,21 @@ bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
|
||||||
|
{
|
||||||
|
unsigned u_len = file_size;
|
||||||
|
unsigned c_len = fo->getBytesWritten();
|
||||||
|
|
||||||
|
assert((int)u_len > 0);
|
||||||
|
assert((int)c_len > 0);
|
||||||
|
|
||||||
|
if (c_len + 4096 <= u_len) // ok if we have 4096 bytes gain
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return checkCompressionRatio(u_len, c_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
@@ -350,7 +365,7 @@ void Packer::verifyOverlappingDecompression(MemBuffer *buf,
|
|||||||
// buf was allocated with MemBuffer.allocForCompression(), and
|
// buf was allocated with MemBuffer.allocForCompression(), and
|
||||||
// its contents are no longer needed, i.e. the compressed data
|
// its contents are no longer needed, i.e. the compressed data
|
||||||
// must have been already written.
|
// must have been already written.
|
||||||
// We now could performa a real overlapping decompression and
|
// We now could perform a real overlapping decompression and
|
||||||
// verify the checksum.
|
// verify the checksum.
|
||||||
//
|
//
|
||||||
// Note:
|
// Note:
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ protected:
|
|||||||
virtual void decompress(const upx_bytep in,
|
virtual void decompress(const upx_bytep in,
|
||||||
upx_bytep out, bool verify_checksum=true);
|
upx_bytep out, bool verify_checksum=true);
|
||||||
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||||
|
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
|
||||||
|
|
||||||
// high-level compression drivers
|
// high-level compression drivers
|
||||||
void compressWithFilters(Filter *ft, unsigned *overlapoh,
|
void compressWithFilters(Filter *ft, unsigned *overlapoh,
|
||||||
|
|||||||
Reference in New Issue
Block a user