0

Hello I've been working on recoverfor 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);
1

I'm going to answer this with a big hint and give you a chance to sort it out. If you can't, then let us know and we'll take another pass at it.

There should be 50 files, not 51, and they should be numbered 000 to 049. So, what do you think is wrong? What's that first image look like again?

Here's something else. Why is the code repeatedly opening and closing the output files so much??? It's not necessary. When a signature is found, close any open output file, and open a new one. After that, just leave it open and keep writing to it until the next signature is found! There's absolutely no need to keep closing and opening the file!

However, you do need to declare the output file pointer early in the program so that it is in scope for the entire program. (In other words, don't declare it inside a pair of curly braces for an if statement or a for loop.)

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

3
  • Since I end up with an extra picture at the beggining of the set of files I assume there is an issue with how I deal with the junk space at the beginning of the .raw file. This extra file then causes all the properly recovered pictures to shift over by one, which, I assume, is the reason check50 gives me error messages for the recovered photos. – Renée May 7 '20 at 9:19
  • The reason I keep opening and closing the files is that I had issues declaring the pointer outside of the individual statements and so I went with a slightly more comple method that worked so I could move on and work on other aspects of the program. I have sincce tried to declare a pointer just outside the loop with all my other variabels and the only way I can get that to compile is if I derefrence the pointers in the individual statements, however, I then suffer a segfault. If you have any hints, or a good resource on the subject from which I can develop my own answers, I'd be delighted! – Renée May 7 '20 at 9:37
  • I have managed to fix the extra file issue. Thank you very much for your help!!! :):):) – Renée May 7 '20 at 9:59

You must log in to answer this question.

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