From be801a24a6aa79d306b00bb9478430636a13bd1d Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Fri, 29 Apr 2011 15:07:00 +0100 Subject: [PATCH] Read Portable Executable sections --- portexec.d | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/portexec.d b/portexec.d index 89b786c..013c325 100644 --- a/portexec.d +++ b/portexec.d @@ -84,6 +84,7 @@ class PortableExecutable readOptionalHeader(input); readDataDirectories(input); readSectionTable(input); + readSections(input); } @@ -148,8 +149,31 @@ class PortableExecutable readInput(input, sectionHeaderEntry); } } - - + + + private void readSections(Stream input) + in + { + assert(input.seekable); + // Section Table must have been read + } + body + { + sections = new ubyte[][sectionHeaderEntries.length]; + + foreach (i, ref sectionHeaderEntry; sectionHeaderEntries) + { + //TODO: ensure pointerToRawData is within file bounds + if (sectionHeaderEntry.pointerToRawData > 0) + { + input.position(sectionHeaderEntry.pointerToRawData); + sections[i] = new ubyte[sectionHeaderEntry.sizeOfRawData]; + input.read(sections[i]); + } + } + } + + bool isPe32() { return peMagicNumber == PeMagicNumber.PE32;