I have a large specific binary file of data that I need to scan for a packet sync pattern 0xEB25. how do I search the file for that specified pattern in python?
Asked
Active
Viewed 109 times
0
-
It depends on what type of file your trying to scan. If your trying to scan a text file try going to this link: https://www.geeksforgeeks.org/reading-writing-text-files-python/. It would be easier if you also provided some code. – Maxim Jul 29 '20 at 01:33
1 Answers
0
If it's contained in a text file and that is Hex code, then this should work:
def isInFile(string):
with open('example.txt') as f:
if string in f.read():
print("true")
then just run
isInFile("1110101100100101")
Where 1110101100100101 is the hex you gave converted into binary
- See this answer for more specifics: How to search for a string in text files?

M. Chak
- 530
- 3
- 13