From 17bd0b3248aeeb3cc7c9ae7f6eee069585fd8e4b Mon Sep 17 00:00:00 2001 From: bitraid Date: Mon, 13 Apr 2020 21:38:22 +0300 Subject: [PATCH] Don't use --strip-reloc with -d Always restore the relocation section of Portable Executables on unpacking, if it exists in the compressed image. --- src/pefile.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 571c3529..1988321f 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2693,15 +2693,7 @@ void PeFile::rebuildRelocs(upx_byte *& extrainfo, unsigned bits, } rel.finish (oxrelocs,soxrelocs); - if (opt->win32_pe.strip_relocs && !isdll) - { - obuf.clear(ODADDR(PEDIR_RELOC) - rvamin, ODSIZE(PEDIR_RELOC)); - ODADDR(PEDIR_RELOC) = 0; - soxrelocs = 0; - // FIXME: try to remove the original relocation section somehow - } - else - omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs); + omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs); delete [] oxrelocs; oxrelocs = NULL; wrkmem.dealloc(); @@ -2933,12 +2925,8 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, ft.unfilter(obuf + oh.codebase - rvamin, oh.codesize); } - //NEW: disable reloc stripping if ASLR is enabled - if(ih.dllflags & IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE) - opt->win32_pe.strip_relocs = false; - // FIXME: ih.flags is checked here because of a bug in UPX 0.92 - if ((opt->win32_pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED)) + if (ih.flags & RELOCS_STRIPPED) { oh.flags |= RELOCS_STRIPPED; ODADDR(PEDIR_RELOC) = 0;