Search code examples
grepjpegxxd

Hex format of JPEG, can image end ffd9 be in 9 and a columns


For solving some problems in steganography, I need to look for end of images in hex

I am using

xxd image.jpeg|grep ffd9

it does return the line having ffd9 when it is in C and D columns

but the same does not return anything when it is in 9 and A columns


Solution

  • With GNU grep this will give you the byte-offsets of the EOI markers:

    LC_ALL=C grep -oabUP "\xFF\xD9" image.jpeg
    

    For reference:

    • bytes 0xFF, 0xD8 indicate start of image (SOI)
    • bytes 0xFF, 0xD9 indicate end of image (EOI)