C++采用ring3读取MBR C++采用ring3读取MBR实例
人气:0想了解C++采用ring3读取MBR实例的相关内容吗,在本文为您仔细讲解C++采用ring3读取MBR的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C++,ring3,读取,MBR,下面大家一起来学习吧。
本文实例讲述了C++采用ring3读取MBR的方法,分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:
DWORD dwBytesReturned = 0;
BYTE bytBuffer_1[512];
BYTE bytBuffer_2[512];
CHAR string[2048];
HANDLE hDevice, hDriver;
BOOL bRet;
hDevice = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDevice == INVALID_HANDLE_VALUE)
{
printf("\nFailed - CreateFile - Open the PhysicalDrive0.\n");
return 0;
}
bRet = ReadFile(hDevice, (LPVOID)bytBuffer_1, 512, &dwBytesReturned, NULL);
if(bRet == FALSE)
{
printf("\nFailed - ReadFile - the first one.\n");
return 0;
}
printf("aaaa");
Sleep(1000*3);
printf("\nRead MBR using the ReadFile function...\n");
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - -");
sprintf(string, "\n");
for(DWORD i = 0; i < 512; i++)
{
sprintf(string, "%s %02X", string, bytBuffer_1[i]);
if(((i + 1) % 16) == 0)
sprintf(string, "%s\n", string);
if(((i + 1) % 16) == 8)
sprintf(string, "%s -", string);
}
printf("%s", string);
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - -");
BYTE bytBuffer_1[512];
BYTE bytBuffer_2[512];
CHAR string[2048];
HANDLE hDevice, hDriver;
BOOL bRet;
hDevice = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDevice == INVALID_HANDLE_VALUE)
{
printf("\nFailed - CreateFile - Open the PhysicalDrive0.\n");
return 0;
}
bRet = ReadFile(hDevice, (LPVOID)bytBuffer_1, 512, &dwBytesReturned, NULL);
if(bRet == FALSE)
{
printf("\nFailed - ReadFile - the first one.\n");
return 0;
}
printf("aaaa");
Sleep(1000*3);
printf("\nRead MBR using the ReadFile function...\n");
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - -");
sprintf(string, "\n");
for(DWORD i = 0; i < 512; i++)
{
sprintf(string, "%s %02X", string, bytBuffer_1[i]);
if(((i + 1) % 16) == 0)
sprintf(string, "%s\n", string);
if(((i + 1) % 16) == 8)
sprintf(string, "%s -", string);
}
printf("%s", string);
printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - -");
打印结果如下:
希望本文所述对大家的C++程序设计有所帮助。
加载全部内容