I want to count the occurrences of a particular header section in a binary file with Python 2.7.3. I have found plenty of examples to count occurrences in .txt type files and to do with lines but little info on counting byte sequences in binaries.
Thoughts are you would use the ASCII characters in the binary to use a string to search for.
The header section in hex is "28 00 28 00 28 00" or "( ( ( " in ascii.
I thought the code would be something like this:
total = 0
for line in f:
if "( ( ( " in line:
total += 1
f.close()
print "%s" % total
But it doesn't even seem to count once, it'll print line and that is 120 chars long.