0
:) recover.c exists.
:) recover.c compiles.
:) handles lack of forensic image
:( recovers 000.jpg correctly
    recovered image does not match
:( recovers middle images correctly
    recovered image does not match
:( recovers 049.jpg correctly
    recovered image does not match



#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

typedef uint8_t BYTE;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("Usage: ./recover file.raw");
        return 1;
    }
    FILE *file = fopen(argv[argc - 1], "r");
    if (file == NULL)
    {
        printf("file can not open");
        return 1;
    }
    BYTE byte[512];

    char image_name_string[3];
    int image_name_int = -1;

    int found = 0;

    FILE *output;

    while (fread(byte, sizeof(BYTE), 512, file))
    {
        //check the header of jpeg file
        if (byte[0] == 0xff && byte[1] == 0xd8 && byte[2] == 0xff && (byte[3] & 0xf0) == 0xe0)
        {
            found = 1;

            //check first image
            if (image_name_int != -1)
            {
                fclose(output);
            }

            //open new image file
            image_name_int++;
            sprintf(image_name_string, "%03i.jpg", image_name_int);
            output = fopen(image_name_string, "w");

            fwrite(byte, sizeof(BYTE), 512, output);
        }

        //keep writing if a jpeg file already found
        else if (found == 1)
        {
            fwrite(byte, sizeof(BYTE), 512, output);
        }
    }

    fclose(output);
    fclose(file);
}
0

oh, i have it. The size of image_name_string must be change. I have set it to 10 instead of 3.

You must log in to answer this question.

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