我試圖讀取 ntfs 磁區。 主要功能:
int main(int argc, char** argv)
{
BYTE sector[512];
ReadSector(L"\\\\.\\E:", 0, sector);
PrintBPB(ReadBPB(sector));
BYTE sector2[512];
ReadSector(L"\\\\.\\E:", 0, sector2);
PrintBPB(ReadBPB(sector2));
return 0;
}
讀取扇區功能:
int ReadSector(LPCWSTR drive, long readPoint, BYTE sector[Sector_Size])
{
int retCode = 0;
DWORD bytesRead;
HANDLE device = NULL;
device = CreateFile(drive, // Drive to open
GENERIC_READ, // Access mode
FILE_SHARE_READ | FILE_SHARE_WRITE, // Share Mode
NULL, // Security Descriptor
OPEN_EXISTING, // How to create
0, // File attributes
NULL); // Handle to template
if (device == INVALID_HANDLE_VALUE) // Open Error
{
printf("CreateFile: %u\n", GetLastError());
return 1;
}
SetFilePointer(device, readPoint, NULL, FILE_BEGIN);//Set a Point to Read
if (!ReadFile(device, sector, 512, &bytesRead, NULL))
{
printf("ReadFile: %u\n", GetLastError());
}
else
{
printf("Success!\n");
}
CloseHandle(device);
}
我認為我將這些位元組復制到我的 BPB bpb 的方式很好。
那么發生了什么?為什么它們不同?我可以弄清楚它與winapi、readfile、createfile有關,但我還是不明白:(
對不起,我的英語不好。

uj5u.com熱心網友回復:
錯誤在我們看不到的代碼中:PrintBPB. 顯然它切換到十六進制輸出(對于“卷序列號”),然后直到稍后才切換回十進制。
當代碼PrintBPB第二次呼叫時,輸出模式仍然是十六進制格式,現在顯示列印“每個扇區的位元組數” 200(0x200與 的值相同512)。
如果您需要知道兩個記憶體塊是否保存相同的值,只需memcmp它們即可。這避免了在轉換中引入錯誤(例如控制臺輸出)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512750.html
標籤:C 温纳皮ntfs
