Guest User

Untitled

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