First start of refactoring field ph out of class Packer.
This commit is contained in:
+32
-14
@@ -138,20 +138,15 @@ bool Packer::testUnpackFormat(int format) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Packer::skipVerify(int method, int level) const
|
bool ph_skipVerify(const PackHeader &ph)
|
||||||
{
|
{
|
||||||
if (method == M_LZMA)
|
if (ph.method == M_LZMA)
|
||||||
return false;
|
return false;
|
||||||
if (level > 1)
|
if (ph.level > 1)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Packer::skipVerify() const
|
|
||||||
{
|
|
||||||
return skipVerify(ph.method, ph.level);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// compress - wrap call to low-level upx_compress()
|
// compress - wrap call to low-level upx_compress()
|
||||||
@@ -233,7 +228,7 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//printf("\nPacker::compress: %d/%d: %7d -> %7d\n", ph.method, ph.level, ph.u_len, ph.c_len);
|
//printf("\nPacker::compress: %d/%d: %7d -> %7d\n", ph.method, ph.level, ph.u_len, ph.c_len);
|
||||||
if (!checkCompressionRatio(ph.u_len, ph.c_len))
|
if (checkCompressionRatio(ph.u_len, ph.c_len))
|
||||||
return false;
|
return false;
|
||||||
// return in any case if not compressible
|
// return in any case if not compressible
|
||||||
if (ph.c_len >= ph.u_len)
|
if (ph.c_len >= ph.u_len)
|
||||||
@@ -242,7 +237,7 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||||||
// update checksum of compressed data
|
// update checksum of compressed data
|
||||||
ph.c_adler = upx_adler32(out, ph.c_len, ph.c_adler);
|
ph.c_adler = upx_adler32(out, ph.c_len, ph.c_adler);
|
||||||
// Decompress and verify. Skip this when using the fastest level.
|
// Decompress and verify. Skip this when using the fastest level.
|
||||||
if (!skipVerify())
|
if (!ph_skipVerify(ph))
|
||||||
{
|
{
|
||||||
// decompress
|
// decompress
|
||||||
unsigned new_len = ph.u_len;
|
unsigned new_len = ph.u_len;
|
||||||
@@ -261,6 +256,15 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
bool Packer::compress(upx_bytep in, upx_bytep out,
|
||||||
|
const upx_compress_config_t *cconf)
|
||||||
|
{
|
||||||
|
return ph_compress(ph, in, out, cconf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const
|
bool Packer::checkCompressionRatio(unsigned u_len, unsigned c_len) const
|
||||||
{
|
{
|
||||||
assert((int)u_len > 0);
|
assert((int)u_len > 0);
|
||||||
@@ -303,7 +307,7 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
|
|||||||
// decompress
|
// decompress
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void Packer::decompress(const upx_bytep in, upx_bytep out,
|
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
|
||||||
bool verify_checksum, Filter *ft)
|
bool verify_checksum, Filter *ft)
|
||||||
{
|
{
|
||||||
unsigned adler;
|
unsigned adler;
|
||||||
@@ -335,12 +339,19 @@ void Packer::decompress(const upx_bytep in, upx_bytep out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||||
|
bool verify_checksum, Filter *ft)
|
||||||
|
{
|
||||||
|
ph_decompress(ph, in, out, verify_checksum, ft);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// overlapping decompression
|
// overlapping decompression
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
||||||
unsigned overlap_overhead) const
|
unsigned overlap_overhead)
|
||||||
{
|
{
|
||||||
if (ph.c_len >= ph.u_len)
|
if (ph.c_len >= ph.u_len)
|
||||||
return false;
|
return false;
|
||||||
@@ -365,6 +376,13 @@ bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||||
|
unsigned overlap_overhead) const
|
||||||
|
{
|
||||||
|
return ph_testOverlappingDecompression(ph, buf, overlap_overhead);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Packer::verifyOverlappingDecompression(Filter *ft)
|
void Packer::verifyOverlappingDecompression(Filter *ft)
|
||||||
{
|
{
|
||||||
assert(ph.c_len < ph.u_len);
|
assert(ph.c_len < ph.u_len);
|
||||||
@@ -384,7 +402,7 @@ void Packer::verifyOverlappingDecompression(Filter *ft)
|
|||||||
// See also:
|
// See also:
|
||||||
// Filter::verifyUnfilter()
|
// Filter::verifyUnfilter()
|
||||||
|
|
||||||
if (skipVerify())
|
if (ph_skipVerify(ph))
|
||||||
return;
|
return;
|
||||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||||
if (offset + ph.c_len > obuf.getSize())
|
if (offset + ph.c_len > obuf.getSize())
|
||||||
|
|||||||
+7
-3
@@ -99,6 +99,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bool ph_skipVerify(const PackHeader &ph);
|
||||||
|
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
|
||||||
|
bool verify_checksum, Filter *ft);
|
||||||
|
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
||||||
|
unsigned overlap_overhead);
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// abstract base class for packers
|
// abstract base class for packers
|
||||||
//
|
//
|
||||||
@@ -140,9 +147,6 @@ protected:
|
|||||||
// unpacker tests - these may throw exceptions
|
// unpacker tests - these may throw exceptions
|
||||||
virtual bool testUnpackVersion(int version) const;
|
virtual bool testUnpackVersion(int version) const;
|
||||||
virtual bool testUnpackFormat(int format) const;
|
virtual bool testUnpackFormat(int format) const;
|
||||||
//
|
|
||||||
virtual bool skipVerify(int method, int level) const;
|
|
||||||
virtual bool skipVerify() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// implementation
|
// implementation
|
||||||
|
|||||||
Reference in New Issue
Block a user