Convert (.hex?) file to viewable image

14,922

This looks like a jpeg file, encoded in a .hex file.

I'm not used to working with hex files, but the 7 first digit look like they are basically counting lines. I'll just ignore them, i'm sure you can find documentation on what exactly there role is (if any!). The real data bytes are what is encoded in the rest of each line.

Sometime ago, I wrote a lightweight jpeg encoder. I went into the source to see if the bytes I can see in your file rang a bell:

The file starts with d8ff, and the code I wrote for encoding jpeg, which starts by writing the file header which identifies it as a jpeg and encodes information about it such as its size, starts by writing the bytes FFDB (see this line, where "SOI" stands for "Start Of File").

We then have e0ff 1000 464a 4649 0100 0001... and my code writes: FFE0 0010 4A46 4946 0001 0100 (see line 127 and following), which are the next bytes of a standard JPEG file with a JFIF header.

Finally, the 3 last bytes of your file are d9ff, and jpec writes FFD9 as the End Of File bytes.

Obviously, your file is not written with the same endianness as my code (actually it looks like it is middle-endian, i've not really seen that before...), but you can see that every packet of 2 bytes (4 hex characters) is the same when inverting the order of these two bytes! This is obviously a jpeg-encoded image...

To read this as an image, I would try:

  1. simply stripping the 7 first digits of each line and writing the remaining bytes as a binary file, if the endianness of this hex file fits the one on your machine, or
  2. stripping the 7 first digits and reversing the order of each packet of 2 bytes, and writing it as a binary file, if the endianness of your machine fits the one I wrote Jpec for!

Hope this helps!

Share:
14,922
user2636689
Author by

user2636689

Updated on June 04, 2022

Comments

  • user2636689
    user2636689 almost 2 years

    I was recently given a text file and told that it could be converted into an image. The text file looks like this...

    0000000 d8ff e0ff 1000 464a 4649 0100 0001 0100
    0000010 0100 0000 e2ff a80c 4349 5f43 5250 464f
    0000020 4c49 0045 0101 0000 980c 7061 6c70 1002
    ...
    000d320 8b4c 1b28 3bd4 0016 91e0 799e 34c1 4457
    000d330 7113 ee4d cd73 4945 63db d9ff          
    000d33c
    

    From googling, I'm pretty sure that this is a .hex file (though many of the hex files I have seen online had different formats, so I am not certain).

    When I search for 'converting hex to image', the results that are formatted like mine are really dry.

    Is anyone certain on what type of file this is and how I can convert it back to a view-able image?

    Thanks