Skip to content

Commit

Permalink
Read Portable Executable sections
Browse files Browse the repository at this point in the history
  • Loading branch information
pdfrod committed Apr 29, 2011
1 parent 8dcc9ce commit be801a2
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions portexec.d
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class PortableExecutable
readOptionalHeader(input);
readDataDirectories(input);
readSectionTable(input);
readSections(input);
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit be801a2

Please sign in to comment.