From 243873cd2d58c5e979cf6327631a5727616ab0ec Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 7 Apr 2006 03:41:26 +0000 Subject: [PATCH] Workaround inconsistent SIZEOF_HEADERS in stub/*.lds. Test with --force-execve and --no-filter. p_lx_exc.cpp p_lx_sh.cpp stub/l_lx_sh86.asm stub/l_lx_sh86.h committer: jreiser 1144381286 +0000 --- src/p_lx_exc.cpp | 21 ++++++++++++++++++--- src/p_lx_sh.cpp | 17 ++++++++++++++++- src/stub/l_lx_sh86.asm | 1 + src/stub/l_lx_sh86.h | 16 ++++++++-------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index a85e2028..2479dd81 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -260,8 +260,12 @@ PackLinuxI386::buildLinuxLoader( unsigned fold_hdrlen = 0; if (0 < szfold) { cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold; - fold_hdrlen = umax(0x80, sizeof(hf->ehdr) + - hf->ehdr.e_phentsize * hf->ehdr.e_phnum + sizeof(l_info) ); + fold_hdrlen = sizeof(hf->ehdr) + hf->ehdr.e_phentsize * hf->ehdr.e_phnum + + sizeof(l_info); + if (0==*(int *)(fold_hdrlen + fold)) { + // inconsistent SIZEOF_HEADERS in *.lds (ld, binutils) + fold_hdrlen = umax(0x80, fold_hdrlen); + } h.sz_unc = (szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen); h.b_method = (unsigned char) ph.method; h.b_ftid = (unsigned char) ph.filter; @@ -362,6 +366,9 @@ PackLinuxI386::buildLinuxLoader( addLoader("LEXEC017", NULL); } } + else { + addLoader("LEXEC017", NULL); + } addLoader("IDENTSTR", NULL); addLoader("LEXEC020", NULL); @@ -402,7 +409,14 @@ PackLinuxI386::buildLoader(Filter const *ft) // filter optimizeFilter(&fold_ft, buf, sz_fold); - bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2)); + + unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) + + sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum); + if (0==*(int *)(fold_hdrlen + buf)) { + // inconsistent SIZEOF_HEADERS in *.lds (ld, binutils) + fold_hdrlen = umax(0x80, fold_hdrlen); + } + bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen); (void)success; return buildLinuxLoader( @@ -410,6 +424,7 @@ PackLinuxI386::buildLoader(Filter const *ft) buf, sz_fold, ft ); } +// FIXME: getLoaderPrefixSize is unused? int PackLinuxI386::getLoaderPrefixSize() const { return 116; diff --git a/src/p_lx_sh.cpp b/src/p_lx_sh.cpp index cd4455b7..24137ca0 100644 --- a/src/p_lx_sh.cpp +++ b/src/p_lx_sh.cpp @@ -59,6 +59,15 @@ PackLinuxI386sh::~PackLinuxI386sh() { } +static unsigned +umax(unsigned a, unsigned b) +{ + if (a <= b) { + return b; + } + return a; +} + int PackLinuxI386sh::buildLoader(Filter const *ft) { @@ -78,7 +87,13 @@ PackLinuxI386sh::buildLoader(Filter const *ft) // filter optimizeFilter(&fold_ft, buf, sz_fold); - bool success = fold_ft.filter(buf + sizeof(cprElfHdr2), sz_fold - sizeof(cprElfHdr2)); + unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) + + sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum); + if (0==*(int *)(fold_hdrlen + buf)) { + // inconsistent SIZEOF_HEADERS in *.lds (ld, binutils) + fold_hdrlen = umax(0x80, fold_hdrlen); + } + bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen); UNUSED(success); return buildLinuxLoader( diff --git a/src/stub/l_lx_sh86.asm b/src/stub/l_lx_sh86.asm index 9b4f1b47..c84eec05 100644 --- a/src/stub/l_lx_sh86.asm +++ b/src/stub/l_lx_sh86.asm @@ -107,6 +107,7 @@ decompress: mov [edx], edi mov [7*4 + esp], eax +;__LEXEC017__ popa ret diff --git a/src/stub/l_lx_sh86.h b/src/stub/l_lx_sh86.h index 1173257a..19fc2669 100644 --- a/src/stub/l_lx_sh86.h +++ b/src/stub/l_lx_sh86.h @@ -1,4 +1,4 @@ -/* l_lx_sh86.h -- created from l_lx_sh86.bin, 4403 (0x1133) bytes +/* l_lx_sh86.h -- created from l_lx_sh86.bin, 4416 (0x1140) bytes This file is part of the UPX executable compressor. @@ -27,11 +27,11 @@ */ -#define LINUX_I386SH_LOADER_SIZE 4403 -#define LINUX_I386SH_LOADER_ADLER32 0xa08bedc6 -#define LINUX_I386SH_LOADER_CRC32 0x64e997fc +#define LINUX_I386SH_LOADER_SIZE 4416 +#define LINUX_I386SH_LOADER_ADLER32 0x93e2f039 +#define LINUX_I386SH_LOADER_CRC32 0x1614a613 -unsigned char linux_i386sh_loader[4403] = { +unsigned char linux_i386sh_loader[4416] = { 232, 0, 0, 0, 0, 96,139,116, 36, 36,139,124, 36, 44,131,205, /* 0x 0 */ 255,235, 0,164,235, 0,138, 6, 70,136, 7, 71, 1,219,117, 7, /* 0x 10 */ 139, 30,131,238,252, 17,219,114, 0, 49,192, 64,138, 7,114, 0, /* 0x 20 */ @@ -305,7 +305,7 @@ unsigned char linux_i386sh_loader[4403] = { 70, 4, 0, 0, 0, 0, 0, 0, 75, 4, 0, 0, 67, 65, 76, 76, /* 0x10e0 */ 84, 82, 49, 48, 0, 5, 0, 0, 0, 67, 84, 84, 72, 69, 69, 78, /* 0x10f0 */ 68, 0, 75, 4, 0, 0, 76, 69, 88, 69, 67, 48, 49, 53, 0, 75, /* 0x1100 */ - 4, 0, 0, 76, 69, 88, 69, 67, 48, 50, 48, 0,104, 4, 0, 0, /* 0x1110 */ - 88, 84, 72, 69, 69, 78, 68, 88, 0,171, 4, 0, 0,255,255,255, /* 0x1120 */ -255,171, 4 /* 0x1130 */ + 4, 0, 0, 76, 69, 88, 69, 67, 48, 49, 55, 0,102, 4, 0, 0, /* 0x1110 */ + 76, 69, 88, 69, 67, 48, 50, 48, 0,104, 4, 0, 0, 88, 84, 72, /* 0x1120 */ + 69, 69, 78, 68, 88, 0,171, 4, 0, 0,255,255,255,255,171, 4 /* 0x1130 */ };