2 * A really stupid jpeg file recover for Linux.
4 * You do not want to use this, you want to use photorec instead:
6 * http://www.cgsecurity.org/wiki/PhotoRec
8 * This program is licensed under the GPLv2.
10 * Luiz Fernando N. Capitulino
11 * <lcapitulino@gmail.com>
17 #include <sys/types.h>
20 // Start of Image, according to the spec
21 #define IMG_START 0xd8ff
23 // End of Image, according to hexdump :P
24 // Some images do not have the EOI specified by the standard (0xffd9),
25 // the value bellow worked for a lot of images.
26 #define IMG_END 0xff3f
28 static int open_file(void)
31 static int counter
= 0;
33 snprintf(filename
, sizeof(filename
), "img%d.jpeg", counter
++);
34 return open(filename
, O_RDWR
| O_CREAT
, 0444);
37 int main(int argc
, char *argv
[])
41 int found
, amount
, fd
, fd2
;
44 fprintf(stderr
, "you have to specify the device name\n");
48 fd
= open(argv
[1], O_RDONLY
);
56 while (read(fd
, &c
, 2) > 0) {
61 perror("open_file()");
64 fprintf(stderr
, "Found %d\r", amount
++);
68 bytes
= write(fd2
, &c
, 2);
81 fprintf(stderr
, "\n");