-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecover.c
60 lines (50 loc) · 1.27 KB
/
recover.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
//Criando um novo tipo conforme Hit do exercicio
typedef uint8_t BYTE;
int main(int argc, char *argv[])
{
// Check for invalid usage
if (argc < 2)
{
printf("Usage: ./recover forensicImage\n");
return 1;
}
// Verificando se o arquivo existe conforme Hit do exercicio
FILE *input = fopen(argv[1], "r");
if (input == NULL)
{
printf("Could not open file.\n");
return 1;
}
BYTE buffer[512];
int nova = 0;
FILE *img = NULL;
char name[8];
//Laço de leitura
while (fread(&buffer, 512, 1, input))
{
//Verificando se começou uma nova imagem
if ((buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff) && ((buffer[3] & 0xf0) == 0xe0))
{
//Fechando a imagem anterior
if (nova > 0)
{
fclose(img);
}
//Função para colocar mascara no nome do arquivo
sprintf(name, "%03i.jpg", nova);
nova ++;
img = fopen(name, "w");
}
//Copiando a imagem
if (nova > 0)
{
fwrite(&buffer, 512, 1, img);
}
}
// Close files
fclose(input);
fclose(img);
}