public long getOffset ( ) throws IOException { if ( offset == null ) { read ( ) ; SectionTable table = data . getSectionTable ( ) ; SectionLoader loader = new SectionLoader ( data ) ; offset = 0L ; List < SectionHeader > headers = table . getSectionHeaders ( ) ; // TODO low alingment check instead? // if (headers.size() == 0) { // offset for sectionless PE's // offset = file.length(); // } for ( SectionHeader section : headers ) { long alignedPointerToRaw = section . getAlignedPointerToRaw ( ) ; long readSize = loader . getReadSize ( section ) ; // ignore invalid sections // corkami: "if a section starts at [unaligned] offset 0, it's invalid." if ( readSize == 0 || section . get ( SectionHeaderKey . POINTER_TO_RAW_DATA ) == 0 ) { continue ; } long endPoint = readSize + alignedPointerToRaw ; if ( offset < endPoint ) { // determine largest endPoint offset = endPoint ; } } } if ( offset > file . length ( ) || offset == 0 ) { offset = file . length ( ) ; } return offset ; }
Returns the file offset of the overlay .