From 1ce6f0e6f4ed0ca985cc6f3afeb640518a5e9ba3 Mon Sep 17 00:00:00 2001 From: bitraid Date: Sun, 12 Apr 2020 03:19:57 +0300 Subject: [PATCH] Fix unpacking of ASLR enabled PE files --- src/pefile.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 7bf66cbe..571c3529 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2933,6 +2933,18 @@ 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)) + { + oh.flags |= RELOCS_STRIPPED; + ODADDR(PEDIR_RELOC) = 0; + ODSIZE(PEDIR_RELOC) = 0; + } + rebuildImports(extrainfo, ord_mask, set_oft); rebuildRelocs(extrainfo, sizeof(ih.imagebase) * 8, oh.flags, oh.imagebase); rebuildTls(); @@ -2966,18 +2978,6 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, oh.headersize = rvamin; oh.chksum = 0; - //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)) - { - oh.flags |= RELOCS_STRIPPED; - ODADDR(PEDIR_RELOC) = 0; - ODSIZE(PEDIR_RELOC) = 0; - } - // write decompressed file if (fo) {