-1

I read this post regarding openning a file in binary format: Reading binary file in Python and looping over each byte

How can I match a string (as hex value) with a binary file in python: as an example, i want to match this in a binary file

00e4009a00ea00ff00a800cd00930018006b00e10067000e00e0002c00710045

How can i compare that with the content in the binary file?

Community
  • 1
  • 1
michael
  • 106,540
  • 116
  • 246
  • 346

1 Answers1

2

Turn the hexadecimal data into binary before matching:

import binascii

pattern = "00e4009a00ea00ff00a800cd00930018006b00e10067000e00e0002c00710045"

if binascii.unhexlify(pattern) in binary_file_contents:
    pass
orlp
  • 112,504
  • 36
  • 218
  • 315