0

I'm working on a portion of the Recover project and was wondering if there is a more elegant solution eluding me. I've noticed that when I come across the first JPEG which starts with ffd8ffe0 gdb tells me it stores in my char array labeled "input" as "/377/330/377/340". I cannot directly use this information for searching, but I was able to figure out a work around using sprintf and %hhx to use strcmp in an if statement.

My question is, is there a simpler way to convert the strange values stored in "input" to hexadecimal? Below is a snippet of the code I used in my work around:

include stdio.h
include stdlib.h
include string.h

int main(void)
{
    char input[8];
    char result[8];

    while (fread(&input, sizeof(char), 8, inptr) == 8)
        {
             sprintf(result, "%hhx%hhx%hhx%hhx", njc[0], njc[1], njc[2], njc[3]);
             if (strcmp(result, "ffd8ffe0") == 0 || strcmp(result, "ffd8ffe1") == 0)
             {
                  // write JPEG file.
             }
        }

}

As I stated before, if you examine "input" through GDB it provides a cryptic value of "/377/330/377/340". It would be great to be able to store this directly as a hexadecimal value.

0

The jpg file is not made up of chars that become strings. They are simply bytes. So you can do something like if input[0] = 0xff && input[1] = 0xd8 ... etc.

Store your 512 bytes in an array of unsigned char buffer[512] for example and you can test the first 4 bytes of that, similarly to the above.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .