I don't know why but when i try working with check50 it tells everything is ok except that the015 jpg i not recovered correctly but for some reason when i actually try it and run it it says it works just fine.
/** * recover.c * * Computer Science 50 * Problem Set 4 * * Recovers JPEGs from a forensic image. */ #include #include
typedef uint8_t BYTE;
int main(int argc, char* argv[]) {
char nameFile[9];
// creates int to keep count of numbers of files opened
int numFiles = 0;
// Creates array to store info in chunks
BYTE fat[512];
//Creates both files to be used
FILE* card = fopen("card.raw", "r");
FILE* image;
if (card == NULL)
{
printf("Could not open card.raw");
return 1;
}
while(feof(card) == 0 )
{
for( int i = 0; i < 512; i++)
fread(&fat[i], sizeof (BYTE), 1, card);
// cheks wheter is the begining of a file
if((fat[0] == 0xff) && (fat[1] == 0xd8) && (fat[2] == 0xff) && (fat[3] == 0xe0 || fat[3] == 0xe1))
{
// if there is something opened
if(numFiles > 0)
{
fclose(image);
sprintf(nameFile , "%03d.jpg",numFiles );
image = fopen(nameFile,"w");
numFiles++;
}
// if nothing has been opened
if( numFiles < 1)
{
sprintf(nameFile, "%03d.jpg",numFiles );
image = fopen(nameFile,"w");
numFiles++;
}
}
// if somethinf has been opened everything that goes after it must be written in a file
if(numFiles > 0)
fwrite(fat, 1, 512, image);
}
// closes remaining windows
fclose(image);
fclose(card);
}