I'm trying to code a program where I can:
- Load a file
- Input a start and beginning offset addresses where to scan data from
- Scan that offset range in search of specific sequence of bytes (such as "05805A6C")
- Retrieve the offset of every match and write them to a .txt file
i66.tinypic.com/2zelef5.png
As the picture shows I need to search the file for "05805A6C" and then print to a .txt file the offset "0x21F0".
I'm using Java Swing for this. So far I've been able to load the file as a Byte array[]. But I haven't found a way how to search for the specific sequence of bytes, nor setting that search between a range of offsets.
This is my code that opens and reads the file into byte array[]
public class Read { static public byte[] readBytesFromFile () { try { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { FileInputStream input = new FileInputStream(chooser.getSelectedFile()); byte[] data = new byte[input.available()]; input.read(data); input.close(); return data; } return null; } catch (IOException e) { System.out.println("Unable to read bytes: " + e.getMessage()); return null; } } } And my code where I try to search among the bytes.
byte[] model = Read.readBytesFromFile(); String x = new String(model); boolean found = false; for (int i = 0; i < model.length; i++) { if(x.contains("05805A6C")){ found = true; } } if(found == true){ System.out.println("Yes"); }else{ System.out.println("No"); }
"pmdl"is aString(not abyte[]).