I'm helping my son work on the recover.c assignment trying to recover JPEGs from card.raw disk image file. I'm running into a strange behavior trying to display bytes from my 512-byte buffer which is a character array. Here's some test code where I only read the first 11 512-byte blocks.
char block[512];
for (int i=0; i<11; i++)
{
fread(block, 1, 512, infile);
printf("Block %i: ", i);
printf("Byte 0 = %X, Byte 1 = %X\n", block[0], block[1]);
}
I'm only trying to display the first 2 bytes of the 512-byte block because my if code can't match up the first 4 bytes to test if it is a JPEG. Here's the output I'm getting this output when I run the test code.
./recover card.raw
Size of infile is: 5250560
Block 0: Byte 0 = 0, Byte 1 = 0
Block 1: Byte 0 = 63, Byte 1 = 73
Block 2: Byte 0 = FFFFFFFF, Byte 1 = FFFFFFD8
Block 3: Byte 0 = 67, Byte 1 = FFFFFFB3
Block 4: Byte 0 = FFFFFFF6, Byte 1 = FFFFFFC8
I looked at card.raw with a binary viewer.
Block 0, 1, and 3 are outputting the correct 1-byte values for byte 0 and 1.
Block 2 and 4 are spitting out 4-byte values which has be baffled.
This explains why my I can't find any JPEG headers by trying to match block[0] through block[3] to the JPEG header values. Can anyone explain what I'm doing wrong here? Thank you.