mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Refactoring: pass upx_compress_config_t to Packer::compressWithFilters()
so that formats can set conf_lzma.max_num_probs. Also renamed compression parameters to use cconf & cresult.
This commit is contained in:
parent
c7bf0b6ddd
commit
66df7389d2
|
@ -76,11 +76,11 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
struct upx_compress_result_t *result )
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
upx_compress_result_t result_buffer;
|
||||
upx_compress_result_t cresult_buffer;
|
||||
|
||||
assert(method > 0); assert(level > 0);
|
||||
|
||||
|
@ -95,18 +95,18 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
// for UPX, we always require a reasonably sized outbut buffer
|
||||
assert(*dst_len >= MemBuffer::getSizeForCompression(src_len));
|
||||
|
||||
if (!result)
|
||||
result = &result_buffer;
|
||||
memset(result, 0, sizeof(*result));
|
||||
if (!cresult)
|
||||
cresult = &cresult_buffer;
|
||||
memset(cresult, 0, sizeof(*cresult));
|
||||
#if 1
|
||||
// debug
|
||||
result->method = method;
|
||||
result->level = level;
|
||||
result->u_len = src_len;
|
||||
result->c_len = 0;
|
||||
cresult->method = method;
|
||||
cresult->level = level;
|
||||
cresult->u_len = src_len;
|
||||
cresult->c_len = 0;
|
||||
#endif
|
||||
// assume no info available - fill in worst case results
|
||||
ucl_uint *res = result->result_ucl.result;
|
||||
ucl_uint *res = cresult->result_ucl.result;
|
||||
//res[0] = 1; // min_offset_found - NOT USED
|
||||
res[1] = src_len - 1; // max_offset_found
|
||||
//res[2] = 2; // min_match_found - NOT USED
|
||||
|
@ -121,17 +121,17 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
#if defined(WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, conf, result);
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, conf, result);
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, conf, result);
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown compression method");
|
||||
|
@ -139,7 +139,7 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
|
||||
#if 1
|
||||
// debug
|
||||
result->c_len = *dst_len;
|
||||
cresult->c_len = *dst_len;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
@ -152,29 +152,29 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
assert(*dst_len > 0);
|
||||
assert(src_len < *dst_len); // must be compressed
|
||||
|
||||
if (result && result->method == 0)
|
||||
result = NULL;
|
||||
if (cresult && cresult->method == 0)
|
||||
cresult = NULL;
|
||||
|
||||
if (method < 0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, result);
|
||||
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, result);
|
||||
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, result);
|
||||
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown decompression method");
|
||||
|
@ -191,12 +191,12 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
|||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
|
||||
if (result && result->method == 0)
|
||||
result = NULL;
|
||||
if (cresult && cresult->method == 0)
|
||||
cresult = NULL;
|
||||
|
||||
assert(*dst_len > 0);
|
||||
assert(src_len < *dst_len); // must be compressed
|
||||
|
@ -207,15 +207,15 @@ int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
|||
}
|
||||
#if defined(WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method, result);
|
||||
r = upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_test_overlap(buf, src_off, src_len, dst_len, method, result);
|
||||
r = upx_nrv_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_test_overlap(buf, src_off, src_len, dst_len, method, result);
|
||||
r = upx_ucl_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown decompression method");
|
||||
|
|
|
@ -39,16 +39,16 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
struct upx_compress_result_t *result );
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult );
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -57,16 +57,16 @@ int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
struct upx_compress_result_t *result );
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult );
|
||||
int upx_nrv_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_nrv_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -75,16 +75,16 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
struct upx_compress_result_t *result );
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult );
|
||||
int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -155,15 +155,15 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
struct upx_compress_result_t *result )
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
assert(level > 0); assert(result != NULL);
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
HRESULT rh;
|
||||
lzma_compress_result_t *res = &result->result_lzma;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
|
||||
MyLzma::InStreamRam is; is.AddRef();
|
||||
MyLzma::OutStreamRam os; os.AddRef();
|
||||
|
@ -196,9 +196,9 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
pr[5].uintVal = 64; // 5..
|
||||
pr[6].uintVal = 0;
|
||||
#if 1
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack
|
||||
// these settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MB of stack
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MB of stack during runtime decompression.
|
||||
pr[1].uintVal = 4;
|
||||
pr[2].uintVal = 8;
|
||||
#endif
|
||||
|
@ -239,12 +239,12 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
pr[3].uintVal = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (conf_parm && conf_parm->conf_lzma.max_num_probs)
|
||||
if (cconf_parm && cconf_parm->conf_lzma.max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
if (n <= conf_parm->conf_lzma.max_num_probs)
|
||||
if (n <= cconf_parm->conf_lzma.max_num_probs)
|
||||
break;
|
||||
if (pr[1].uintVal > pr[2].uintVal)
|
||||
{
|
||||
|
@ -350,7 +350,7 @@ error:
|
|||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
// see res->num_probs above
|
||||
|
@ -384,13 +384,13 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
|||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
|
||||
if (result)
|
||||
if (cresult)
|
||||
{
|
||||
assert(result->method == method);
|
||||
assert(result->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
||||
assert(result->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(result->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(result->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
|
||||
assert(cresult->method == method);
|
||||
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
||||
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
|
||||
}
|
||||
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
|
||||
if (!s.Probs)
|
||||
|
@ -412,7 +412,7 @@ error:
|
|||
*dst_len = dst_out;
|
||||
free(s.Probs);
|
||||
|
||||
UNUSED(result);
|
||||
UNUSED(cresult);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ error:
|
|||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
|
||||
|
@ -438,7 +438,7 @@ int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
|||
if ((int)overlap_overhead >= 256)
|
||||
return UPX_E_OK;
|
||||
|
||||
UNUSED(result);
|
||||
UNUSED(cresult);
|
||||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,11 +101,11 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb_parm,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
struct upx_compress_result_t *result )
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
int r;
|
||||
assert(level > 0); assert(result != NULL);
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
|
||||
ucl_progress_callback_t cb;
|
||||
cb.callback = 0;
|
||||
|
@ -115,20 +115,20 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|||
cb.user = cb_parm;
|
||||
}
|
||||
|
||||
ucl_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
if (conf_parm)
|
||||
conf = conf_parm->conf_ucl; // struct copy
|
||||
ucl_compress_config_t cconf;
|
||||
memset(&cconf, 0xff, sizeof(cconf));
|
||||
if (cconf_parm)
|
||||
cconf = cconf_parm->conf_ucl; // struct copy
|
||||
|
||||
ucl_uint *res = result->result_ucl.result;
|
||||
ucl_uint *res = cresult->result_ucl.result;
|
||||
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
cconf.bb_endian = 0;
|
||||
cconf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
|
||||
{
|
||||
static const unsigned char sizes[3]={32,8,16};
|
||||
conf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
static const unsigned char sizes[3] = {32, 8, 16};
|
||||
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
}
|
||||
else {
|
||||
throwInternalError("unknown compression method");
|
||||
|
@ -136,20 +136,20 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|||
}
|
||||
|
||||
// optimize compression parms
|
||||
if (level <= 3 && conf.max_offset == UCL_UINT_MAX)
|
||||
conf.max_offset = 8*1024-1;
|
||||
else if (level == 4 && conf.max_offset == UCL_UINT_MAX)
|
||||
conf.max_offset = 32*1024-1;
|
||||
if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
|
||||
cconf.max_offset = 8*1024-1;
|
||||
else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
|
||||
cconf.max_offset = 32*1024-1;
|
||||
|
||||
if M_IS_NRV2B(method)
|
||||
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, res);
|
||||
&cb, level, &cconf, res);
|
||||
else if M_IS_NRV2D(method)
|
||||
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, res);
|
||||
&cb, level, &cconf, res);
|
||||
else if M_IS_NRV2E(method)
|
||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, res);
|
||||
&cb, level, &cconf, res);
|
||||
else {
|
||||
throwInternalError("unknown compression method");
|
||||
return UPX_E_ERROR;
|
||||
|
@ -166,7 +166,7 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
|||
int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r;
|
||||
|
||||
|
@ -204,7 +204,7 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
|||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
UNUSED(result);
|
||||
UNUSED(cresult);
|
||||
return convert_errno_from_ucl(r);
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
|||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result )
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r;
|
||||
|
||||
|
@ -254,7 +254,7 @@ int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
|||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
UNUSED(result);
|
||||
UNUSED(cresult);
|
||||
return convert_errno_from_ucl(r);
|
||||
}
|
||||
|
||||
|
|
|
@ -626,16 +626,16 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
|||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
struct upx_compress_result_t *result );
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult );
|
||||
int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const struct upx_compress_result_t *result );
|
||||
const upx_compress_result_t *cresult );
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -1904,7 +1904,7 @@ void PackArmPe::pack(OutputFile *fo)
|
|||
}
|
||||
|
||||
compressWithFilters(&ft, 2048, strategy,
|
||||
NULL, 0, 0, ih.codebase, rvamin);
|
||||
NULL, NULL, ih.codebase, rvamin);
|
||||
// info: see buildLoader()
|
||||
newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
||||
if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4)
|
||||
|
|
|
@ -293,7 +293,12 @@ void PackDjgpp2::pack(OutputFile *fo)
|
|||
ft.buf_len = usize - data->size;
|
||||
ft.addvalue = text->vaddr - hdrsize;
|
||||
// compress
|
||||
compressWithFilters(&ft, 512);
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
#if 1
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ~28 kB stack
|
||||
#endif
|
||||
compressWithFilters(&ft, 512, 0, NULL, &cconf);
|
||||
|
||||
// patch coff header #2
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
|
|
@ -412,8 +412,10 @@ void PackExe::pack(OutputFile *fo)
|
|||
ph.u_len = ih_imagesize + relocsize;
|
||||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
// compress
|
||||
compressWithFilters(&ft, 32, 0, NULL, 0, MAXMATCH);
|
||||
// compress (max_match = 8192)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = MAXMATCH;
|
||||
compressWithFilters(&ft, 32, 0, NULL, &cconf);
|
||||
if (ph.max_run_found + ph.max_match_found > 0x8000)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
|
|
|
@ -302,7 +302,9 @@ void PackPs1::pack(OutputFile *fo)
|
|||
Filter ft(ph.level);
|
||||
|
||||
// compress (max_match = 65535)
|
||||
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
compressWithFilters(&ft, 512, 0, NULL, &cconf);
|
||||
|
||||
if (ph.overlap_overhead > sa_cnt)
|
||||
{
|
||||
|
|
|
@ -489,7 +489,9 @@ void PackTos::pack(OutputFile *fo)
|
|||
// prepare filter
|
||||
Filter ft(ph.level);
|
||||
// compress (max_match = 65535)
|
||||
compressWithFilters(&ft, 512, 0, NULL, 0, 65535);
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
compressWithFilters(&ft, 512, 0, NULL, &cconf);
|
||||
|
||||
// get loader
|
||||
const unsigned lsize = getLoaderSize();
|
||||
|
|
|
@ -348,7 +348,7 @@ void PackUnix::packExtent(
|
|||
ft->cto = 0;
|
||||
|
||||
compressWithFilters(ft, OVERHEAD, strategy,
|
||||
NULL, 0, 0, 0, 0, // those 5 args are the defaults
|
||||
NULL, NULL, 0, 0, // those 4 args are the defaults
|
||||
hdr_ibuf, hdr_u_len);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1924,7 +1924,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
|||
}
|
||||
|
||||
compressWithFilters(&ft, 2048, strategy,
|
||||
NULL, 0, 0, ih.codebase, rvamin);
|
||||
NULL, NULL, ih.codebase, rvamin);
|
||||
// info: see buildLoader()
|
||||
newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
||||
if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4)
|
||||
|
|
|
@ -158,7 +158,7 @@ bool Packer::skipVerify() const
|
|||
**************************************************************************/
|
||||
|
||||
bool Packer::compress(upx_bytep in, upx_bytep out,
|
||||
unsigned max_offset, unsigned max_match)
|
||||
const upx_compress_config_t *cconf_parm)
|
||||
{
|
||||
ph.c_len = 0;
|
||||
assert(ph.level >= 1); assert(ph.level <= 10);
|
||||
|
@ -170,24 +170,20 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||
ph.u_adler = upx_adler32(in, ph.u_len, ph.u_adler);
|
||||
|
||||
// set compression paramters
|
||||
upx_compress_config_t conf;
|
||||
conf.reset();
|
||||
// arguments
|
||||
if (max_offset != 0)
|
||||
conf.conf_ucl.max_offset = max_offset;
|
||||
if (max_match != 0)
|
||||
conf.conf_ucl.max_match = max_match;
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
if (cconf_parm)
|
||||
cconf = *cconf_parm;
|
||||
// options
|
||||
if (opt->crp.crp_ucl.c_flags != -1)
|
||||
conf.conf_ucl.c_flags = opt->crp.crp_ucl.c_flags;
|
||||
cconf.conf_ucl.c_flags = opt->crp.crp_ucl.c_flags;
|
||||
if (opt->crp.crp_ucl.p_level != -1)
|
||||
conf.conf_ucl.p_level = opt->crp.crp_ucl.p_level;
|
||||
cconf.conf_ucl.p_level = opt->crp.crp_ucl.p_level;
|
||||
if (opt->crp.crp_ucl.h_level != -1)
|
||||
conf.conf_ucl.h_level = opt->crp.crp_ucl.h_level;
|
||||
if (opt->crp.crp_ucl.max_offset != UINT_MAX && opt->crp.crp_ucl.max_offset < conf.conf_ucl.max_offset)
|
||||
conf.conf_ucl.max_offset = opt->crp.crp_ucl.max_offset;
|
||||
if (opt->crp.crp_ucl.max_match != UINT_MAX && opt->crp.crp_ucl.max_match < conf.conf_ucl.max_match)
|
||||
conf.conf_ucl.max_match = opt->crp.crp_ucl.max_match;
|
||||
cconf.conf_ucl.h_level = opt->crp.crp_ucl.h_level;
|
||||
if (opt->crp.crp_ucl.max_offset != UINT_MAX && opt->crp.crp_ucl.max_offset < cconf.conf_ucl.max_offset)
|
||||
cconf.conf_ucl.max_offset = opt->crp.crp_ucl.max_offset;
|
||||
if (opt->crp.crp_ucl.max_match != UINT_MAX && opt->crp.crp_ucl.max_match < cconf.conf_ucl.max_match)
|
||||
cconf.conf_ucl.max_match = opt->crp.crp_ucl.max_match;
|
||||
|
||||
// Avoid too many progress bar updates. 64 is s->bar_len in ui.cpp.
|
||||
unsigned step = (ph.u_len < 64*1024) ? 0 : ph.u_len / 64;
|
||||
|
@ -205,7 +201,7 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||
// compress
|
||||
int r = upx_compress(in, ph.u_len, out, &ph.c_len,
|
||||
uip->getCallback(),
|
||||
ph.method, ph.level, &conf, &ph.compress_result);
|
||||
ph.method, ph.level, &cconf, &ph.compress_result);
|
||||
|
||||
//uip->finalCallback(ph.u_len, ph.c_len);
|
||||
uip->endCallback();
|
||||
|
@ -224,8 +220,11 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
|||
ph.max_run_found = res[5];
|
||||
ph.first_offset_found = res[6];
|
||||
//ph.same_match_offsets_found = res[7];
|
||||
assert(max_offset == 0 || max_offset >= ph.max_offset_found);
|
||||
assert(max_match == 0 || max_match >= ph.max_match_found);
|
||||
if (cconf_parm)
|
||||
{
|
||||
assert(cconf.conf_ucl.max_offset == 0 || cconf.conf_ucl.max_offset >= ph.max_offset_found);
|
||||
assert(cconf.conf_ucl.max_match == 0 || cconf.conf_ucl.max_match >= ph.max_match_found);
|
||||
}
|
||||
|
||||
//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))
|
||||
|
@ -1140,7 +1139,7 @@ int Packer::getLoaderSectionStart(const char *name, int *slen) const
|
|||
void Packer::compressWithFilters(Filter *parm_ft,
|
||||
const unsigned overlap_range,
|
||||
int strategy, const int *parm_filters,
|
||||
unsigned max_offset, unsigned max_match,
|
||||
const upx_compress_config_t *cconf,
|
||||
unsigned filter_off, unsigned compress_buf_off,
|
||||
unsigned char *hdr_buf,
|
||||
unsigned hdr_u_len)
|
||||
|
@ -1323,7 +1322,7 @@ void Packer::compressWithFilters(Filter *parm_ft,
|
|||
ph.filter_cto = ft.cto;
|
||||
ph.n_mru = ft.n_mru;
|
||||
// compress
|
||||
if (compress(ibuf + compress_buf_off, *otemp, max_offset, max_match))
|
||||
if (compress(ibuf + compress_buf_off, *otemp, cconf))
|
||||
{
|
||||
unsigned lsize = 0;
|
||||
if (ph.c_len + lsize + hdr_c_len <= best_ph.c_len + best_ph_lsize + best_hdr_c_len)
|
||||
|
|
|
@ -165,7 +165,7 @@ public:
|
|||
protected:
|
||||
// main compression drivers
|
||||
virtual bool compress(upx_bytep in, upx_bytep out,
|
||||
unsigned max_offset = 0, unsigned max_match = 0);
|
||||
const upx_compress_config_t *cconf = NULL);
|
||||
virtual void decompress(const upx_bytep in, upx_bytep out,
|
||||
bool verify_checksum = true, Filter *ft = NULL);
|
||||
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
|
||||
|
@ -176,7 +176,7 @@ protected:
|
|||
const unsigned overlap_range,
|
||||
int strategy = 0,
|
||||
const int *filters = NULL,
|
||||
unsigned max_offset = 0, unsigned max_match = 0,
|
||||
const upx_compress_config_t *cconf = NULL,
|
||||
unsigned filter_buf_off = 0,
|
||||
unsigned compress_buf_off = 0,
|
||||
unsigned char *header_buffer = 0,
|
||||
|
|
Loading…
Reference in New Issue
Block a user