public BufferedImage createEntropyImage ( File file ) throws IOException { resetAvailabilityFlags ( ) ; this . data = new PEData ( null , null , null , null , null , file ) ; image = new BufferedImage ( fileWidth , height , IMAGE_TYPE ) ; final int MIN_WINDOW_SIZE = 100 ; // bytes to be read at once to calculate local entropy final int windowSize = Math . max ( MIN_WINDOW_SIZE , pixelSize ) ; final int windowHalfSize = ( int ) Math . round ( windowSize / ( double ) 2 ) ; final long minLength = withMinLength ( 0 ) ; try ( RandomAccessFile raf = new RandomAccessFile ( file , "r" ) ) { // read until EOF with windowSized steps for ( long address = 0 ; address <= file . length ( ) ; address += minLength ) { // the start of the window (windowHalf to the left) long start = ( address - windowHalfSize < 0 ) ? 0 : address - windowHalfSize ; raf . seek ( start ) ; // cut byte number if EOF reached, otherwise read full window int bytesToRead = ( int ) Math . min ( file . length ( ) - start , windowSize ) ; byte [ ] bytes = new byte [ bytesToRead ] ; raf . readFully ( bytes ) ; /* calculate and draw entropy square pixel for this window */ double entropy = ShannonEntropy . entropy ( bytes ) ; Color color = getColorForEntropy ( entropy ) ; drawPixels ( color , address , minLength ) ; } } drawVisOverlay ( true ) ; return image ; }
Creates an image of the local entropies of this file .