I have written the following code to read the information from the RAW file and try to sort it out into the proper jpeg files.
Through gdb, I can see that the file is reading into the buffer fine (and there is some very interesting info hidden in there). The problem is that the loop only runs three times before exiting "normally" according to GDB, but it is exiting during the 'if' condition to check for a jpeg_sig, which doesn't make sense.
When I run the program outside of GDB then there is no error message. I can't tell why it the loop is not running until the break that I put in at the top of the while loop. Can someone help? The rest of the while loop is what happens if a JPEG signature is found -- if not, it just loops back up.
while (1)
{
//checks to make sure end of file hasn't been reached by reading a char
char check = fgetc(file);
if (check == feof(file))
{
break;
}
//if not reached, seeks back
fseek(file, -(sizeof(char)), SEEK_CUR);
//reads block into buffer
for (int buffread = 0; buffread < 512; buffread++)
{
fread(&buffer[buffread], sizeof(BYTE), 1, file);
}
//if first part of buffer matches with signature, then make a new jpeg
if ((buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff) && ((buffer[3] == 0xe0) || (buffer[3] == 0xe1)))