0

I need to search a binary file for particular strings. The strings come from a word list in a text file. I think it would be easier to translate the words from the text file into a format that can then be searched. The format that I need to translate the strings into is a hexadecimal byte notation. For Example, I need to search for the string TRUE, here is what I need the end product to look like:

Original Word = TRUE
Hex Translate = b'\x54\x52\x55\x45'

I've been attempting to do this several ways, to no success. Here is my current attempt:

 for word in dirtyWords:
        data = word.strip('\n')
        data = word.encode('utf-8')
        data = binascii.hexlify(data)
        print(data)
        data = str(data).replace("b'",'').replace("'",'')
        sx = r"\x" + r"\x".join(data[n : n+2] for n in range(0, len(data), 2))
        print(sx)
        sx = sx.encode('utf-8')
        print(sx)

This gives me the following output:

b'54525545'
\x54\x52\x55\x45
b'\\x54\\x52\\x55\\x45'

The byte encoding is adding an extra backslash to which when I attempt to search the binary file, it will of course fail. Any ideas?

Joshua Faust
  • 306
  • 2
  • 16

0 Answers0