Not sure why there are not results from this program, recover literally does nothing. Better than my old program that created over 500 images I guess.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./recover image");
return 1;
}
char *infile = argv[1];
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", infile);
return 1;
}
typedef uint8_t BYTE;
BYTE buffer [512];
// sets up buffer as an array with 512 elements of size BYTE
FILE *img = NULL;
{
int filenumber = 0;
if (buffer[0] == 0xff || buffer[1] == 0xd8 || buffer[2] == 0xff || (buffer[3] & 0xf0) == 0xe0 )
{
filenumber ++;
char filename [8];
if (filenumber == 1)
{
sprintf(filename, "%03i.jpg" , filenumber - 1);
img = fopen(filename, "w");
//img is a pointer
fwrite(buffer, sizeof(BYTE),512,img);
// buffer is usually an array, so I'm not sure why I need the adress for the buffer
// img is a pointer, as it should be
// writes from the buffer into the img
}
else
{
fclose(img);
// fclose closes the file pointer, img
sprintf(filename, "%03i.jpg" , filenumber - 1);
img = fopen(filename, "w");
// img is a pointer
fwrite(buffer, sizeof(BYTE),512,img);
// buffer is usually an array, so I'm not sure why I need the adress for the buffer
// img is a pointer, as it should be
// writes from the buffer into the image
}
}
else if (filenumber > 0)
{
// write to already existing file
fwrite(buffer,sizeof(BYTE),512,img);
// buffer is usually an array, so I'm not sure why I need the adress for the buffer
// img is a pointer, as it should be
// writes from the buffer into the image
}
}
while(fread(buffer, sizeof(BYTE), 512, inptr) == 512);
}