From 0d5ae77efc0f75ca2ff0eb79dd3f72132ff1277b Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 13 Feb 2007 02:25:32 +0100 Subject: [PATCH] Some more dos/exe updates. --- src/main.cpp | 5 +++++ src/options.h | 4 ++++ src/p_exe.cpp | 24 +++++++++++++++++++----- src/p_mach_enum.h | 2 +- src/stub/src/arch/i086/Makefile.extra | 2 +- src/stub/src/arch/i086/cleanasm.py | 2 +- src/stub/src/arch/i086/lzma_d.S | 8 ++++---- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4d698fba..b3770828 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -553,23 +553,28 @@ static int do_option(int optc, const char *arg) // method case 702: + opt->method_nrv2b_seen = true; if (!set_method(M_NRV2B_LE32, -1)) e_method(M_NRV2B_LE32, opt->level); break; case 704: + opt->method_nrv2d_seen = true; if (!set_method(M_NRV2D_LE32, -1)) e_method(M_NRV2D_LE32, opt->level); break; case 705: + opt->method_nrv2e_seen = true; if (!set_method(M_NRV2E_LE32, -1)) e_method(M_NRV2E_LE32, opt->level); break; case 721: + opt->method_lzma_seen = true; opt->all_methods_use_lzma = true; if (!set_method(M_LZMA, -1)) e_method(M_LZMA, opt->level); break; case 722: + opt->method_lzma_seen = false; opt->all_methods_use_lzma = false; if (M_IS_LZMA(opt->method)) opt->method = -1; diff --git a/src/options.h b/src/options.h index 65e8be17..94cd9e80 100644 --- a/src/options.h +++ b/src/options.h @@ -47,6 +47,10 @@ struct options_t { // compression options int method; + bool method_lzma_seen; + bool method_nrv2b_seen; + bool method_nrv2d_seen; + bool method_nrv2e_seen; int level; // compression level 1..10 int filter; // preferred filter from Packer::getFilters() bool ultra_brute; diff --git a/src/p_exe.cpp b/src/p_exe.cpp index 6c26238c..78b86297 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -53,11 +53,16 @@ PackExe::PackExe(InputFile *f) : bele = &N_BELE_RTP::le_policy; COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32); ih_exesize = ih_imagesize = ih_overlay = 0; + + // disable lzma for "--brute" unless explicitly given "--lzma" + if (opt->all_methods_use_lzma && !opt->method_lzma_seen) + opt->all_methods_use_lzma = false; } const int *PackExe::getCompressionMethods(int method, int level) const { +#if 0 static const int m_all[] = { M_NRV2B_8, M_NRV2D_8, M_NRV2E_8, M_END }; static const int m_nrv2b[] = { M_NRV2B_8, M_END }; static const int m_nrv2d[] = { M_NRV2D_8, M_END }; @@ -68,11 +73,15 @@ const int *PackExe::getCompressionMethods(int method, int level) const if (M_IS_NRV2B(method)) return m_nrv2b; if (M_IS_NRV2D(method)) return m_nrv2d; if (M_IS_NRV2E(method)) return m_nrv2e; - if (M_IS_LZMA(method)) return m_lzma; + if (M_IS_LZMA(method)) return m_lzma; bool small = ih_imagesize <= 256*1024; if (level == 1 || small) return m_nrv2b; return m_nrv2e; +#else + bool small = ih_imagesize <= 256*1024; + return Packer::getDefaultCompressionMethods_8(method, level, small); +#endif } @@ -96,7 +105,9 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const oh.ident = 'M' + 'Z' * 256; oh.headsize16 = 2; - unsigned minsp = M_IS_LZMA(ph.method) ? getDecompressorWrkmemSize() + 0x1100 : 0x200; + unsigned minsp = 0x200; + if (M_IS_LZMA(ph.method)) + minsp = getDecompressorWrkmemSize() + 0x1100; assert(minsp < 0xff00); oh.sp = ih.sp > minsp ? (unsigned) ih.sp : minsp; @@ -170,7 +181,7 @@ void PackExe::buildLoader(const Filter *) "NRV2EEX9", NULL ); - else if (ph.method == M_LZMA) + else if M_IS_LZMA(ph.method) addLoader("LZMA_DEC00,LZMA_DEC10,LZMA_DEC99,LZMA_DEC30", ph.u_len > 0xffff ? "LZMA_DEC31" : "", NULL @@ -439,9 +450,12 @@ void PackExe::pack(OutputFile *fo) // compress (max_match = 8192) upx_compress_config_t cconf; cconf.reset(); cconf.conf_ucl.max_match = MAXMATCH; + cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack compressWithFilters(&ft, 32, &cconf); - if (ph.max_run_found + ph.max_match_found > 0x8000) - throwCantPack("decompressor limit exceeded, send a bugreport"); + + if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method)) + if (ph.max_run_found + ph.max_match_found > 0x8000) + throwCantPack("decompressor limit exceeded, send a bugreport"); #ifdef TESTING if (opt->debug.debug_level) diff --git a/src/p_mach_enum.h b/src/p_mach_enum.h index e24343a7..208c0826 100644 --- a/src/p_mach_enum.h +++ b/src/p_mach_enum.h @@ -35,7 +35,7 @@ #ifdef WANT_MACH_HEADER_ENUM /*{*/ #undef WANT_MACH_HEADER_ENUM - enum { // magic + enum { // magic MH_MAGIC = 0xfeedface }; enum { // cputype diff --git a/src/stub/src/arch/i086/Makefile.extra b/src/stub/src/arch/i086/Makefile.extra index cbfbc593..163d3003 100644 --- a/src/stub/src/arch/i086/Makefile.extra +++ b/src/stub/src/arch/i086/Makefile.extra @@ -108,7 +108,7 @@ endef # Borland C/C++ 5.02 ifneq ($(wildcard $(BC502DIR)/bin/.),) c := tc.method-lzma.bcc -$c = @$(WINEENV) CL='$(CL)' wine cmd.exe /c tmp/bcc.bat +$c = @$(WINEENV) wine cmd.exe /c tmp/bcc.bat $c += -mc $c += -O1 -1 $c += -w diff --git a/src/stub/src/arch/i086/cleanasm.py b/src/stub/src/arch/i086/cleanasm.py index 4f65709a..ec214f5c 100644 --- a/src/stub/src/arch/i086/cleanasm.py +++ b/src/stub/src/arch/i086/cleanasm.py @@ -139,7 +139,7 @@ def main(argv): if m.group(3): args = m.group(3).strip() # if inst in ["movl",] and re.search(r"\b[de]s\b", args): - # correct objdump bug + # fix bug in objdump inst = "movw" m = re.search(r"^(.+?)\b0x0\s+(\w+):\s+[12]\s+(__\w+)$", args) if m: diff --git a/src/stub/src/arch/i086/lzma_d.S b/src/stub/src/arch/i086/lzma_d.S index abad9177..ea96bc62 100644 --- a/src/stub/src/arch/i086/lzma_d.S +++ b/src/stub/src/arch/i086/lzma_d.S @@ -30,8 +30,8 @@ ; ------------- DECOMPRESSION ------------- ; Input: -; si - source -; di - dest +; ds:si - source +; es:di - dest ; cld ; Output: @@ -111,10 +111,10 @@ __PIA_V03: #else // optimized version inc ax - jnes .L1 + jnes 1f add dh, (__AHINCR >> 8) movw ds, dx -.L1: +1: mov WORD PTR [bp-12],ax #endif ret