Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- // check if arg count is 2
- if (argc != 2)
- {
- printf("Usage: ./recover image\n");
- return 1;
- }
- // create a pointer to open the memory card file
- FILE *inptr = fopen("card.raw", "r");
- // check if pointer is Null, if it is then return 1
- if (inptr == NULL)
- {
- printf("this file is empty\n");
- return 1;
- }
- FILE *imgOut = NULL;
- char filename[10];
- int count = 0;
- // create buffer array
- unsigned char buffer[512];
- do
- {
- // read in buffer
- fread(&buffer, 512, 1, inptr);
- // printf("this is it\n");
- // check if the start of new jpeg image
- if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
- {
- printf("this is a jpeg\n");
- sprintf(filename, "test.jpg");
- imgOut = fopen(filename, "w");
- if (imgOut == NULL)
- {
- printf("img is NULL\n");
- fclose(inptr);
- return 1;
- }
- // if it's the very first jpeg
- if (count == 0)
- {
- //img = fopen(filename, "w");
- fwrite(&buffer, 512, 1, imgOut);
- //count++;
- }
- }
- else if (imgOut)
- {
- fwrite(&buffer, 512, 1, imgOut);
- }
- }
- while (!feof(inptr));
- fclose(inptr);
- fclose(imgOut);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement