From cbf1dbe2cb6c421546507650b824a55a5be7f91b Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 12 Jul 2004 11:06:22 +0000 Subject: [PATCH] Added new win32/pe option `--strip-loadconf'. committer: mfx 1089630382 +0000 --- NEWS | 1 + TODO | 5 +---- doc/Makefile | 2 +- doc/upx.pod | 3 +++ src/help.cpp | 8 +++++--- src/main.cpp | 15 ++++++++++++--- src/options.h | 1 + src/p_w32pe.cpp | 21 ++++++++++++++++----- src/version.h | 2 +- 9 files changed, 41 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 0547dc3e..5c03e91f 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ User visible changes for UPX Changes in 1.92 beta (XX XXX 2004): * UNSTABLE BETA VERSION - DO NOT USE EXCEPT FOR TESTING + * win32/pe: added option `--strip-loadconf' to strip the SEH load config section Changes in 1.91 beta (30 Jun 2004): * djgpp2/coff: added support for recent binutils versions diff --git a/TODO b/TODO index 1efaa8f3..6e744bd8 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,8 @@ -UPX TODO list. Last updated 2004-06-30. +UPX TODO list. Last updated 2004-07-12. IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON: -- win32/pe should add support for PEDIR_LOADCONF (Visual C++ 7.1 generated - exes, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG) - - win32/pe should reliably detect .NET exes and somehow deal with them - stub ctojr32 needs CPU 486 because of bswap diff --git a/doc/Makefile b/doc/Makefile index c7aec66e..69ebde5d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/sh top_srcdir = .. PACKAGE = upx -VERSION_DATE = 30 Jun 2004 +VERSION_DATE = 12 Jul 2004 VERSION := $(shell sed -n 's/^.*UPX_VERSION_STRING .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h) TRIMSPACE = cat diff --git a/doc/upx.pod b/doc/upx.pod index 2b9ab08a..92584223 100644 --- a/doc/upx.pod +++ b/doc/upx.pod @@ -869,6 +869,9 @@ Extra options available for this executable format: unexpected value in a header field. Use with care. + --strip-loadconf=0 Don't strip Structured Exception Handling load config [DEFAULT]. + --strip-loadconf=1 Strip Structured Exception Handling load config. + --strip-relocs=0 Don't strip relocation records. --strip-relocs=1 Strip relocation records. [DEFAULT] This option only works on executables with base diff --git a/src/help.cpp b/src/help.cpp index c3e590be..819b41b0 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -105,7 +105,7 @@ void show_help(int x) " -d decompress -l list compressed file\n" " -t test compressed file -V display version number\n" " -h give %s help -L display software license\n%s", - x == 0 ? "" : " --best compress best (can be very slow for big files)\n", + x == 0 ? "" : " --best compress best (can be slow for big files)\n", x == 0 ? "more" : "this", x == 0 ? "" : "\n"); fg = con_fg(f,FG_YELLOW); @@ -140,7 +140,7 @@ void show_help(int x) fg = con_fg(f,fg); con_fprintf(f, " --overlay=copy copy any extra data attached to the file [default]\n" - " --overlay=strip strip any extra data attached to the file [dangerous]\n" + " --overlay=strip strip any extra data attached to the file [DANGEROUS]\n" " --overlay=skip don't compress a file with an overlay\n" "\n"); fg = con_fg(f,FG_YELLOW); @@ -207,7 +207,7 @@ void show_help(int x) " --all-filters try all available preprocessing filters\n" "\n"); fg = con_fg(f,FG_YELLOW); - con_fprintf(f,"Options for [b]vmlinuz/386\n"); + con_fprintf(f,"Options for vmlinuz/386\n"); fg = con_fg(f,fg); con_fprintf(f, " --all-methods try all available compression methods\n" @@ -229,6 +229,8 @@ void show_help(int x) " --compress-icons=1 compress all but the first icon\n" " --compress-icons=2 compress all but the first icon directory [default]\n" " --compress-resources=0 do not compress any resources at all\n" + " --strip-loadconf=0 do not strip SEH load config [default]\n" + " --strip-loadconf=1 strip SEH load config [DANGEROUS]\n" " --strip-relocs=0 do not strip relocations\n" " --strip-relocs=1 strip relocations [default]\n" " --all-methods try all available compression methods\n" diff --git a/src/main.cpp b/src/main.cpp index 6ad65067..a5b2ec06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ void init_options(struct options_t *o) for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++) o->win32_pe.compress_rt[i] = -1; o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST + o->win32_pe.strip_loadconf = -1; o->win32_pe.strip_relocs = -1; } @@ -676,6 +677,12 @@ static int do_option(int optc, const char *arg) //printf("compress_resources: %d\n", opt->win32_pe.compress_resources); break; case 633: + opt->win32_pe.strip_loadconf = 1; + if (mfx_optarg && strcmp(mfx_optarg,"0") == 0) + opt->win32_pe.strip_loadconf = 0; + //printf("strip_loadconf: %d\n", opt->win32_pe.strip_loadconf); + break; + case 634: opt->win32_pe.strip_relocs = 1; if (mfx_optarg && strcmp(mfx_optarg,"0") == 0) opt->win32_pe.strip_relocs = 0; @@ -823,7 +830,8 @@ static const struct mfx_option longopts[] = {"compress-exports", 2, 0, 630}, {"compress-icons", 2, 0, 631}, {"compress-resources", 2, 0, 632}, - {"strip-relocs", 2, 0, 633}, + {"strip-loadconf", 0x12, 0, 633}, + {"strip-relocs", 0x12, 0, 634}, // ps1/exe {"console-run", 0x10, 0, 670}, {"no-align", 0x10, 0, 671}, @@ -904,7 +912,8 @@ static const struct mfx_option longopts[] = {"compress-exports", 2, 0, 630}, {"compress-icons", 2, 0, 631}, {"compress-resources", 2, 0, 632}, - {"strip-relocs", 2, 0, 633}, + {"strip-loadconf", 0x12, 0, 633}, + {"strip-relocs", 0x12, 0, 634}, { NULL, 0, NULL, 0 } }; @@ -1223,7 +1232,7 @@ int __acc_cdecl_main main(int argc, char *argv[]) set_term(stdout); do_files(i,argc,argv); -#if 1 && (UPX_VERSION_HEX < 0x020000) +#if 0 && (UPX_VERSION_HEX < 0x020000) { FILE *f = stdout; int fg = con_fg(f,FG_RED); diff --git a/src/options.h b/src/options.h index b3072f11..8ebbe0c6 100644 --- a/src/options.h +++ b/src/options.h @@ -128,6 +128,7 @@ struct options_t { int compress_icons; int compress_resources; signed char compress_rt[25]; // 25 == RT_LAST + int strip_loadconf; int strip_relocs; } win32_pe; }; diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index def39cd6..45269811 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -1601,6 +1601,9 @@ int PackW32Pe::buildLoader(const Filter *ft) void PackW32Pe::pack(OutputFile *fo) { + if (opt->win32_pe.strip_loadconf < 0) + opt->win32_pe.strip_loadconf = false; + const unsigned objs = ih.objects; isection = new pe_section_t[objs]; fi->seek(pe_offset+sizeof(ih),SEEK_SET); @@ -1612,8 +1615,8 @@ void PackW32Pe::pack(OutputFile *fo) // check the PE header // FIXME: add more checks - if (!opt->force - && (ih.cpu < 0x14c || ih.cpu > 0x150 + if (!opt->force && ( + ih.cpu < 0x14c || ih.cpu > 0x150 || ih.opthdrsize != 0xE0 || (ih.flags & EXECUTABLE) == 0 || (ih.subsystem != 2 && ih.subsystem != 3 && ih.subsystem != 1) @@ -1621,15 +1624,17 @@ void PackW32Pe::pack(OutputFile *fo) || ih.ddirsentries != 16 || IDSIZE(PEDIR_EXCEPTION) // is this used on i386? // || IDSIZE(PEDIR_COPYRIGHT) - || IDSIZE(PEDIR_LOADCONF) || IDSIZE(PEDIR_COMRT) )) throwCantPack("unexpected value in PE header (try --force)"); + // Structured Exception Handling + if (!opt->win32_pe.strip_loadconf && IDSIZE(PEDIR_LOADCONF)) + throwCantPack("Structured Exception Handling present (try --strip-loadconf)"); + if (IDSIZE(PEDIR_SEC)) throwCantPack("compressing certificate info is not supported"); - //if (IDSIZE(PEDIR_DELAYIMP)) - // throwCantPack("delay load imports are not supported"); + if (isdll) opt->win32_pe.strip_relocs = false; else if (opt->win32_pe.strip_relocs < 0) @@ -1904,6 +1909,12 @@ void PackW32Pe::pack(OutputFile *fo) ODADDR(PEDIR_BOUNDIM) = 0; ODSIZE(PEDIR_BOUNDIM) = 0; + if (opt->win32_pe.strip_loadconf) + { + ODADDR(PEDIR_LOADCONF) = 0; + ODSIZE(PEDIR_LOADCONF) = 0; + } + // tls is put into section 1 ic = s1addr + s1size - sotls; diff --git a/src/version.h b/src/version.h index 8be7792f..de355846 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ #define UPX_VERSION_HEX 0x019200 /* 01.92.00 */ #define UPX_VERSION_STRING "1.92 beta" #define UPX_VERSION_STRING4 "1.92" -#define UPX_VERSION_DATE "Jul 1st 2004" +#define UPX_VERSION_DATE "Jul 12th 2004"