我想读C盘Boot扇区,为什么出错(100分)

  • 主题发起人 主题发起人 M42
  • 开始时间 开始时间
M

M42

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TDIOC_REGISTERS = packed record
reg_EBX: DWORD;
reg_EDX: DWORD;
reg_ECX: DWORD;
reg_EAX: DWORD;
reg_EDI: DWORD;
reg_ESI: DWORD;
reg_Flags: DWORD;
end;

TTransfer = record
StartSector: Longint;
SectorCount: Word;
Buffer: Longint;
end;

const
VWIN32_DIOC_DOS_DRIVEINFO = 6;

function myproc:boolean;
var
hDevice: thandle;
reg: TDIOC_REGISTERS;
fResult: boolean;
cb: dword;
transfer: ttransfer;
buf: array[0..511] of char;
const
nDrive = 3; // Drive C:
begin
hDevice := CreateFile('//./VWIN32', GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);

if hdevice = INVALID_HANDLE_VALUE then exit;

transfer.StartSector := 0;
transfer.SectorCount := 1;
transfer.Buffer := longint(@buf);

reg.reg_ESI := 0;
reg.reg_EAX := $7305;
reg.reg_EBX := longint(@transfer);
reg.reg_ECX := $FFFFFFFF;
reg.reg_EDX := ndrive;
reg.reg_Flags := 0;

Result := DeviceIoControl(hDevice, VWIN32_DIOC_DOS_DRIVEINFO,
@reg, sizeof(reg), @reg, sizeof(reg), cb, 0);

CloseHandle(hDevice);
end;
 
VWIN32只能在98下使用.
 
忘了声明一下,就是在98下用的。为什么会不行呢。
 
只要能达到目的,下面的代码可行:
1.编辑一个文件A.DAT(注意必须按下列格式<空行也是>,你最好用粘贴复制):
N D.DAT

L 100 2 0 1

RBX
0

RCX
200

W

Q

2.把A.DAT拷贝到和你的程序同一目录。
3.读取的代码:
Procedure ReadBOOT;
Var
BootBuf : Packed Array [0..511] Of Char;
TmFl : File;
TmD : DWord;
Begin
WinExec(PChar('C:/WINDOWS/COMMAND/DEBUG.EXE<A.DAT'),SW_HIDE);

TmD:=GetTickCount()+2001; { Delay 2s }
While (TmD>GetTickCount()) Do
Application.ProcessMessages;

AssiGnFile(TmFl,'D.DAT');
ReSet(TmFl,1);
BlockRead(TmFl,BootBuf,512);
CloseFile(TmFl);
//现在BootBuf就是C盘的boot
End;
 
接受答案了.
 
后退
顶部