Added new win32/pe option `--strip-loadconf'.

committer: mfx <mfx> 1089630382 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2004-07-12 11:06:22 +00:00
parent 3177de92fb
commit cbf1dbe2cb
9 changed files with 41 additions and 17 deletions

1
NEWS
View File

@ -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

5
TODO
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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);

View File

@ -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;
};

View File

@ -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;

View File

@ -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"