I am trying to search for a very specific string in a folder full of binary files. The goal is to have the program open each binary file, search for the specific string and then print out file that the string is located in.
I think I have something that is close to working, but is not there yet. I was playing the bytes
on the string I want to search but I still am not finding anything. I have also tried struct.uppack
but that didn't seem to work either.
Any help is much appreciated. Thank you for your time.
Code:
import os
toSearch =bytes("find me","unicode_escape")
folderToSearch = "C:\\dir\\for\\bin\\files"
for root, dirs, files in os.walk(folderToSearch):
for file in files:
if file.endswith(".ROM"):
with open(root+"\\"+file,"rb") as binary_file:
fileContent = binary_file.read()
if fileContent.find(toSearch) != -1:
print(os.path.join(root, file))