search binary file and list all founded keyword offset
with open('1.bin', 'rb') as f:
s = f.read()
k = s.find(b'\xFF\x00')
for list in k:
print(list)
and i got error
TypeError:'int' object in not interable.
please help. thanks.
You can use regular expression for this, e.g.
import re
with open('1.bin', 'rb') as f:
s = f.read()
for match in s.finditer(b'\xFF\x00'): # UPD: should be re.finditer(b'\xFF\x00', s)
print(match.span())
(Mar-16-2020, 12:04 PM)scidam Wrote: [ -> ]You can use regular expression for this, e.g.
import re
with open('1.bin', 'rb') as f:
s = f.read()
for match in s.finditer(b'\xFF\x00'):
print(match.span())
thanks for help.
i got error with your code. "AttributeError: 'bytes' object has no attribute 'finditer'"
and i try with
import re
with open('1.bin', 'rb') as f:
s = f.read()
for match in re.finditer(b'\xFF\x00'):
print(match.span())
got error"TypeError: finditer() missing 1 required positional argument: 'string'"
I'm sorry, that was a typo; It should be re.finditer(b'\xFF\x00', s)
.