summaryrefslogtreecommitdiffstats
path: root/src/PEImage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/PEImage.cpp')
-rw-r--r--src/PEImage.cpp67
1 files changed, 22 insertions, 45 deletions
diff --git a/src/PEImage.cpp b/src/PEImage.cpp
index 99c6776..247d514 100644
--- a/src/PEImage.cpp
+++ b/src/PEImage.cpp
@@ -35,19 +35,6 @@ PEImage::PEImage(const TCHAR* iname)
, hdr32(0)
, hdr64(0)
, fd(-1)
-, debug_aranges(0)
-, debug_pubnames(0)
-, debug_pubtypes(0)
-, debug_info(0), debug_info_length(0)
-, debug_abbrev(0), debug_abbrev_length(0)
-, debug_line(0), debug_line_length(0)
-, debug_frame(0), debug_frame_length(0)
-, debug_str(0)
-, debug_loc(0), debug_loc_length(0)
-, debug_ranges(0), debug_ranges_length(0)
-, codeSegment(0)
-, linesSegment(-1)
-, reloc(0), reloc_length(0)
, nsec(0)
, nsym(0)
, symtable(0)
@@ -470,6 +457,15 @@ static DWORD sizeInImage(const IMAGE_SECTION_HEADER& sec)
return sec.SizeOfRawData < sec.Misc.VirtualSize ? sec.SizeOfRawData : sec.Misc.VirtualSize;
}
+void PEImage::initSec(PESection& peSec, int secNo) const
+{
+ auto &imgSec = sec[secNo];
+
+ peSec.length = sizeInImage(imgSec);
+ peSec.base = DPV<byte>(imgSec.PointerToRawData, peSec.length);
+ peSec.secNo = secNo;
+}
+
void PEImage::initDWARFSegments()
{
for(int s = 0; s < nsec; s++)
@@ -480,49 +476,30 @@ void PEImage::initDWARFSegments()
int off = strtol(name + 1, 0, 10);
name = strtable + off;
}
- if(strcmp(name, ".debug_aranges") == 0)
- debug_aranges = DPV<char>(sec[s].PointerToRawData, sizeInImage(sec[s]));
- if(strcmp(name, ".debug_pubnames") == 0)
- debug_pubnames = DPV<char>(sec[s].PointerToRawData, sizeInImage(sec[s]));
- if(strcmp(name, ".debug_pubtypes") == 0)
- debug_pubtypes = DPV<char>(sec[s].PointerToRawData, sizeInImage(sec[s]));
- if(strcmp(name, ".debug_info") == 0)
- debug_info = DPV<char>(sec[s].PointerToRawData, debug_info_length = sizeInImage(sec[s]));
- if(strcmp(name, ".debug_abbrev") == 0)
- debug_abbrev = DPV<char>(sec[s].PointerToRawData, debug_abbrev_length = sizeInImage(sec[s]));
- if(strcmp(name, ".debug_line") == 0)
- debug_line = DPV<char>(sec[linesSegment = s].PointerToRawData, debug_line_length = sizeInImage(sec[s]));
- if (strcmp(name, ".debug_line_str") == 0)
- debug_line_str = DPV<char>(sec[s].PointerToRawData, debug_line_str_length = sizeInImage(sec[s]));
- if(strcmp(name, ".debug_frame") == 0)
- debug_frame = DPV<char>(sec[s].PointerToRawData, debug_frame_length = sizeInImage(sec[s]));
- if(strcmp(name, ".debug_str") == 0)
- debug_str = DPV<char>(sec[s].PointerToRawData, sizeInImage(sec[s]));
- if(strcmp(name, ".debug_loc") == 0)
- debug_loc = DPV<char>(sec[s].PointerToRawData, debug_loc_length = sizeInImage(sec[s]));
- if(strcmp(name, ".debug_ranges") == 0)
- debug_ranges = DPV<char>(sec[s].PointerToRawData, debug_ranges_length = sizeInImage(sec[s]));
- if(strcmp(name, ".reloc") == 0)
- reloc = DPV<char>(sec[s].PointerToRawData, reloc_length = sizeInImage(sec[s]));
- if(strcmp(name, ".text") == 0)
- codeSegment = s;
+
+ for (const SectionDescriptor *sec_desc : sec_descriptors) {
+ if (!strcmp(name, sec_desc->name)) {
+ PESection& peSec = this->*(sec_desc->pSec);
+ initSec(peSec, s);
+ }
+ }
}
}
bool PEImage::relocateDebugLineInfo(unsigned int img_base)
{
- if(!reloc || !reloc_length)
+ if(!reloc.isPresent())
return true;
- char* relocbase = reloc;
- char* relocend = reloc + reloc_length;
+ byte* relocbase = reloc.startByte();
+ byte* relocend = reloc.endByte();
while(relocbase < relocend)
{
unsigned int virtadr = *(unsigned int *) relocbase;
unsigned int chksize = *(unsigned int *) (relocbase + 4);
char* p = RVA<char> (virtadr, 1);
- if(p >= debug_line && p < debug_line + debug_line_length)
+ if(debug_line.isPtrInside(p))
{
for (unsigned int w = 8; w < chksize; w += 2)
{
@@ -536,7 +513,7 @@ bool PEImage::relocateDebugLineInfo(unsigned int img_base)
}
}
}
- if(chksize == 0 || chksize >= reloc_length)
+ if(chksize == 0 || chksize >= reloc.length)
break;
relocbase += chksize;
}
@@ -545,7 +522,7 @@ bool PEImage::relocateDebugLineInfo(unsigned int img_base)
int PEImage::getRelocationInLineSegment(unsigned int offset) const
{
- return getRelocationInSegment(linesSegment, offset);
+ return getRelocationInSegment(debug_line.secNo, offset);
}
int PEImage::getRelocationInSegment(int segment, unsigned int offset) const