My recover program compiles and runs (finds 27 images). While opening them they all seem to be different at least in shape. However the copying seems to be problematic (all made of white and grey squares instead of proper block)
I have been on this forever, I feel like it's the last step :)
thanks for the help !
// check argv1 exists
char *infile = argv[1];
// open input file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", infile);
return 2;
}
uint8_t buffer[512];
char filename[8];
while (fread(&buffer, sizeof(buffer), 1, inptr) == 1) // read as long as we haven't reached EOF
{
fread(&buffer,512, 1, inptr); // read input file
// condition if we meet a start of JPEG signature
if (buffer[0] == 0xff &&
buffer[1] == 0xd8 &&
buffer[2] == 0xff &&
(buffer[3] & 0xf0) == 0xe0)
{
if(count!=0)
{
count = count+1; // increase count of images found
FILE *img = fopen(filename,"w");
fclose(img); // close file we were working on
}
if (count==0) // manage case for first image found
{
printf("%i loop 1 \n",loop); // for testing purposes
sprintf(filename, "%03i.jpg",count);
FILE *img = fopen(filename,"w");
fwrite(&buffer,512,1,img);
count = count+1; // increase count of images found
}
if (count > 1)
{
printf("%i loop 2 \n",loop); // testing purposes
printf("we found %i images\n", count); // testing purposes
sprintf(filename,"%03i.jpg",count);
FILE *img = fopen(filename,"w");
fwrite(&buffer,512,1,img);
// fclose(img);
}
}
else if(count!=0) // keep printing in the same file if we haven't met a new signature
{
FILE *img = fopen(filename,"w");
fwrite(&buffer,512,1,img);
}
}
printf("end of while loopfile reached\n"); // for debug purposes
// close file
// fclose(img):
fclose(inptr);