-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
63 lines (47 loc) · 1.35 KB
/
main.c
File metadata and controls
63 lines (47 loc) · 1.35 KB
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
61
62
63
#include <stdio.h>
int main(char argv[], int argc)
{
if(argc != 2)
{
printf("Usage: %s ImageFile\n", argv[0]);
return 1;
}
FILE *pImageFile = fopen(argv[1], "rb");
if(pImageFile == NULL)
{
puts("Read image file failed!");
return 1;
}
fseek(pImageFile, 0, SEEK_END);
long lFileSize = ftell(pImageFile);
printf("Image size: %ld\n", lFileSize);
//alloc buffer
unsigned char *pImageBuffer = (unsigned char*)malloc(lFileSize);
if(pImageBuffer == NULL)
{
puts("Memorey alloc failed!");
return 1;
}
//ser file pointer to the begining
fseek(pImageFIle, 0, SEEK_SET);
//read the whole image file into memory
long lReadResult = fread(pImageBuffer, 1, lFileSize, pImageFile);
printf("Read size: %ld\n", lReadResult);
if(lReadResult != lFileSize)
{
puts("Read file error!");
free(pImageBuffer);
fclose(pImageFile);
return 1;
}
fclose(pImageFile);
//print FAT12 structure
PrintImage(pImageBuffer);
//seek files of root direcotory
SeekRootDir(pImageBuffer);
// file read buffer
unsigned char outBuffer[2048];
//read file 0
DWORD filesize = ReadFile(pImageBuffer, &FileHeaders[0], outBuffer);
printf("File size: %u, file content: \n%s", filesize, outBuffer);
}