public Optional < SectionHeader > maybeGetSectionTableEntry ( SectionTable table ) { checkArgument ( table != null , "table must not be null" ) ; List < SectionHeader > sections = table . getSectionHeaders ( ) ; // loop through all section headers to check if entry is within section for ( SectionHeader header : sections ) { long vSize = header . getAlignedVirtualSize ( ) ; // corkami: "a section can have a null VirtualSize: in this case, // only the SizeOfRawData is taken into consideration. " // see: https://code.google.com/p/corkami/wiki/PE#section_table if ( vSize == 0 ) { vSize = header . getAlignedSizeOfRaw ( ) ; } long vAddress = header . getAlignedVirtualAddress ( ) ; logger . debug ( "check if rva is within " + vAddress + " and " + ( vAddress + vSize ) ) ; // return header if data entry va points into it if ( rvaIsWithin ( new VirtualLocation ( vAddress , vSize ) ) ) { return Optional . of ( header ) ; } } logger . warn ( "there is no entry that matches data dir entry RVA " + virtualAddress ) ; return Optional . absent ( ) ; }
more convenient use of the API