0

I don't know why my code isn't working. It recovers images but only a small fuzzy part of them. Can anyone help?

/** * recover.c * * Computer Science 50 * Problem Set 4 * * Recovers JPEGs from a forensic image. */

include

include

include

typedef uint8_t BYTE; int main(int argc, char* argv[]) { // open memory card file char picture[8]; BYTE block[512]; int counter = 0;

FILE* inptr = fopen("card.raw", "r");
if(inptr == NULL)
{
    printf("could not open file/n");
    return 1;
}
FILE* outptr;
while(fread(&block, 512, 1, inptr) > 0)
{

        if ((block[0] == 0xff) && (block[1] == 0xd8) && (block[2]== 0xff) && (block[3] >= 0xe0) && (block[3] <= 0xef))
        {

            if( counter > 0)
            {
                fclose(outptr);
                sprintf(picture, "%d.jpg", counter);
                counter++;
                outptr = fopen(picture, "w");
            }  

            if( counter == 0)
            {
                sprintf(picture, "%d.jpg", counter);
                counter++;
                outptr = fopen(picture, "w");
                if (outptr == NULL)
                {
                    printf("could not create /n");
                    return 2;
                }
            }

            fwrite(&block, 512, 1, outptr);

        }  


}
fclose(inptr);

}

1 Answer 1

0

You are only writing the first block of each file, which contains the signature, to the output file. All of the following blocks (which will not have a jpeg signature), meaning the rest of the image, are being discarded because there is no code to handle them.

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

1
  • thank you so much! seems so obvious when you finally see it!
    – katie
    Apr 26, 2016 at 8:42

You must log in to answer this question.

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