Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- int main(int argc, char *argv[])
- {
- if (argc != 2)
- {
- printf("Usage : ./recover [IMAGE]");
- return 1;
- }
- //Open File
- FILE *input = fopen (argv[1], "r");
- if (input == NULL)
- {
- printf("Could not open file.");
- return 2;
- }
- FILE *output = NULL;
- unsigned char buffer[512];
- int count = 0;
- char *filename = malloc ( 8 * sizeof(char));
- while (fread(buffer, sizeof(char), 512, input))
- {
- if (buffer[0] == 0xff && buffer[1] == 0xd8 && (buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0))
- {
- sprintf(filename, "%03i.jpg", count);
- output = fopen(filename, "w");
- count++;
- }
- if (output != NULL)
- {
- fwrite(buffer, sizeof(char), 512, output);
- }
- }
- free(filename);
- fclose (output);
- fclose (input);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment