能力值:
( LV4,RANK:50 )
|
-
-
2 楼
可以跟楼主套个近乎么 。。。貌似跟我暑假作业有点关系,如果有问题希望能请教LZ啊~
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
其实我也遇到这个问题,后来查到不用驱动也能解决这个问题,Win7/Vista下只需要通过DeviceIoControl发送控制码FSCTL_LOCK_VOLUME先把卷锁然后发送FSCTL_DISMOUNT_VOLUME把卷卸掉就能直接通过ReadFile/WriteFile读写扇区了,以下是Delphi中写入分区引导扇区的代码代码 function TMain.WritePbr(hDevice: THandle; PartNum: Byte; PartitionType: Byte;
LdrName: PChar; const BytesPerSector: DWORD): Boolean;
var
OrgPbr, G4DPbr: PChar;
ByteRet, PbrSize, PbrOfs: DWORD;
Res: TResourceStream;
const
GPTOffset = $01B8;
begin
Result := False;
if not DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, nil, 0, nil, 0, ByteRet,
nil) then
Exit;
try
OrgPbr := AllocMem(BytesPerSector);
try
SetFilePointer(hDevice, 0, nil, FILE_BEGIN);
ReadFile(hDevice, OrgPbr[0], BytesPerSector, ByteRet, nil);
except
FreeMem(OrgPbr, BytesPerSector);
end;
try
Res := TResourceStream.Create(HInstance, 'GRLDR', RT_RCDATA);
try
GetMem(G4DPbr, BytesPerSector * 16);
Move(Res.Memory^, G4DPbr^, BytesPerSector * 16);
ReplaceGrldr(G4DPbr, LdrName);
finally
Res.Free;
end;
except
Exit;
end;
case PartitionType of
PARTITION_FAT_12, PARTITION_FAT_16:
begin
PbrSize := BytesPerSector;
PbrOfs := 3 * BytesPerSector;
Move(OrgPbr[0], G4DPbr[PbrOfs], $3E);
G4DPbr[PbrOfs + $41] := Char(PartNum);
end;
PARTITION_FAT32, PARTITION_FAT32_XINT13:
begin
PbrSize := BytesPerSector;
PbrOfs := 2 * BytesPerSector;
Move(OrgPbr[0], G4DPbr[PbrOfs], $5A);
G4DPbr[PbrOfs + $5D] := Char(PartNum);
end;
PARTITION_IFS:
begin
PbrSize := BytesPerSector * 4;
PbrOfs := 5 * BytesPerSector;
Move(OrgPbr[0], G4DPbr[PbrOfs], $54);
G4DPbr[PbrOfs + $57] := Char(PartNum);
end;
else
PrintLog('分区标识 ' + IntToHex(PartitionType, 2) + '不被支持');
Exit;
end;
try
SetFilePointer(hDevice, 0, nil, FILE_BEGIN);
if DeviceIoControl(hDevice, FSCTL_DISMOUNT_VOLUME, nil, 0, nil, 0,
ByteRet, nil) then
Result := WriteFile(hDevice, G4DPbr[PbrOfs], PbrSize, ByteRet, nil);
finally
FreeMem(G4DPbr, BytesPerSector * 16);
FreeMem(OrgPbr, BytesPerSector);
end;
finally
DeviceIoControl(hDevice, FSCTL_UNLOCK_VOLUME, nil, 0, nil, 0, ByteRet, nil);
end;
end;
|
能力值:
( LV5,RANK:60 )
|
-
-
4 楼
原来如此,谢谢,又学了一种方法!
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
貌似记错了,是需要发送 FSCTL_DISMOUNT_VOLUME 才能写,读是没问题
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
CreateFile不可以???
用这个\\.\PHYSICALDRIVEx 是能打开的读的(能不能写没试)
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
如果是系统分区的话 FSCTL_LOCK_VOLUME会失败吧 FSCTL_DISMOUNT_VOLUME也不好用...
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
nt6下的NTFS如果直接CreateFile只能读写前64个扇区,后面的扇区貌似只能读不能写
|
能力值:
( LV2,RANK:10 )
|
-
-
9 楼
这里讨论的是U盘扇区的读写,即便是通过U盘引导启动的NT6 PE,也是映射到内存中的,不会占用U盘所在分区
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
噢 u盘的话 可以
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
[代码没显示呀
|