Guest User

Untitled

a guest
Jun 20th, 2017
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6.     if(argc!=2)
  7.     {
  8.         fprintf(stderr, "Usage: ./recover image\n");
  9.         return 1;
  10.     }
  11.     FILE* src=fopen(argv[1],"r");
  12.     if(src==NULL)
  13.     {
  14.         fprintf(stderr, "File cannot be opened\n");
  15.         return 2;
  16.     }
  17.     uint8_t buff[512];
  18.     FILE* img;
  19.     int c=0;
  20.     while(fread(buff,1,512,src)==512)
  21.     {
  22.         if(buff[0]==255&&buff[1]==216&&buff[2]==255&&(buff[3]>=224&&buff[3]<=239))
  23.         {
  24.             if(c>0)
  25.             fclose(img);
  26.             char tgt[50];
  27.             sprintf(tgt,"%03i.jpg",c);
  28.             img=fopen(tgt,"w");
  29.             fwrite(&buff,512,1,img);
  30.             c++;
  31.         }
  32.         if(c>0)
  33.         {
  34.             fwrite(&buff,512,1,img);
  35.         }
  36.     }
  37.     fclose(src);
  38. }
RAW Paste Data