I want to make a program which reads .bin files which I want to find occurrences of certain patterns of Hex. I know the first 2 bytes and I know the total number of bytes of each occurrences. I also know illegal character which would indicate an occurrence that I’m not interested in.
So for example the hex I am looking for would start: 0x12 0x34 followed by 8 bytes which I don’t know. The illegal characters would be anything which contained a hex letter i.e 0x0f. So...
0x12 0x34 0x12 0x45 0x25 0x23 0x12 0x32 0x87 0x12 (this would be read)
0x12 0x34 0x22 0x78 0x23 0x11 0x10 0x78 0x87 0x11 (this would be read)
0x12 0x34 0x12 0x45 0x25 0x23 0x12 0x32 0x87 0x1d (this would not due to an illegal character)
Furthermore I then need to reverse the characters of each hex pair of each occurrence before outputting to a txt file so in the above example I would get a txt file with.
One step at a time.
read from file, until you find 0x12. when you do, read the next byte and see if it is 0x34. if yes, read 8 more bytes into an array. search for illegal values. I suggest you split one byte in two (low = byte & 0xF; high = byte >> 4) then if either half is >= 10, it is illegal. if you don't find any, start outputting. to swap digits, split them like before.