首页
社区
课程
招聘
[旧帖] 关于获取硬盘序列号的问题 最后一步不会弄了 0.00雪花
发表于: 2009-6-10 21:59 3113

[旧帖] 关于获取硬盘序列号的问题 最后一步不会弄了 0.00雪花

2009-6-10 21:59
3113
function GetDriveGeometry():pchar; stdcall;
const IDENTIFY_BUFFER_SIZE = 512;
type
TSendCmdOutParams = packed record
    cBufferSize  : DWORD;
    DriverStatus : TDriverStatus;
    bBuffer      : Array[0..0] of BYTE;
  end;
var
  hDevice: THandle;
  dTemp: DWord;
  stin:tSENDCMDINPARAMS;
  stout:Array [0..(SizeOf(TSendCmdOutParams)+IDENTIFY_BUFFER_SIZE-1)-1] of Byte;
begin
  Result:=nil;
  hDevice:= CreateFile('\\.\PhysicalDrive0',GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,
                       nil,OPEN_EXISTING,0,0);
  if hDevice = INVALID_HANDLE_VALUE then showmessage('open disk fail');
  FillChar(stin,SizeOf(TSendCmdInParams)-1,#0);
  FillChar(stout,SizeOf(stout),#0);
  dtemp:=0;
  stin.irDriveRegs.bSectorCountReg :=1;
  stin.irDriveRegs.bSectorNumberReg:=1;
  stin.irDriveRegs.bDriveHeadReg :=$A0;
  stin.irDriveRegs.bCommandReg:=$0ec;
  stin.cBufferSize :=IDENTIFY_BUFFER_SIZE;
  if not DeviceIoControl(hDevice,$0007C088,@stIn,sizeof(SENDCMDINPARAMS)-1,@stOut,sizeof(stout),dtemp,nil) then
  showmessage(inttostr(getlasterror()));
//到这里 DeviceIoControl是执行成功的 可是下面如何返回PCHAR 型 输出 不会了呢
  result:=@stout;
  CloseHandle(hDevice);
end;

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 212
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
这样也不行  请高手指点一下 谢谢

procedure ChangeByteOrder( var Data; Size : Integer );
var
  ptr : PChar;
  i : Integer;
  c : Char;
begin
  ptr := @Data;
  for i := 0 to (Size shr 1)-1 do
  begin
    c := ptr^;
    ptr^ := (ptr+1)^;
    (ptr+1)^ := c;
    Inc(ptr,2);
  end;
end;
function GetDriveGeometry():pchar; stdcall;
const IDENTIFY_BUFFER_SIZE = 512;
type
TSendCmdOutParams = packed record
    cBufferSize  : DWORD;
    DriverStatus : TDriverStatus;
    bBuffer      : Array[0..0] of BYTE;
  end;
  TIdSector = packed record
    wGenConfig : Word;
    wNumCyls : Word;
    wReserved : Word;
    wNumHeads : Word;
    wBytesPerTrack : Word;
    wBytesPerSector : Word;
    wSectorsPerTrack : Word;
    wVendorUnique : Array[0..2] of Word;
    sSerialNumber : Array[0..19] of CHAR;
    wBufferType : Word;
    wBufferSize : Word;
    wECCSize : Word;
    sFirmwareRev : Array[0..7] of Char;
    sModelNumber : Array[0..39] of Char;
    wMoreVendorUnique : Word;
    wDoubleWordIO : Word;
    wCapabilities : Word;
    wReserved1 : Word;
    wPIOTiming : Word;
    wDMATiming : Word;
    wBS : Word;
    wNumCurrentCyls : Word;
    wNumCurrentHeads : Word;
    wNumCurrentSectorsPerTrack : Word;
    ulCurrentSectorCapacity : DWORD;
    wMultSectorStuff : Word;
    ulTotalAddressableSectors : DWORD;
    wSingleWordDMA : Word;
    wMultiWordDMA : Word;
    bReserved : Array[0..127] of BYTE;
  end;
  PIdSector = ^TIdSector;
var
  hDevice: THandle;
  dTemp: DWord;
  stin:tSENDCMDINPARAMS;
  stout:Array [0..(SizeOf(TSendCmdOutParams)+IDENTIFY_BUFFER_SIZE-1)-1] of Byte;
  IdOutCmd : TSendCmdOutParams absolute stout;
begin
  Result:=nil;
  hDevice:= CreateFile('\\.\PhysicalDrive0',GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,
                       nil,OPEN_EXISTING,0,0);
  if hDevice = INVALID_HANDLE_VALUE then showmessage('open disk fail');
  FillChar(stin,SizeOf(TSendCmdInParams)-1,#0);
  FillChar(stout,SizeOf(stout),#0);
  dtemp:=0;
  stin.irDriveRegs.bSectorCountReg :=1;
  stin.irDriveRegs.bSectorNumberReg:=1;
  stin.irDriveRegs.bDriveHeadReg :=$A0;
  stin.irDriveRegs.bCommandReg:=$0ec;
  stin.cBufferSize :=IDENTIFY_BUFFER_SIZE;
  if not DeviceIoControl(hDevice,$0007C088,@stIn,sizeof(SENDCMDINPARAMS)-1,@stOut,sizeof(stout),dtemp,nil) then
  showmessage(inttostr(getlasterror()));
  with PIdSector(@IdOutCmd.bBuffer)^ do  begin
    ChangeByteOrder(stout, SizeOf(stout));
    (PChar(@stout)+SizeOf(stout))^:= #0;
    Result := PChar(@stout);
  end;
  CloseHandle(hDevice);
end;
2009-6-11 11:40
0
游客
登录 | 注册 方可回帖
返回
//