c - 在 Windows 8 上使用 C 读取引导扇区

标签 c windows operating-system boot

我尝试使用这个程序读取引导扇区

int lire_secteur(int num_sect,unsigned char* buf)
{
int retCode = 0;
unsigned char secteur[512];
char disque[10]   ;
char partition ;
FILE* device ;
do
{
    disque[0]='\0'  ;       
    scanf("%c",&partition) ;
    if (partition=='0')
    {
        strcpy(disque,"\\\\.\\PHYSICALDRIVE0") ;
    }
    else
    {
        sprintf(disque,"\\\\.\\%c:",partition) ;
    }
    device = fopen(disque, "rb+");
}

while (device == NULL) ;
fseek( device,num_sect*512 , SEEK_SET );
if (fread (secteur, 512,1, device) < 1)
{
    printf("erreur\n");
    return 1 ;
}
else
{
    memcpy(buf,secteur, 512);
    retCode=0;
}
return retCode;
}

我已经成功读取了硬盘驱动器中的所有扇区,但是当我想读取引导扇区时,我有这个: enter image description here

是我的代码中的问题还是由于 windows8?

最佳答案

你得到了正确的结果,那就是引导扇区。 您可能希望以十六进制格式打印出来,而不仅仅是像那样的字符串,因为您将向屏幕输出随机控制字符。

关于c - 在 Windows 8 上使用 C 读取引导扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577114/

相关文章:

c++ - 确定函数签名

operating-system - 检测 Julia 中的系统语言

c++ - 哪个线程调用了windows proc回调函数?

c - OpenCV 2.1 : Runtime error

c - 表达式必须具有整型

c - 具有相同数据的两个 C void 指针是否是不同的内存对象?

c++ - Win32 c++ 控制台应用程序和 Eclipse

vba - 从网络主机(LAN 连接的 PC)获取操作系统信息

windows - 无法在Windows 8上切换Docker OS

c - C中的空指针