Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- if (argc != 2)
- {
- printf("Usage: ./recover [Your file].\n");
- return 1;
- }
- FILE *file = fopen(argv[1], "r");
- if (file == NULL)
- {
- printf("Your file cannot be opened for reading.\n");
- return 1;
- }
- unsigned char bytes[512];
- char filename[8];
- int end = 1;
- int found = 0;
- int counter = 0;
- FILE *img;
- do
- {
- end = fread(bytes, 512, 1, file);
- if (bytes[0] == 0xff && bytes[1] == 0xd8 && bytes[2] == 0xff && (bytes[3] & 0xf0) == 0xe0)
- {
- found = 1;
- if (counter == 0)
- {
- sprintf(filename, "%03i.jpg", counter);
- img = fopen(filename, "w");
- fwrite(bytes, 512, 1, img);
- }
- else
- {
- fclose(img);
- counter++;
- sprintf(filename, "%03i.jpg", counter);
- img = fopen(filename, "w");
- }
- }
- else
- {
- if (found == 1)
- {
- fwrite(bytes, 512, 1, img);
- }
- }
- } while (end != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement