0

I am writing a file-data searching script and want to allow the user to search for a string of hex values (via argv). I had to switch from PHP to Python because the maximum value of integers are (too) limited on 32-bit PHP/machines. In PHP I could just do:

$SearchValue = pack('H*', $Input);

However, in Python there does not seem to be any equivalent for this format character. What are some alternatives for this conversion in Python, if any? The output needs to be a binary string (b'...').

2
  • 2
    docs.python.org/2/library/struct.html Commented Nov 24, 2014 at 8:25
  • @AshwiniChaudhary Is it really possible to convert a hex string to binary data through struct.pack? If so, how exactly? I looked but I didn't find anything - did I miss something? Commented Nov 24, 2014 at 8:43

1 Answer 1

2
3>> import binascii
3>> binascii.unhexlify('deadbeef')
b'\xde\xad\xbe\xef'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.