diff options
author | Rainer Schuetze <r.sagitario@gmx.de> | 2020-03-09 06:59:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 06:59:21 (GMT) |
commit | b4649ddf354245cfb8b8cf3fd0bc9c1987ee9828 (patch) | |
tree | c6c3ebf4ad5f07666baf0b0c75da9cd68e2ca5b8 | |
parent | 3239e14109ac416358e1962932fdd360e724beea (diff) | |
parent | 8c9ad1da866f2a57a47b3cf1c74f20b61537381c (diff) | |
download | cv2pdb-b4649ddf354245cfb8b8cf3fd0bc9c1987ee9828.zip cv2pdb-b4649ddf354245cfb8b8cf3fd0bc9c1987ee9828.tar.gz cv2pdb-b4649ddf354245cfb8b8cf3fd0bc9c1987ee9828.tar.bz2 |
Merge pull request #58 from dscho/invalidate-symbol-table
Fix `.exe` files (according to dumpbin/objdump)
-rw-r--r-- | src/PEImage.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/PEImage.cpp b/src/PEImage.cpp index d3651c8..5808cf9 100644 --- a/src/PEImage.cpp +++ b/src/PEImage.cpp @@ -225,6 +225,19 @@ bool PEImage::replaceDebugSection (const void* data, int datalen, bool initCV) IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress) = lastVirtualAddress + datalen;
IMGHDR(OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size) = sizeof(IMAGE_DEBUG_DIRECTORY);
+ // invalidate the symbol table pointer if it points outside of the data to be copied
+ IMAGE_DOS_HEADER *dos = DPV<IMAGE_DOS_HEADER>(0);
+ if(dos && dos->e_magic == IMAGE_DOS_SIGNATURE)
+ {
+ // The 32-bit and 64-bit headers are identical in the FileHeader part, so we just use the 32-bit one
+ IMAGE_NT_HEADERS32* hdr = DPV<IMAGE_NT_HEADERS32>(dos->e_lfanew);
+ if(hdr && hdr->FileHeader.PointerToSymbolTable >= dump_total_len)
+ {
+ hdr->FileHeader.PointerToSymbolTable = 0;
+ hdr->FileHeader.NumberOfSymbols = 0;
+ }
+ }
+
// append debug data chunk to existing file image
memcpy(newdata, dump_base, dump_total_len);
memset(newdata + dump_total_len, 0, fill);
|