mirror of https://github.com/me50/kukemuna.git
This commit is contained in:
commit
f72a0d63d5
|
|
@ -0,0 +1,66 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define BLOCKSIZE 512
|
||||||
|
#define NAMESIZE 8
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
printf("Usage: ./recover FILE\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *card = fopen(argv[1], "r");
|
||||||
|
if (card == NULL)
|
||||||
|
{
|
||||||
|
printf("Could not open file.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t buffer[BLOCKSIZE];
|
||||||
|
int count = 0, first = 1;
|
||||||
|
char *filename = malloc(NAMESIZE);
|
||||||
|
FILE *jpg = NULL;
|
||||||
|
|
||||||
|
while (fread(buffer, 1, BLOCKSIZE, card) == BLOCKSIZE)
|
||||||
|
{
|
||||||
|
// JPG header found
|
||||||
|
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff &&
|
||||||
|
(buffer[3] & 0xf0) == 0xe0)
|
||||||
|
{
|
||||||
|
if (first == 1)
|
||||||
|
{
|
||||||
|
sprintf(filename, "%03i.jpg", count);
|
||||||
|
jpg = fopen(filename, "w");
|
||||||
|
if (jpg == NULL)
|
||||||
|
{
|
||||||
|
printf("Could not open file.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fclose(jpg);
|
||||||
|
sprintf(filename, "%03i.jpg", count);
|
||||||
|
jpg = fopen(filename, "w");
|
||||||
|
if (jpg == NULL)
|
||||||
|
{
|
||||||
|
printf("Could not open file.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (first == 0) // Ignore data before first JPG header
|
||||||
|
{
|
||||||
|
fwrite(buffer, 1, BLOCKSIZE, jpg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(jpg);
|
||||||
|
fclose(card);
|
||||||
|
free(filename);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue