guys! I was solving recover, but my program finds way too many JPEGs. I believe that this is because of the following lines:

// starting bytes of jpeg are in [lower, upper]
uint8_t lower[4] = {0xff, 0xd8, 0xff, 0xe0};
uint8_t upper[4] = {0xff, 0xd8, 0xff, 0xee};

// checks for jpg (at least, it should)
if ((abs(memcmp(&lower, check, 4)) <= 15) && 
    (abs(memcmp(&upper, check, 4)) <= 15))

As far as I know, memcmp returns a difference between these two segments of memory which is small when they differ only in one byte (namely, it is a difference of numbers represented by these bytes.

I haven't found any better way to check for JPEG. However, I found a solution which simply checks for {0xff, 0xd8, 0xff, 0xe0} and {0xff, 0xd8, 0xff, 0xe1} and it works, which is strange as it potentially misses JPEGs.

Do you guys know better ways than mine to check for all possible startings of a JPEG?


Did you watch the walkthrough? Zamyla gives you the code you need to determine if a block is the start of a jpg. Is it a JPG?

You must log in to answer this question.

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