I am working on the recover problem and I request some help. Well as the problem requires that search through raw data to get and save images separately, I am working on the problem step by step. At this point I have been able to code the program to accept one command line argument. I am currently having problems with the fread function in the loop. It is my understanding that the first argument for fread is a pointer to a store where I can place the elements from the second, third and forth arguments. My intention afterwards is that I can search the elements in the store (&buffer[0]), for the bytes of interest. However, after "freading", I find that the first 512 bytes from the card are different from those stored in the buffer[0]. So I cannot proceed to start searching for the first 4 bytes of interest. It is possible that I am approaching this the wrong way and I will appreciate any advice on how to finish the problem set from where I am now.
/** * * - recover - * * a program that accepts a forensic image from * which to recover jpegs * */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define FILE_NAME "temp.txt"
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Only one command line argument\n");
return 1;
}
//Initialising pointer to the card.raw argument
char *image = argv[1];
FILE *card = fopen(image, "r");
//Creating a BYTE struct
typedef uint8_t BYTE;
//Initialising a variable for a single byte
BYTE *single_byte = NULL;
//Calculating the size of the card in bytes
fseek(card, sizeof(single_byte), SEEK_END);
long size = 0;
size = ftell(card);
printf("I am size: %li | Size of singlebyte: %lu\n", size, sizeof(*single_byte));
//Moving the cursor to the starting position
fseek(card, -1*size, SEEK_CUR);
long offset = 0;
offset = ftell(card);
printf("Current offset: %lu | Current size: %li\n", offset, size);
int buffer[513];
// looping through the card to store the elements in a buffer array
for (int i = 0; i < 512; i++)
{
fread(&buffer[0], sizeof(*single_byte), 512, card);
printf("%i: %x\n", i, buffer[i]);
}
}