mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Merge branch 'devel' of https://github.com/upx/upx into devel
This commit is contained in:
commit
0e329336fc
|
@ -19,7 +19,7 @@ environment:
|
|||
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
- where bash & where cat & where curl & where git & where sed & where tar
|
||||
- where bash & where cat & where curl & where git & where gzip & where readlink & where sed & where sha256sum & where tar
|
||||
# - bash --version & git --version & sed --version & tar --version
|
||||
- git --version & bash --version
|
||||
# - dir "c:\Program Files\Git\usr\bin"
|
||||
|
|
2
NEWS
2
NEWS
|
@ -2,7 +2,7 @@
|
|||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
Changes in 3.92 (XX XXX 2016):
|
||||
Changes in 3.92 (27 Nov 2016):
|
||||
* UPX has moved to GitHub - the new home page is https://upx.github.io
|
||||
* All pe formats: important internal changes - reunited the diverged
|
||||
source files - please report regressions into the bug tracker.
|
||||
|
|
|
@ -162,7 +162,7 @@ endif
|
|||
|
||||
# automatically format some C++ source code files
|
||||
ifeq ($(shell uname),Linux)
|
||||
CLANG_FORMAT_FILES += packhead.cpp
|
||||
CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp
|
||||
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
|
||||
CLANG_FORMAT_FILES += snprintf.cpp
|
||||
CLANG_FORMAT_FILES += stdcxx.cpp stdcxx.h
|
||||
|
|
|
@ -31,10 +31,13 @@
|
|||
#include "mem.h"
|
||||
|
||||
#if (ACC_CC_MSC)
|
||||
# pragma warning(disable: 4456) // -Wno-shadow
|
||||
# pragma warning(disable: 4456) // -Wno-shadow
|
||||
#endif
|
||||
#if (ACC_CC_MSC && (_MSC_VER < 1900))
|
||||
# pragma warning(disable: 4127) // warning C4127: conditional expression is constant
|
||||
# pragma warning(disable: 4127) // warning C4127: conditional expression is constant
|
||||
#endif
|
||||
#if (ACC_CC_INTELC_GNUC)
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -54,15 +57,6 @@ void lzma_compress_config_t::reset()
|
|||
}
|
||||
|
||||
|
||||
#if !(WITH_LZMA)
|
||||
extern int compress_lzma_dummy;
|
||||
int compress_lzma_dummy = 0;
|
||||
#else
|
||||
#define opt compress_lzma_opt
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
|
||||
|
||||
// INFO: the LZMA SDK is covered by a permissive license which allows
|
||||
// using unmodified LZMA source code in UPX and the UPX stubs.
|
||||
// See SPECIAL EXCEPTION below.
|
||||
|
@ -100,28 +94,6 @@ int compress_lzma_dummy = 0;
|
|||
// while you keep LZMA SDK code unmodified.
|
||||
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#include "C/7zVersion.h"
|
||||
#if (WITH_LZMA != ((0x1000 * (MY_VER_MAJOR / 10)) + (0x0100 * (MY_VER_MAJOR % 10)) +\
|
||||
(0x0010 * (MY_VER_MINOR / 10)) + (0x0001 * (MY_VER_MINOR % 10))))
|
||||
# error "WITH_LZMA version mismatch"
|
||||
#endif
|
||||
|
||||
#if (WITH_LZMA >= 0x938)
|
||||
#include "C/7zTypes.h"
|
||||
#else
|
||||
#include "C/Types.h"
|
||||
#endif
|
||||
|
||||
static void *cb_alloc(void *, size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
static void cb_free(void *, void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress defaults
|
||||
**************************************************************************/
|
||||
|
@ -138,13 +110,12 @@ static int prepare(lzma_compress_result_t *res,
|
|||
res->fast_mode = 2;
|
||||
res->num_fast_bytes = 64; // 5 .. 273
|
||||
res->match_finder_cycles = 0;
|
||||
#if 1
|
||||
// UPX overrides
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
res->pos_bits = (method >> 16) & 15;
|
||||
|
@ -159,7 +130,7 @@ static int prepare(lzma_compress_result_t *res,
|
|||
res->lit_context_bits = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
// TODO: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
|
@ -239,129 +210,19 @@ error:
|
|||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#define _7ZIP_ST 1
|
||||
#define kLiteralNextStates kLiteralNextStates_enc
|
||||
#include "C/LzmaEnc.h"
|
||||
#include "C/LzmaEnc.c"
|
||||
#include "C/LzFind.c"
|
||||
#undef kLiteralNextStates
|
||||
#undef kNumFullDistances
|
||||
|
||||
|
||||
struct upx_ICompressProgress {
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
upx_callback_p cb;
|
||||
};
|
||||
|
||||
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
|
||||
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
|
||||
if (cb && cb->nprogress)
|
||||
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
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 upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
unsigned dst_avail = *dst_len;
|
||||
*dst_len = 0;
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
upx_ICompressProgress progress;
|
||||
progress.Progress = cb_progress; progress.cb = cb;
|
||||
|
||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
|
||||
CLzmaEncProps props; memset(&props, 0, sizeof(props));
|
||||
props.level = level;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.pb = res->pos_bits;
|
||||
props.lp = res->lit_pos_bits;
|
||||
props.lc = res->lit_context_bits;
|
||||
props.dictSize = res->dict_size;
|
||||
props.algo = res->fast_mode ? 1 : 0;
|
||||
props.fb = res->num_fast_bytes;
|
||||
props.mc = res->match_finder_cycles;
|
||||
|
||||
unsigned char props_buf[LZMA_PROPS_SIZE];
|
||||
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (dst_avail < 1)
|
||||
goto error;
|
||||
dst[0] = 0; // filled below
|
||||
dst += 1; *dst_len += 1; dst_avail -= 1;
|
||||
#else
|
||||
if (dst_avail < 2)
|
||||
goto error;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
|
||||
dst[0] = ((tt << 3) | res->pos_bits);
|
||||
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
|
||||
dst += 2; *dst_len += 2; dst_avail -= 2;
|
||||
#endif
|
||||
SizeT x_len; x_len = dst_avail;
|
||||
rh = LzmaEncode(dst, &x_len, src, src_len,
|
||||
&props, props_buf, &props_buf_size, 0,
|
||||
(ICompressProgress *) (void *) &progress, &cba, &cba);
|
||||
assert(x_len <= dst_avail);
|
||||
*dst_len += x_len;
|
||||
if (rh == SZ_OK) {
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
dst[-1] = props_buf[0];
|
||||
#endif
|
||||
r = UPX_E_OK;
|
||||
}
|
||||
|
||||
error:
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress - cruft because of pseudo-COM layer
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef MSDOS
|
||||
#undef OS2
|
||||
#undef _WIN32
|
||||
#undef _WIN32_WCE
|
||||
#undef COMPRESS_MF_MT
|
||||
#undef _NO_EXCEPTIONS
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# define INITGUID 1
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#else
|
||||
# include "C/Common/MyInitGuid.h"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#endif
|
||||
#include "C/Common/MyInitGuid.h"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
|
||||
namespace MyLzma {
|
||||
|
||||
|
@ -380,7 +241,7 @@ STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
|||
{
|
||||
size_t remain = b_size - b_pos;
|
||||
if (size > remain) size = (UInt32) remain;
|
||||
memcpy(data, b_buf + b_pos, size);
|
||||
memmove(data, b_buf + b_pos, size);
|
||||
b_pos += size;
|
||||
if (processedSize != NULL) *processedSize = size;
|
||||
return S_OK;
|
||||
|
@ -406,7 +267,7 @@ STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSi
|
|||
{
|
||||
size_t remain = b_size - b_pos;
|
||||
if (size > remain) size = (UInt32) remain, overflow = true;
|
||||
memcpy(b_buf + b_pos, data, size);
|
||||
memmove(b_buf + b_pos, data, size);
|
||||
b_pos += size;
|
||||
if (processedSize != NULL) *processedSize = size;
|
||||
return overflow ? E_FAIL : S_OK;
|
||||
|
@ -429,35 +290,16 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
|
|||
|
||||
} // namespace
|
||||
|
||||
|
||||
#if (ACC_CC_INTELC_GNUC)
|
||||
//# pragma warning(disable: 424) // #424: extra ";" ignored
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
#endif
|
||||
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Alloc.c"
|
||||
# include "C/7zCrc.c"
|
||||
# include "C/Compress/Lz/MatchFinder.c"
|
||||
//# include "CPP/7zip/Common/InBuffer.cpp"
|
||||
# include "CPP/7zip/Common/OutBuffer.cpp"
|
||||
# include "CPP/7zip/Common/StreamUtils.cpp"
|
||||
//# include "CPP/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#else
|
||||
# include "C/Common/Alloc.cpp"
|
||||
# include "C/Common/CRC.cpp"
|
||||
//# include "C/7zip/Common/InBuffer.cpp"
|
||||
# include "C/7zip/Common/OutBuffer.cpp"
|
||||
# include "C/7zip/Common/StreamUtils.cpp"
|
||||
# include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#endif
|
||||
#include "C/Common/Alloc.cpp"
|
||||
#include "C/Common/CRC.cpp"
|
||||
//#include "C/7zip/Common/InBuffer.cpp"
|
||||
#include "C/7zip/Common/OutBuffer.cpp"
|
||||
#include "C/7zip/Common/StreamUtils.cpp"
|
||||
#include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
#include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#undef RC_NORMALIZE
|
||||
|
||||
|
||||
|
@ -496,14 +338,10 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
NCoderPropID::kMatchFinder // 7 mf
|
||||
};
|
||||
PROPVARIANT pr[8];
|
||||
#ifdef COMPRESS_MF_BT4
|
||||
const unsigned nprops = 8;
|
||||
static wchar_t matchfinder[] = L"BT4";
|
||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
|
||||
#else
|
||||
const unsigned nprops = 7;
|
||||
#endif
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
|
@ -516,11 +354,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
pr[5].uintVal = res->num_fast_bytes;
|
||||
pr[6].uintVal = res->match_finder_cycles;
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
try {
|
||||
#else
|
||||
# error
|
||||
#endif
|
||||
|
||||
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
|
||||
goto error;
|
||||
|
@ -532,21 +366,17 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||
goto error;
|
||||
}
|
||||
assert(os.b_pos == 5);
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
os.b_pos = 1;
|
||||
#else
|
||||
os.b_pos = 0;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
||||
os.WriteByte(Byte((t << 3) | res->pos_bits));
|
||||
os.WriteByte(Byte((res->lit_pos_bits << 4) | (res->lit_context_bits)));
|
||||
#endif
|
||||
|
||||
rh = enc.Code(&is, &os, NULL, NULL, &progress);
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
} catch (...) { rh = E_OUTOFMEMORY; }
|
||||
#endif
|
||||
} catch (...) {
|
||||
rh = E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
assert(is.b_pos <= src_len);
|
||||
assert(os.b_pos <= *dst_len);
|
||||
|
@ -571,121 +401,17 @@ error:
|
|||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
|
||||
#undef _LZMA_PROB32
|
||||
#include "C/LzmaDec.h"
|
||||
#include "C/LzmaDec.c"
|
||||
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
#define Properties prop
|
||||
assert(M_IS_LZMA(method));
|
||||
// see res->num_probs above
|
||||
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
CLzmaDec s; memset(&s, 0, sizeof(s));
|
||||
SizeT srcLen = 0;
|
||||
int r = UPX_E_ERROR;
|
||||
SRes rh;
|
||||
ELzmaStatus status;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
rh = LzmaProps_Decode(&s.Properties, src, src_len);
|
||||
if (rh != 0)
|
||||
goto error;
|
||||
src += 1; src_len -= 1;
|
||||
#else
|
||||
if (src_len < 3)
|
||||
goto error;
|
||||
s.Properties.pb = src[0] & 7;
|
||||
s.Properties.lp = (src[1] >> 4);
|
||||
s.Properties.lc = src[1] & 15;
|
||||
if (s.Properties.pb >= 5) goto error;
|
||||
if (s.Properties.lp >= 5) goto error;
|
||||
if (s.Properties.lc >= 9) goto error;
|
||||
// extra
|
||||
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
|
||||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
s.Properties.dicSize = 0;
|
||||
|
||||
if (cresult)
|
||||
{
|
||||
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) LzmaProps_GetNumProbs(&s.Properties));
|
||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
UNUSED(res);
|
||||
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
}
|
||||
|
||||
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
|
||||
if (rh != SZ_OK)
|
||||
{
|
||||
r = UPX_E_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
|
||||
LzmaDec_Init(&s);
|
||||
srcLen = src_len;
|
||||
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
|
||||
assert(srcLen <= src_len);
|
||||
assert(s.dicPos <= *dst_len);
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
rh = SZ_ERROR_INPUT_EOF;
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
{
|
||||
r = UPX_E_OK;
|
||||
if (srcLen != src_len)
|
||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||
}
|
||||
error:
|
||||
*dst_len = s.dicPos;
|
||||
LzmaDec_FreeProbs(&s, &cba);
|
||||
return r;
|
||||
#undef Properties
|
||||
}
|
||||
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef _LZMA_IN_CB
|
||||
#undef _LZMA_OUT_READ
|
||||
#undef _LZMA_PROB32
|
||||
#undef _LZMA_LOC_OPT
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Compress/Lzma/LzmaDecode.h"
|
||||
# include "C/Compress/Lzma/LzmaDecode.c"
|
||||
#else
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
#endif
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
|
@ -703,14 +429,6 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
|||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (src_len < 2)
|
||||
goto error;
|
||||
rh = LzmaDecodeProperties(&s.Properties, src, src_len);
|
||||
if (rh != 0)
|
||||
goto error;
|
||||
src += 1; src_len -= 1;
|
||||
#else
|
||||
if (src_len < 3)
|
||||
goto error;
|
||||
s.Properties.pb = src[0] & 7;
|
||||
|
@ -722,7 +440,6 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
|||
// extra
|
||||
if ((src[0] >> 3) != s.Properties.lc + s.Properties.lp) goto error;
|
||||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
|
||||
if (cresult)
|
||||
{
|
||||
|
@ -757,8 +474,6 @@ error:
|
|||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
|
@ -801,16 +516,7 @@ int upx_lzma_init(void)
|
|||
|
||||
const char *upx_lzma_version_string(void)
|
||||
{
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
# error "invalid WITH_LZMA version"
|
||||
return MY_VERSION;
|
||||
#elif (WITH_LZMA + 0 == 0x457)
|
||||
# error "invalid WITH_LZMA version"
|
||||
return "4.57";
|
||||
#elif (WITH_LZMA + 0 == 0x449)
|
||||
# error "invalid WITH_LZMA version"
|
||||
return "4.49";
|
||||
#elif (WITH_LZMA + 0 == 0x443)
|
||||
#if (WITH_LZMA == 0x443)
|
||||
return "4.43";
|
||||
#else
|
||||
# error "unknown WITH_LZMA version"
|
||||
|
@ -819,6 +525,4 @@ const char *upx_lzma_version_string(void)
|
|||
}
|
||||
|
||||
|
||||
#endif /* WITH_LZMA */
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
|
|
@ -55,8 +55,13 @@
|
|||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(((int)(1u << 31)) >> 31 == -1) // arithmetic right shift
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) > 0) // -funsigned-char
|
||||
|
||||
#if (ACC_CC_MSC)
|
||||
# pragma warning(error: 4319)
|
||||
#endif
|
||||
|
||||
// FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages)
|
||||
#if 1 && (ACC_ARCH_ARM) && defined(__pe__) && !defined(__CEGCC__) && !defined(_WIN32)
|
||||
# undef HAVE_CHMOD
|
||||
|
|
549
src/linker.cpp
549
src/linker.cpp
File diff suppressed because it is too large
Load Diff
191
src/linker.h
191
src/linker.h
|
@ -25,52 +25,50 @@
|
|||
<markus@oberhumer.com> <ezerotven+github@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_LINKER_H
|
||||
#define __UPX_LINKER_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ElfLinker
|
||||
**************************************************************************/
|
||||
|
||||
class ElfLinker : private noncopyable
|
||||
{
|
||||
class ElfLinker : private noncopyable {
|
||||
friend class Packer;
|
||||
|
||||
public:
|
||||
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
|
||||
protected:
|
||||
struct Section;
|
||||
struct Symbol;
|
||||
struct Relocation;
|
||||
struct Section;
|
||||
struct Symbol;
|
||||
struct Relocation;
|
||||
|
||||
upx_byte *input;
|
||||
int inputlen;
|
||||
upx_byte *output;
|
||||
int outputlen;
|
||||
upx_byte *input;
|
||||
int inputlen;
|
||||
upx_byte *output;
|
||||
int outputlen;
|
||||
|
||||
Section *head;
|
||||
Section *tail;
|
||||
Section *head;
|
||||
Section *tail;
|
||||
|
||||
Section **sections;
|
||||
Symbol **symbols;
|
||||
Relocation **relocations;
|
||||
Section **sections;
|
||||
Symbol **symbols;
|
||||
Relocation **relocations;
|
||||
|
||||
unsigned nsections;
|
||||
unsigned nsections_capacity;
|
||||
unsigned nsymbols;
|
||||
unsigned nsymbols_capacity;
|
||||
unsigned nrelocations;
|
||||
unsigned nrelocations_capacity;
|
||||
unsigned nsections;
|
||||
unsigned nsections_capacity;
|
||||
unsigned nsymbols;
|
||||
unsigned nsymbols_capacity;
|
||||
unsigned nrelocations;
|
||||
unsigned nrelocations_capacity;
|
||||
|
||||
bool reloc_done;
|
||||
bool reloc_done;
|
||||
|
||||
protected:
|
||||
void preprocessSections(char *start, char const *end);
|
||||
void preprocessSymbols(char *start, char const *end);
|
||||
void preprocessRelocations(char *start, char const *end);
|
||||
Section *findSection(const char *name, bool fatal=true) const;
|
||||
Symbol *findSymbol(const char *name, bool fatal=true) const;
|
||||
void preprocessSections(char *start, char *end);
|
||||
void preprocessSymbols(char *start, char *end);
|
||||
void preprocessRelocations(char *start, char *end);
|
||||
Section *findSection(const char *name, bool fatal = true) const;
|
||||
Symbol *findSymbol(const char *name, bool fatal = true) const;
|
||||
|
||||
Symbol *addSymbol(const char *name, const char *section, upx_uint64_t offset);
|
||||
Relocation *addRelocation(const char *section, unsigned off, const char *type,
|
||||
|
@ -81,7 +79,7 @@ public:
|
|||
virtual ~ElfLinker();
|
||||
|
||||
virtual void init(const void *pdata, int plen);
|
||||
//virtual void setLoaderAlignOffset(int phase);
|
||||
// virtual void setLoaderAlignOffset(int phase);
|
||||
virtual int addLoader(const char *sname);
|
||||
void addLoader(const char *s, va_list ap);
|
||||
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
|
||||
|
@ -90,14 +88,14 @@ public:
|
|||
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
||||
#endif
|
||||
virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
|
||||
virtual int getSection(const char *sname, int *slen=NULL) const;
|
||||
virtual int getSection(const char *sname, int *slen = NULL) const;
|
||||
virtual int getSectionSize(const char *sname) const;
|
||||
virtual upx_byte *getLoader(int *llen=NULL) const;
|
||||
virtual upx_byte *getLoader(int *llen = NULL) const;
|
||||
virtual void defineSymbol(const char *name, upx_uint64_t value);
|
||||
virtual upx_uint64_t getSymbolOffset(const char *) const;
|
||||
|
||||
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
|
||||
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
|
||||
virtual void dumpSymbols(unsigned flags = 0, FILE *fp = NULL) const;
|
||||
|
||||
void alignWithByte(unsigned len, unsigned char b);
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0); }
|
||||
|
@ -105,36 +103,32 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void relocate();
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
|
||||
// target endianness abstraction
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Section : private noncopyable
|
||||
{
|
||||
struct ElfLinker::Section : private noncopyable {
|
||||
char *name;
|
||||
void *input;
|
||||
upx_byte *output;
|
||||
unsigned size;
|
||||
upx_uint64_t offset;
|
||||
unsigned p2align; // log2
|
||||
unsigned p2align; // log2
|
||||
Section *next;
|
||||
|
||||
Section(const char *n, const void *i, unsigned s, unsigned a=0);
|
||||
Section(const char *n, const void *i, unsigned s, unsigned a = 0);
|
||||
~Section();
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Symbol : private noncopyable
|
||||
{
|
||||
struct ElfLinker::Symbol : private noncopyable {
|
||||
char *name;
|
||||
Section *section;
|
||||
upx_uint64_t offset;
|
||||
|
@ -143,124 +137,115 @@ struct ElfLinker::Symbol : private noncopyable
|
|||
~Symbol();
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Relocation : private noncopyable
|
||||
{
|
||||
struct ElfLinker::Relocation : private noncopyable {
|
||||
const Section *section;
|
||||
unsigned offset;
|
||||
const char *type;
|
||||
const Symbol *value;
|
||||
upx_uint64_t add; // used in .rela relocations
|
||||
upx_uint64_t add; // used in .rela relocations
|
||||
|
||||
Relocation(const Section *s, unsigned o, const char *t,
|
||||
const Symbol *v, upx_uint64_t a);
|
||||
Relocation(const Section *s, unsigned o, const char *t, const Symbol *v, upx_uint64_t a);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ElfLinker arch subclasses
|
||||
**************************************************************************/
|
||||
|
||||
class ElfLinkerAMD64 : public ElfLinker
|
||||
{
|
||||
class ElfLinkerAMD64 : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerArmBE : public ElfLinker
|
||||
{
|
||||
class ElfLinkerArmBE : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
public:
|
||||
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerArmLE : public ElfLinker
|
||||
{
|
||||
class ElfLinkerArmLE : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
class ElfLinkerArm64LE : public ElfLinker
|
||||
{
|
||||
class ElfLinkerArm64LE : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerM68k : public ElfLinker
|
||||
{
|
||||
class ElfLinkerM68k : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
public:
|
||||
ElfLinkerM68k() { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
protected:
|
||||
virtual void alignCode(unsigned len);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsBE : public ElfLinker
|
||||
{
|
||||
class ElfLinkerMipsBE : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
public:
|
||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsLE : public ElfLinker
|
||||
{
|
||||
class ElfLinkerMipsLE : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerPpc32 : public ElfLinker
|
||||
{
|
||||
class ElfLinkerPpc32 : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
public:
|
||||
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
class ElfLinkerPpc64le : public ElfLinker
|
||||
{
|
||||
class ElfLinkerPpc64le : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerX86 : public ElfLinker
|
||||
{
|
||||
class ElfLinkerX86 : public ElfLinker {
|
||||
typedef ElfLinker super;
|
||||
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
||||
const char *type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 33fb09d29159f9dde2ddae9fe6875f8614d28ca3
|
||||
Subproject commit 426fe82d122e2cf140a86751055ee523378fe2ef
|
|
@ -1666,7 +1666,7 @@ int PackMachBase<T>::canUnpack()
|
|||
}
|
||||
if (!strcmp("__LINKEDIT", segptr->segname)) {
|
||||
offLINK = segptr->fileoff;
|
||||
if (offLINK < pos_next) {
|
||||
if (offLINK < (off_t) pos_next) {
|
||||
offLINK = pos_next;
|
||||
}
|
||||
}
|
||||
|
|
0
src/stub/powerpc-darwin.macho-upxmain.exe
Executable file → Normal file
0
src/stub/powerpc-darwin.macho-upxmain.exe
Executable file → Normal file
|
@ -178,8 +178,7 @@ def do_file(fn):
|
|||
# FIXME / TODO
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
#assert pos == len(odata), ("unexpected strip_with_dump", pos, len(odata))
|
||||
assert pos == len(odata), ("unexpected strip_with_dump", pos, len(odata))
|
||||
else:
|
||||
if pos >= 0:
|
||||
odata = idata[:pos]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#define UPX_VERSION_HEX 0x035c00 /* 03.92.00 */
|
||||
#define UPX_VERSION_STRING "3.92-BETA"
|
||||
#define UPX_VERSION_STRING "3.92"
|
||||
#define UPX_VERSION_STRING4 "3.92"
|
||||
#define UPX_VERSION_DATE "Sep 25th 2016"
|
||||
#define UPX_VERSION_DATE_ISO "2016-09-25"
|
||||
#define UPX_VERSION_DATE "Nov 27th 2016"
|
||||
#define UPX_VERSION_DATE_ISO "2016-11-25"
|
||||
#define UPX_VERSION_YEAR "2016"
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
|
Loading…
Reference in New Issue
Block a user