Introduced upx_compress_result_t.
This commit is contained in:
parent
869fb8e327
commit
c3ee14eb67
@ -69,25 +69,26 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result )
|
||||
struct upx_compress_result_t *result )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
upx_uint result_buffer[16];
|
||||
upx_compress_result_t result_buffer;
|
||||
|
||||
assert(level > 0);
|
||||
if (!result)
|
||||
result = result_buffer;
|
||||
result = &result_buffer;
|
||||
|
||||
memset(result, 0, sizeof(*result));
|
||||
// assume no info available - fill in worst case results
|
||||
//result[0] = 1; // min_offset_found - NOT USED
|
||||
result[1] = src_len - 1; // max_offset_found
|
||||
//result[2] = 2; // min_match_found - NOT USED
|
||||
result[3] = src_len - 1; // max_match_found
|
||||
//result[4] = 1; // min_run_found - NOT USED
|
||||
result[5] = src_len; // max_run_found
|
||||
result[6] = 1; // first_offset_found
|
||||
//result[7] = 999999; // same_match_offsets_found - NOT USED
|
||||
result[8] = 0; // LzmaGetNumProbs()
|
||||
upx_uint *res = result->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
|
||||
res[3] = src_len - 1; // max_match_found
|
||||
//res[4] = 1; // min_run_found - NOT USED
|
||||
res[5] = src_len; // max_run_found
|
||||
res[6] = 1; // first_offset_found
|
||||
//res[7] = 999999; // same_match_offsets_found - NOT USED
|
||||
|
||||
#if defined(WITH_LZMA)
|
||||
if (M_IS_LZMA(method))
|
||||
|
||||
@ -40,7 +40,7 @@ int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result );
|
||||
struct upx_compress_result_t *result );
|
||||
int upx_lzma_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method );
|
||||
@ -56,7 +56,7 @@ int upx_nrv_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result );
|
||||
struct upx_compress_result_t *result );
|
||||
int upx_nrv_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method );
|
||||
@ -72,7 +72,7 @@ int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result );
|
||||
struct upx_compress_result_t *result );
|
||||
int upx_ucl_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method );
|
||||
|
||||
@ -117,14 +117,16 @@ int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
upx_uintp result )
|
||||
struct upx_compress_result_t *result )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
assert(level > 0); assert(result != NULL);
|
||||
UNUSED(cb); UNUSED(method); UNUSED(level);
|
||||
UNUSED(conf_parm); UNUSED(result);
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
HRESULT rh;
|
||||
lzma_compress_result_t *res = &result->result_lzma;
|
||||
|
||||
MyLzma::InStreamRam is; is.AddRef();
|
||||
MyLzma::OutStreamRam os; os.AddRef();
|
||||
@ -150,9 +152,8 @@ int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
|
||||
NCoderPropID::kMatchFinderCycles // 6
|
||||
};
|
||||
PROPVARIANT pr[7];
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = VT_UI4;
|
||||
pr[3].vt = pr[4].vt = pr[5].vt = VT_UI4;
|
||||
pr[6].vt = VT_UI4;
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = VT_UI4; pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
|
||||
// setup defaults
|
||||
pr[0].uintVal = 2;
|
||||
@ -188,9 +189,9 @@ int upx_lzma_compress ( const upx_bytep src, upx_uint src_len,
|
||||
else if (rh == S_OK)
|
||||
r = UPX_E_OK;
|
||||
|
||||
//result[8] = LzmaGetNumProbs(&s.Properties));
|
||||
//result[8] = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
|
||||
result[8] = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
//res->num_probs = LzmaGetNumProbs(&s.Properties));
|
||||
//res->num_probs = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
|
||||
res->num_probs = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
|
||||
error:
|
||||
*dst_len = os.Pos;
|
||||
|
||||
@ -76,7 +76,7 @@ int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb_parm,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf_parm,
|
||||
upx_uintp result )
|
||||
struct upx_compress_result_t *result )
|
||||
{
|
||||
int r = UPX_E_ERROR;
|
||||
assert(level > 0); assert(result != NULL);
|
||||
@ -94,6 +94,8 @@ int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
|
||||
if (conf_parm)
|
||||
conf = conf_parm->conf_ucl; // struct copy
|
||||
|
||||
ucl_uint *res = result->result_ucl.result;
|
||||
|
||||
// prepare bit-buffer settings
|
||||
conf.bb_endian = 0;
|
||||
conf.bb_size = 0;
|
||||
@ -113,13 +115,13 @@ int upx_ucl_compress ( const upx_bytep src, upx_uint src_len,
|
||||
|
||||
if M_IS_NRV2B(method)
|
||||
r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, result);
|
||||
&cb, level, &conf, res);
|
||||
else if M_IS_NRV2D(method)
|
||||
r = ucl_nrv2d_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, result);
|
||||
&cb, level, &conf, res);
|
||||
else if M_IS_NRV2E(method)
|
||||
r = ucl_nrv2e_99_compress(src, src_len, dst, dst_len,
|
||||
&cb, level, &conf, result);
|
||||
&cb, level, &conf, res);
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
|
||||
|
||||
23
src/conf.h
23
src/conf.h
@ -202,6 +202,7 @@ struct upx_callback_t
|
||||
upx_uint user3;
|
||||
};
|
||||
|
||||
|
||||
struct lzma_compress_config_t
|
||||
{
|
||||
unsigned pos_bits;
|
||||
@ -219,6 +220,26 @@ struct upx_compress_config_t
|
||||
};
|
||||
|
||||
|
||||
struct lzma_compress_result_t
|
||||
{
|
||||
unsigned pos_bits;
|
||||
unsigned lit_pos_bits;
|
||||
unsigned lit_context_bits;
|
||||
unsigned num_probs;
|
||||
};
|
||||
|
||||
struct ucl_compress_result_t
|
||||
{
|
||||
upx_uint result[16];
|
||||
};
|
||||
|
||||
struct upx_compress_result_t
|
||||
{
|
||||
lzma_compress_result_t result_lzma;
|
||||
ucl_compress_result_t result_ucl;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// system includes
|
||||
**************************************************************************/
|
||||
@ -593,7 +614,7 @@ int upx_compress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const struct upx_compress_config_t *conf,
|
||||
upx_uintp result );
|
||||
struct upx_compress_result_t *result );
|
||||
int upx_decompress ( const upx_bytep src, upx_uint src_len,
|
||||
upx_bytep dst, upx_uintp dst_len,
|
||||
int method );
|
||||
|
||||
@ -374,13 +374,13 @@ void PackUnix::packExtent(
|
||||
if (hdr_ulen) {
|
||||
unsigned hdr_clen;
|
||||
MemBuffer hdr_obuf;
|
||||
unsigned result[16];
|
||||
upx_compress_config_t conf;
|
||||
memset(&conf, 0xff, sizeof(conf));
|
||||
hdr_obuf.allocForCompression(hdr_ulen);
|
||||
int r = upx_compress(hdr_ibuf, hdr_ulen, hdr_obuf, &hdr_clen, 0,
|
||||
ph.method, 10, &conf, result);
|
||||
(void)r;
|
||||
ph.method, 10, NULL, NULL);
|
||||
if (r != UPX_E_OK)
|
||||
throwInternalError("header compression failed");
|
||||
if (hdr_clen >= hdr_ulen)
|
||||
throwInternalError("header compression size increase");
|
||||
ph.saved_u_adler = upx_adler32(hdr_ibuf, hdr_ulen, init_u_adler);
|
||||
ph.saved_c_adler = upx_adler32(hdr_obuf, hdr_clen, init_c_adler);
|
||||
ph.u_adler = upx_adler32(ibuf, ph.u_len, ph.saved_u_adler);
|
||||
|
||||
@ -208,11 +208,10 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
||||
//OutputFile::dump("data.raw", in, ph.u_len);
|
||||
|
||||
// compress
|
||||
unsigned result[16];
|
||||
memset(result, 0, sizeof(result));
|
||||
upx_compress_result_t result;
|
||||
int r = upx_compress(in, ph.u_len, out, &ph.c_len,
|
||||
uip->getCallback(),
|
||||
ph.method, ph.level, &conf, result);
|
||||
ph.method, ph.level, &conf, &result);
|
||||
|
||||
//uip->finalCallback(ph.u_len, ph.c_len);
|
||||
uip->endCallback();
|
||||
@ -222,14 +221,14 @@ bool Packer::compress(upx_bytep in, upx_bytep out,
|
||||
if (r != UPX_E_OK)
|
||||
throwInternalError("compression failed");
|
||||
|
||||
//ph.min_offset_found = result[0];
|
||||
ph.max_offset_found = result[1];
|
||||
//ph.min_match_found = result[2];
|
||||
ph.max_match_found = result[3];
|
||||
//ph.min_run_found = result[4];
|
||||
ph.max_run_found = result[5];
|
||||
ph.first_offset_found = result[6];
|
||||
//ph.same_match_offsets_found = result[7];
|
||||
//ph.min_offset_found = result.result_ucl.result[0];
|
||||
ph.max_offset_found = result.result_ucl.result[1];
|
||||
//ph.min_match_found = result.result_ucl.result[2];
|
||||
ph.max_match_found = result.result_ucl.result[3];
|
||||
//ph.min_run_found = result.result_ucl.result[4];
|
||||
ph.max_run_found = result.result_ucl.result[5];
|
||||
ph.first_offset_found = result.result_ucl.result[6];
|
||||
//ph.same_match_offsets_found = result.result_ucl.result[7];
|
||||
assert(max_offset == 0 || max_offset >= ph.max_offset_found);
|
||||
assert(max_match == 0 || max_match >= ph.max_match_found);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user