C程序从Fat MBR读取十六进制值

时间:2018-03-29 20:55:10

标签: c hex fat16

我是C语言的新手,正在尝试创建一个取证工具。到目前为止我有这个。它读取一个dd文件,它是fat16 MBR的转储。我能够正确读取某些字节但不能读取某些字节。

我需要帮助的是SizeOfFat变量需要获取以小端读取的字节0x16和0x17的值。我如何读取FB00然后将其转换为00FB然后打印该值?

char buf[64];
int startFat16 = part_entry[0].start_sect,sectorSize = 512,dirEntrySize=32;
fseek(fp, startFat16*512, SEEK_SET);
fread(buf, 1, 64, fp);

int rootDir = *(int*)(buf+0x11);
int sectorPerCluster = *(int*)(buf+0x0D);
int sizeOfFat = *(int*)(buf+0x16);
int fatCopies = *(int*)(buf+0x10);  
printf("\n Phase 2 \n no of sectors per cluster : %d \n",(unsigned char)sectorPerCluster);
printf("size of fat : %d \n",(unsigned char)sizeOfFat);
printf("no of Fat copies : %d \n",(unsigned char)fatCopies);
printf("maximum number of root directories : %d \n",(unsigned char)rootDir);

我在这里使用的十六进制值是 -

EB 3C 90 4D 53 44 4F 53 35 2E 30 00 02 08 02 00 
02 00 02 00 00 F8 FB 00 3F 00 FF 00 3F 00 00 00
E1 D7 07 00 80 00 29 CD 31 52 F4 4E 4F 20 4E 41

1 个答案:

答案 0 :(得分:1)

使用int,您只能保证它可以保存32位有符号整数。使用您的代码,您可以为每个变量读取sizeof(int)个字节,即使它们的大小不同。大多数系统都有uint16_tuint8_tuint32_t类型。将它们用于固定宽度数据。另请注意,它们是未签名的。您不希望每个群集都有负扇区,对吗?