[H-GEN] file recovery tools
Peter Arnold
arnoldpj at optusnet.com.au
Tue Dec 30 18:08:09 EST 2003
David Makepeace wrote:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
>
> main(int argc, char *argv[])
> {
> int fd = -1;
> char buf[512];
> char fname[80];
> int fnum = 0;
>
> while (read(0, buf, 512) == 512) {
> if (*(unsigned *)&buf == 0xe1ffd8ff) {
> if (fd != -1) close(fd);
> sprintf(fname, "recovered%03d.jpg", fnum++);
> fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
> if (fd == -1) {
> perror(fname);
> exit(1);
> }
> }
> if (fd != -1) write(fd, buf, 512);
> }
> if (fd != -1) close(fd);
> exit(0);
> }
Hey David,
Thanks for the above program. It achieved the same results but is an order of magnitude (or two) faster than my script :).
For the record though I changed:
if (*(unsigned *)&buf == 0xe1ffd8ff) {
to
if (*(unsigned *)&buf == 0xffd8ffe1) {
for it to work for me.
Cheers
Peter
More information about the General
mailing list