From cc100be26e92609c99b68c02e7d1318a3330eb6e Mon Sep 17 00:00:00 2001 From: Kornel Pal Date: Wed, 22 Dec 2021 02:55:33 +0100 Subject: [PATCH] PE: Fix stripped relocation handling --- src/pefile.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 9de7d3c0..79de1b3d 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2316,7 +2316,10 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, if (IDSIZE(PEDIR_SEC)) IDSIZE(PEDIR_SEC) = IDADDR(PEDIR_SEC) = 0; - ih.flags |= handleStripRelocs(ih.imagebase, default_imagebase, ih.dllflags); + if (ih.flags & RELOCS_STRIPPED) + opt->win32_pe.strip_relocs = true; + else + ih.flags |= handleStripRelocs(ih.imagebase, default_imagebase, ih.dllflags); handleStub(fi,fo,pe_offset); unsigned overlaystart = readSections(objs, ih.imagesize, ih.filealign, ih.datasize); @@ -2568,7 +2571,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, // this one is tricky: it seems windoze touches 4 bytes after // the end of the relocation data - so we have to increase // the virtual size of this section - const unsigned ncsize_virt_increase = (ncsize & oam1) == 0 ? 8 : 0; + const unsigned ncsize_virt_increase = soxrelocs && (ncsize & oam1) == 0 ? 8 : 0; // fill the sections strcpy(osection[0].name,"UPX0");