Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- int main(int argc, char* argv[])
- {
- if(argc!=2)
- {
- fprintf(stderr, "Usage: ./recover image\n");
- return 1;
- }
- FILE* src=fopen(argv[1],"r");
- if(src==NULL)
- {
- fprintf(stderr, "File cannot be opened\n");
- return 2;
- }
- uint8_t buff[512];
- FILE* img;
- int c=0;
- while(fread(buff,1,512,src)==512)
- {
- if(buff[0]==255&&buff[1]==216&&buff[2]==255&&(buff[3]>=224&&buff[3]<=239))
- {
- if(c>0)
- fclose(img);
- char tgt[50];
- sprintf(tgt,"%03i.jpg",c);
- img=fopen(tgt,"w");
- fwrite(&buff,512,1,img);
- c++;
- }
- if(c>0)
- {
- fwrite(&buff,512,1,img);
- }
- }
- fclose(src);
- }
Add Comment
Please, Sign In to add comment