0

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

typedef uint8_t BYTE;

int main(int argc, char *argv[]) { if (argc != 2) { printf("./usage: recover filename\n"); return 1; } char *infile = argv[1];

//open card file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
    printf("could not open %s.\n", infile);
}
BYTE buffer[512];
char filename[8];
int count = 0;
FILE *img_pointer = NULL;

// repeat until end of file
while (fread(buffer, sizeof(buffer), 1, inptr)) //read 512 bytes into buffer
{
    if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && ((buffer[3] & 0xf0) == 0xe0))
    {
        sprintf(filename, "%03i.jpg", count);
        count++;
        img_pointer = fopen(filename, "w");
        while (fwrite(buffer, sizeof(buffer), 1, img_pointer))
        {
            if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && ((buffer[3] & 0xf0) == 0xe0))
            {
                fclose(img_pointer);
            }
        }

    }
}
fclose(img_pointer);
fclose(inptr);

}

0

You must log in to answer this question.

Browse other questions tagged .