From 1518e5bc981699c636dd2f1e29ec513ef0cb5c0e Mon Sep 17 00:00:00 2001 From: bitraid Date: Thu, 25 Mar 2021 21:41:49 +0200 Subject: [PATCH] PE: fix SizeOfHeaders value of Optional Header field --- src/p_w32pe.cpp | 3 +-- src/p_w64pep.cpp | 6 ------ src/p_w64pep.h | 2 +- src/pefile.cpp | 4 +--- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index b02d9e3b..c6363ee4 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -278,8 +278,7 @@ void PackW32Pe::setOhDataBase(const pe_section_t *osection) void PackW32Pe::setOhHeaderSize(const pe_section_t *osection) { - (void)osection; - oh.headersize = rvamin; // FIXME + oh.headersize = ALIGN_UP(pe_offset + sizeof(oh) + sizeof(osection) * oh.objects, oh.filealign); } void PackW32Pe::pack(OutputFile *fo) diff --git a/src/p_w64pep.cpp b/src/p_w64pep.cpp index 4a35be51..7166b9c6 100644 --- a/src/p_w64pep.cpp +++ b/src/p_w64pep.cpp @@ -266,12 +266,6 @@ void PackW64Pep::defineSymbols(unsigned ncsection, unsigned upxsection, linker->defineSymbol("START", upxsection); } -void PackW64Pep::setOhHeaderSize(const pe_section_t *osection) -{ - (void)osection; - oh.headersize = rvamin; // FIXME -} - void PackW64Pep::pack(OutputFile *fo) { // FIXME: Relocation stripping disabled for now - Stefan Widmann diff --git a/src/p_w64pep.h b/src/p_w64pep.h index aac38156..cf1b409b 100644 --- a/src/p_w64pep.h +++ b/src/p_w64pep.h @@ -51,7 +51,7 @@ public: unsigned sizeof_oh, unsigned isize_isplit, unsigned s1addr); virtual void setOhDataBase(const pe_section_t *) {} - virtual void setOhHeaderSize(const pe_section_t *osection); + virtual void setOhHeaderSize(const pe_section_t *) {} virtual void pack(OutputFile *fo); virtual bool canPack(); diff --git a/src/pefile.cpp b/src/pefile.cpp index 06b0cf9f..a75331c7 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2997,9 +2997,7 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, ODADDR(PEDIR_BOUNDIM) = 0; ODSIZE(PEDIR_BOUNDIM) = 0; - // oh.headersize = osection[0].rawdataptr; - // oh.headersize = ALIGN_UP(pe_offset + sizeof(oh) + sizeof(pe_section_t) * objs, oh.filealign); - oh.headersize = rvamin; + setOhHeaderSize(osection); oh.chksum = 0; // write decompressed file