private SectionTable loadSectionTable ( PESignature pesig , COFFFileHeader coff , RandomAccessFile raf ) throws IOException { // offset is the start of the optional header + SizeOfOptionalHeader long offset = pesig . getOffset ( ) + PESignature . PE_SIG . length + COFFFileHeader . HEADER_SIZE + coff . getSizeOfOptionalHeader ( ) ; logger . info ( "SectionTable offset: " + offset ) ; // get entries, so you can determine the size int numberOfEntries = ( int ) coff . getNumberOfSections ( ) ; int size = SectionTable . ENTRY_SIZE * numberOfEntries ; if ( size + offset > file . length ( ) ) { size = ( int ) ( file . length ( ) - offset ) ; } if ( size <= 0 ) { logger . warn ( "Unable to parse Section table, offset outside the file" ) ; return new SectionTable ( new byte [ 0 ] , 0 , offset ) ; } // read bytes byte [ ] tableBytes = loadBytes ( offset , size , raf ) ; // construct header return new SectionTable ( tableBytes , numberOfEntries , offset ) ; }
Loads the section table . Presumes a valid PE file .