#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: ./recover Card.raw\n");
return 1;
}
char *card = argv[1];
int jpgCount = 0;
typedef uint8_t BYTE;
BYTE buffer[512];
FILE *file = fopen(card, "r");
if (file == NULL)
{
fprintf(stderr, "fopen returned NULL.\n");
return 2;
}
else
{
while (fread(&buffer, 1, 512, file) == 512)
{
if (buffer[0] == 0xff &&
buffer[1] == 0xd8 &&
buffer[2] == 0xff &&
(buffer[3] & 0xf0) == 0xe0)
{
char Imgfile[8];
sprintf(Imgfile, "%03d.jpg", jpgCount);
FILE *img = fopen(Imgfile, "w");
if (img == NULL)
{
fprintf(stderr, "Couldn't create the file.\n");
return 1;
}
if (jpgCount == 0)
{
fwrite(&buffer, 1, 512, img);
jpgCount++;
}
else
{
fclose(img);
fwrite(&buffer, 1, 512, img);
jpgCount++;
}
}
}
fclose(file);
}
return 0;
}
Recover finds all 50 pictures and names them correctly but it doesn't open any of them and spits out "invalid or unsupported image format.", can someone please point out what i'm doing wrong here? Thanks in advance.