public void read ( ) throws IOException { try ( RandomAccessFile raf = new RandomAccessFile ( file , "r" ) ) { // check that offset location is within the file throwIf ( file . length ( ) < PE_OFFSET_LOCATION ) ; /* read pe signature offset at offset location */ byte [ ] offsetBytes = loadBytesSafely ( PE_OFFSET_LOCATION , PE_OFFSET_LOCATION_SIZE , raf ) ; // save signature offset peOffset = Optional . of ( ( long ) bytesToInt ( offsetBytes ) ) ; // check if supposed pe signature is within the file // a truncated signature has to be taken into account and allowed // see d_nonnull.dll throwIf ( file . length ( ) < peOffset . get ( ) || peOffset . get ( ) < 0 ) ; /* read PE signature at offset and verify */ byte [ ] peSigVal = loadBytesSafely ( peOffset . get ( ) , PE_SIG . length , raf ) ; for ( int i = 0 ; i < PE_SIG . length ; i ++ ) { throwIf ( peSigVal [ i ] != PE_SIG [ i ] ) ; } } }
Reads the PE signature and sets the peOffset .