-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
  • 99,904
  • 114
  • 238
  • 340

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
  • 106,415
  • 33
  • 201
  • 300