Skip to main content
3 of 3
added 160 characters in body
MARS
  • 5.2k
  • 3
  • 14
  • 23

recover end of file detection

I'm having a lot of trouble with recover. I have written some code, just to get the basic structure. I was trying to iterate over the raw file until the end, printing when stumbled upon a jpeg.

Anyway, when I run my code. It stops after 4 blocks of 512B, having encountered 1 jpeg. How do I make my code run over the whole raw file?.

Here's my code:

//typedef uint8_t  BYTE;

int main(int argc, char* argv[])
{
    //open card image
    FILE* file = fopen("card.raw", "r");
    
    //initialize counters
    int counter = 0;
    int iterations = 0;
    
    //open buffer
    BYTE buffer[512];
    
    do
    {
        //store 512B in buffer
        fread(&buffer, sizeof(BYTE), 512, file);
        
        //check for start of jpeg
        if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] == 0xe0)
        {
            printf("JPEG found\n");
            counter++;
        }
        else if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] == 0xe1)
        {
            printf("JPEG found\n");
            counter++;
        }
        
        iterations++;
    }
    while(buffer[0] != 0x00 && buffer[1] != 0x00 && buffer[2] != 0x00 && buffer[3] != 0x00);
    
    printf("Counter is %d\n", counter);
    printf("Iterations is %d\n", iterations);
    fclose(file);
    return 0;
}
Jesse
  • 157
  • 3
  • 17