阅读:1634回复:3
请问如何在驱动中得到硬盘的MBR
各位老大,我想在我的驱动中直接读写硬盘扇区得MBR,但发现使用ZwCreateFile时出错,返回值STATUS_OBJECT_TYPE_MISMATCH,请教各位大虾是何原因导致,如何修改。
具体代码如下: NTSTATUS status; OBJECT_ATTRIBUTES oa; UNICODE_STRING usname; IO_STATUS_BLOCK iostatus; WCHAR wcFileName[MAX_PATH]; HANDLE hFile; IO_STATUS_BLOCK IOSB; LARGE_INTEGER liOffset; memset(wcFileName,0,sizeof(wcFileName)); swprintf(wcFileName,L"\\Device\\Harddisk0"); RtlInitUnicodeString(&usname, wcFileName); InitializeObjectAttributes(&oa, &usname, OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE , NULL, NULL); status = ZwCreateFile(&hFile, GENERIC_READ|GENERIC_WRITE, &oa, &iostatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE|FILE_SHARE_READ, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT|FILE_NO_INTERMEDIATE_BUFFERING, NULL, 0); if(!NT_SUCCESS(status)) { STATUS_INVALID_PARAMETER DbgPrint("\n ZwCreateFile=%d,iostatus=%d",status,iostatus.Information); return FALSE; } liOffset.QuadPart = 0; status = ZwReadFile( hFile, NULL, NULL, NULL, &IOSB, pMbr, 1*SECTOR_SIZE, &liOffset, NULL ); if(!NT_SUCCESS(status)) { //STATUS_INVALID_PARAMETER DbgPrint("\n ZwReadFile=%d,iostatus=%d",status,iostatus.Information); ZwClose(hFile); return FALSE; } return TRUE; |
|
沙发#
发布于:2009-01-10 20:23
IoReadPartitionTable
|
|
|
板凳#
发布于:2009-01-10 20:26
读扇区当然也没问题,不过符号连接好像不是Harddisk0 而是PhysicalDrive0 如果我没记错的话。
|
|
|
地板#
发布于:2009-01-15 14:34
DR0
|
|
|