-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecover.c
59 lines (51 loc) · 1.4 KB
/
recover.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
if (argc != 2) {
printf ("Incorrect number of args: %i\n", argc);
return 1;
}
char *file_name = argv[1];
FILE *input = fopen (file_name, "r");
if (input == NULL) {
printf ("Cannot open file\n");
return 1;
}
const int BLOCK_SIZE = 512;
//unsigned char *block = malloc (BLOCK_SIZE);
unsigned char block [512];
int count = 0;
FILE *output = NULL;
while (fread (block, BLOCK_SIZE, 1, input) == 1) {
if (block[0] == 0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] >>4 == 0xe) {
char file_out [10];
if (count < 10) {
sprintf(file_out, "00%i.jpg", count);
} else {
sprintf (file_out, "0%i.jpg", count);
}
if (count == 0){
output = fopen (file_out, "a");
}
else {
// jpeg file, close old pointer. Reopen a new one
fclose (output);
output = fopen (file_out, "a");
}
count ++;
}
if (output != NULL) {
fwrite (block, BLOCK_SIZE, 1, output);
}
if (feof (input)) break;
}
if (output != NULL) {
fclose (output);
}
/*if (block != NULL) {
free (block);
}*/
return 0;
}