0
    // creat a counter that keepw trach of jpegs found
    int counter = 0;

    // crate a string filename for sprintf
    char filename[8];
    //
    FILE* picture = NULL;
    // chech if we have found a jpeg
    int jpegfound = 0;

    //i ll go throurh the memory until there are not any blocks left
    while (fread(buffer, 512, 1, input) == 1)
    {
        //reaf first 4 bytes to see if it is a jpeg
        if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] >= 0xe0 && buffer[3] <= 0xef ))
        {
            if (jpegfound == 1)
            {
                fclose(picture);
            }
            else
            {
                jpegfound = 1;
            }

            sprintf(filename, "%03d.jpeg", counter);
            picture = fopen(filename, "a");
            counter++;
        }
        if (jpegfound ==1)
        {
               fwrite(&buffer, 512, 1, picture);
        }
    }
    fclose(picture);
    fclose(input);
    return 0;

}
  • just a notice: there are 49 jpegs at the left of my screen but i cant open them an check50 indicates :) recover.c exists. :) recover.c compiles. :) handles lack of forensic image :( recovers 000.jpg correctly 000.jpg not found :( recovers middle images correctly 001.jpg not found :( recovers 049.jpg correctly 049.jpg not found – philnikolo Aug 6 '19 at 17:28
  • then i tried it again and again and now it shows me only 000.jpeg and 001.jpeg but still the same indication in check50....confused!!! – philnikolo Aug 6 '19 at 17:46
0

There are a couple of issues in the code. First, it opens the output files in "a" or append mode. By doing this, if you've run the program before and the files already exist, it will just add more data to the existing file, not create a new file. That means, if the code created bad files to start with, and you didn't delete them before running the program, it will just add data to an already bad file.

The output files should be opened in "w" or write mode. This will delete any pre-existing file of the same name and create a new file.

Next, the output files being created have the file extension of ".jpeg". Aren't they supposed to be ".jpg" without the "e"?

Finally, there may be one remaining issue. How was buffer[512] declared? If you used an improper data type, the data written to the output file will be corrupted. I can't tell if this is an issue because the declaration wasn't included in the code above.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • i have no idea where jpeg came from!!!changing it fixed it.i laso understand what you are saying about "a" and "w". thanks a lot – philnikolo Aug 7 '19 at 17:16

You must log in to answer this question.

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