//读取硬盘主引导记录
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
char lpBuffer[512] = { 0 };
char *fileName = "\\\\.\\PHYSICALDRIVE0";
HANDLE hFile = NULL;
DWORD numRead = 0;
int ErrorCode = 0;
hFile = CreateFileA(fileName, GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,NULL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
ErrorCode = GetLastError();
MessageBoxA(NULL, "Open File Failed!", "Warring", MB_OK);
return 0;
}
ReadFile(hFile, lpBuffer, 512, &numRead, NULL);
for(int i = 1; i<=446; i++)
{
printf("%02X ", (BYTE)lpBuffer[i-1]);
if( !(i%8) )
{
printf(" ");
}
if( !(i%16) )
{
printf("\n");
}
}
printf("\n\n");
for(int i = 1; i<=64; i++)
{
printf("%02X ", (BYTE)lpBuffer[i-1+446]);
if( !(i%8) )
{
printf(" ");
}
if( !(i%16) )
{
printf("\n");
}
}
printf("\n\n");
printf("%02X %02X\n", (BYTE)lpBuffer[510], (BYTE)lpBuffer[511]);
getchar();
return 0;
}