pyguys
pyguys

Reputation: 1

python search file hex value and list keyword offset

In Python, I am trying to get the offset (relative to the beginning of the file) of byte-code 0x8212 on a binary file with the following code

with open('test.bin', 'rb') as f:
    s = f.read()
    k = s.find(b'\x82\x12')
    for l in k:
        print(l)

but it throws error

TypeError:'int' object in not interable. 

Please advice.

Upvotes: 0

Views: 450

Answers (1)

barbecu
barbecu

Reputation: 742

string.find() returns the lowest index occurence of the value, Therefore k is an integer and not a list and cannot be iterated over.

If you want a list try using regex or reference this article: How to find all occurrences of a substring?

Upvotes: 1

Related Questions