From 10e34a2a218b1af3d8f5a84ff3e1d44b48364d20 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Wed, 3 Jun 2015 07:15:03 +0200 Subject: remove DWARF sections from executable --- CHANGES | 5 +++++ VERSION | 2 +- src/PEImage.cpp | 25 ++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 4bf87b4..9ba5f0d 100644 --- a/CHANGES +++ b/CHANGES @@ -220,3 +220,8 @@ unreleased Version 0.22 2015-05-08 Version 0.35 * new tool dumplines to display the debug line number info + +2015-06-03 Version 0.36 + + * last version introduced a regression that could cause DWARF conversion to crash + * DWARF sections now stripped from image (if last sections) diff --git a/VERSION b/VERSION index ec5227f..00f3c45 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION = 0.35 +VERSION = 0.36 diff --git a/src/PEImage.cpp b/src/PEImage.cpp index 707cc7e..ed663a2 100644 --- a/src/PEImage.cpp +++ b/src/PEImage.cpp @@ -146,10 +146,22 @@ bool PEImage::replaceDebugSection (const void* data, int datalen, bool initCV) // assume there is place for another section because of section alignment int s; DWORD lastVirtualAddress = 0; + int firstDWARFsection = -1; int cntSections = countSections(); for(s = 0; s < cntSections; s++) { - if (strcmp ((char*) sec [s].Name, ".debug") == 0) + const char* name = (const char*) sec[s].Name; + if(name[0] == '/') + { + int off = strtol(name + 1, 0, 10); + name = strtable + off; + } + if (strncmp (name, ".debug_", 7) != 0) + firstDWARFsection = -1; + else if (firstDWARFsection < 0) + firstDWARFsection = s; + + if (strcmp (name, ".debug") == 0) { if (s == cntSections - 1) { @@ -159,9 +171,14 @@ bool PEImage::replaceDebugSection (const void* data, int datalen, bool initCV) strcpy ((char*) sec [s].Name, ".ddebug"); printf("warning: .debug not last section, cannot remove section\n"); } - lastVirtualAddress = sec [s].VirtualAddress + sec[s].Misc.VirtualSize; + lastVirtualAddress = sec[s].VirtualAddress + sec[s].Misc.VirtualSize; } - + if (firstDWARFsection > 0) + { + s = firstDWARFsection; + dump_total_len = sec[s].PointerToRawData; + lastVirtualAddress = sec[s-1].VirtualAddress + sec[s-1].Misc.VirtualSize; + } int align = IMGHDR(OptionalHeader.FileAlignment); int align_len = xdatalen; int fill = 0; @@ -373,6 +390,8 @@ bool PEImage::initDWARFObject() static DWORD sizeInImage(const IMAGE_SECTION_HEADER& sec) { + if (sec.Misc.VirtualSize == 0) + return sec.SizeOfRawData; // for object files return sec.SizeOfRawData < sec.Misc.VirtualSize ? sec.SizeOfRawData : sec.Misc.VirtualSize; } -- cgit v0.12