I recently extracted a bunch of raw bytes (from wireshark) into a regular .txt file.
Because these raw bytes are stored in a text file, all those hex-digits are actually written as ASCII characters on the disk.

Now, I want to interpret the ASCII encoded hex-digits as raw bytes, because they actually represent a .jpeg image.

I alredy tried to copy paste the digits into ghex, (I work on Ubuntu) but ghex only allows you to paste data into the interpreted area, not into the byte-manipulation area.

Is there a simple way to do this?


Not really a reverse engineering question but,

Use this in the terminal:

cat textfile.txt | xxd -r -p > image.jpeg

  • Thanks, but for which SE site is the question most appropriate? – J.Doe Mar 24 '20 at 17:13
  • It is a general technical question. I'd say that it belongs on the main StackOverflow site – Yotamz Mar 24 '20 at 17:21

Here's my go to in Python3: bytes.fromhex('020a0d')

From there you can interpret how you'd like.

Python 3.7.6 (default, Dec 30 2019, 19:38:26) 
>>> hex_str = '020a0d'
>>> bytes.fromhex(hex_str)

As an aside, I've found that storing things as ASCII Hex is one of the better RE habits I've gotten into. You can share the data with others, mark it up, examine it in any editor or IDE. Much better than pushing around an actual binary file.

  • You could also paste the bytes into something like CyberChef; convert to raw bytes and download the resultant file. – multithr3at3d Dec 1 '20 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.