mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
First start of refactoring field ph out of class Packer.
This commit is contained in:
parent
0dc03214c5
commit
8ab3e63aeb
|
@ -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;
|
||||
if (level > 1)
|
||||
if (ph.level > 1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Packer::skipVerify() const
|
||||
{
|
||||
return skipVerify(ph.method, ph.level);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// 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);
|
||||
if (!checkCompressionRatio(ph.u_len, ph.c_len))
|
||||
if (checkCompressionRatio(ph.u_len, ph.c_len))
|
||||
return false;
|
||||
// return in any case if not compressible
|
||||
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
|
||||
ph.c_adler = upx_adler32(out, ph.c_len, ph.c_adler);
|
||||
// Decompress and verify. Skip this when using the fastest level.
|
||||
if (!skipVerify())
|
||||
if (!ph_skipVerify(ph))
|
||||
{
|
||||
// decompress
|
||||
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
|
||||
{
|
||||
assert((int)u_len > 0);
|
||||
|
@ -303,8 +307,8 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const
|
|||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
void Packer::decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum, Filter *ft)
|
||||
void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum, Filter *ft)
|
||||
{
|
||||
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
|
||||
**************************************************************************/
|
||||
|
||||
bool Packer::testOverlappingDecompression(const upx_bytep buf,
|
||||
unsigned overlap_overhead) const
|
||||
bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
||||
unsigned overlap_overhead)
|
||||
{
|
||||
if (ph.c_len >= ph.u_len)
|
||||
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)
|
||||
{
|
||||
assert(ph.c_len < ph.u_len);
|
||||
|
@ -384,7 +402,7 @@ void Packer::verifyOverlappingDecompression(Filter *ft)
|
|||
// See also:
|
||||
// Filter::verifyUnfilter()
|
||||
|
||||
if (skipVerify())
|
||||
if (ph_skipVerify(ph))
|
||||
return;
|
||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||
if (offset + ph.c_len > obuf.getSize())
|
||||
|
|
10
src/packer.h
10
src/packer.h
|
@ -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
|
||||
//
|
||||
|
@ -140,9 +147,6 @@ protected:
|
|||
// unpacker tests - these may throw exceptions
|
||||
virtual bool testUnpackVersion(int version) const;
|
||||
virtual bool testUnpackFormat(int format) const;
|
||||
//
|
||||
virtual bool skipVerify(int method, int level) const;
|
||||
virtual bool skipVerify() const;
|
||||
|
||||
protected:
|
||||
// implementation
|
||||
|
|
Loading…
Reference in New Issue
Block a user