
/*
example of copying "flash" content to a file (actually, an example of accessing "raw" volumes):
    find_jpeg \\?\PhysicalDrive3
or
    find_jpeg \\\\?\\PhysicalDrive3
or 
    cp \\\\?\\PhysicalDrive3 CF (if using cygwin's "cp" to copy volume content to hard disk first)
*/


#include <stdio.h>
#define jpegsize 3000000/512

main(int argc, char **argv)
{
 FILE *fi, *fo;
 long xpos;
 int i, n;
 char buf[512];
 char s[222];

 fi=fopen(argv[1],"rb");
 if(!fi) {puts("cant open"); exit(0);}

 n=0;
 while(!feof(fi))
   {
    fread(buf,512,1,fi);
    if(!memcmp(buf+6,"Exif",4))
      {
       xpos=ftell(fi);
       printf("%ld\n",xpos);
       sprintf(s,"file%04d.jpg",n++);
       fo=fopen(s,"wb");
       fwrite(buf,512,1,fo);
       for(i=1;i<jpegsize;i++)
         {
          fread(buf,512,1,fi);
          fwrite(buf,512,1,fo);
         }
       fclose(fo);
       fseek(fi,xpos,SEEK_SET);
      }
   }
}
