Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- typedef uint8_t BYTE;
- typedef struct
- {
- BYTE a;
- BYTE b;
- BYTE c;
- BYTE d;
- }JBLK;
- 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;
- }
- int c=0;
- fpos_t pos;
- while(fgetc(src)!=EOF)
- {
- JBLK tmp;
- fread(&tmp,sizeof(JBLK),1,src);
- if(tmp.a==255&&tmp.b==216&&tmp.c==255&&(tmp.d>=224&&tmp.d<=239))
- {
- char tg[50];
- sprintf(tg,"00%i.jpg",c);
- FILE* tgt=fopen(tg,"w");
- fwrite(&tmp,sizeof(JBLK),1,tgt);
- fread(&tmp,sizeof(JBLK),1,src);
- while(!(tmp.a==255&&tmp.b==216&&tmp.c==255&&(tmp.d>=224&&tmp.d<=239)))
- {
- fwrite(&tmp,sizeof(JBLK),1,tgt);
- fgetpos(src,&pos);
- fread(&tmp,sizeof(JBLK),1,src);
- }
- fclose(tgt);
- c++;
- fsetpos(src,&pos);
- }
- else continue;
- }
- fclose(src);
- return 0;
- }
Add Comment
Please, Sign In to add comment