Hello I've been working on recover
for sevreal days now and I've finally got it to work, almost. It compiles just fine, responds properly to a lack of forensic image, creates and properly names 51 jpg files and I can open these files without issue and they display full color pictures of staff and students. However the first image "000.jpg" is just white and grey squares and since the images go from 000 - 050 I'm pretty sure it's not suposed to be there and is an extra. The first properly recovered image ("001.jpg") is of Brian with a bunch of helium emoji balloons.
My questions: Is the picture of Brian supposed to be the first image? And the pic of the boy in white sitting on the grass the last? If so, then my code is creating and extra file (pressumably from the junk space). Could someone please take a look at my code and possibly point out, or hint at, where this issue is coming from? I'm at my wits' end and I'd greatly appreciate it!!!
MY MAIN LOOP:
bool end = false;
bool working = false;
int img_counter = 0;
char filename[8];
int noblocks = 0;
do
{
fread(buffer,1,512,card);
noblocks++;
if (feof(card))
{
printf("number of blocks :%i\n", noblocks);
printf("End of file reached.\n");
end = true;
return 0;
}
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
printf("file detected\n");
working = true;
if (img_counter == 0) // if first jpg
{
sprintf(filename, "%03i.jpg", img_counter);
FILE *output = fopen(filename,"w");
fwrite(buffer,1,512,output);
fclose(output);
img_counter++;
}
if (img_counter != 0) // if new jpg
{
sprintf(filename, "%03i.jpg", img_counter);
FILE *output = fopen(filename,"w");
fwrite(buffer,1,512,output);
fclose(output);
img_counter++;
}
}
else
{
if (working == true)// if a file has already been detected
{
sprintf(filename, "%03i.jpg", img_counter - 1);
FILE *output = fopen(filename, "a"); //appends current block to previous file
fwrite(buffer,1,512,output);
fclose(output);
}
}
}
while(end == false);