diff --git a/include/retdec/pelib/PeHeader.h b/include/retdec/pelib/PeHeader.h index db2b96136..56a123d6c 100644 --- a/include/retdec/pelib/PeHeader.h +++ b/include/retdec/pelib/PeHeader.h @@ -1094,6 +1094,16 @@ namespace PeLib ibBuffer >> ishCurr.NumberOfRelocations; ibBuffer >> ishCurr.NumberOfLinenumbers; ibBuffer >> ishCurr.Characteristics; + + // PointerToRawData is aligned down to 0x200 by the Windows loader. + // This is because the section is mapped to memory based on file sectors. + // This behavior is independent of the FileAlignment value + // and only happens when SectionAlignment is greater or equal to page size + if(header.OptionalHeader.SectionAlignment >= PELIB_PAGE_SIZE) + { + ishCurr.PointerToRawData = ishCurr.PointerToRawData & ~(PELIB_SECTOR_SIZE - 1); + } + vIshdCurr.push_back(ishCurr); uiOffset += PELIB_IMAGE_SECTION_HEADER::size(); diff --git a/include/retdec/pelib/PeLibAux.h b/include/retdec/pelib/PeLibAux.h index 43f53d410..262355a0f 100644 --- a/include/retdec/pelib/PeLibAux.h +++ b/include/retdec/pelib/PeLibAux.h @@ -230,6 +230,8 @@ namespace PeLib const dword PELIB_MAX_IMPORTED_FUNCTIONS = 0x1000; // Maximum number of exported functions (per DLL) that we support const dword PELIB_MAX_EXPORTED_FUNCTIONS = 0x1000; // Maximum number of exported functions that we support + const dword PELIB_SECTOR_SIZE = 0x200; + template struct PELIB_IMAGE_ORDINAL_FLAGS; diff --git a/src/fileinfo/fileinfo.cpp b/src/fileinfo/fileinfo.cpp index 5a8b52aa8..b2f79a19c 100644 --- a/src/fileinfo/fileinfo.cpp +++ b/src/fileinfo/fileinfo.cpp @@ -525,3 +525,4 @@ int main(int argc, char* argv[]) delete fileDetector; return isFatalError(res) ? static_cast(res) : static_cast(ReturnCode::OK); } +