读取硬盘序列号的源码,欢迎测试上传序列号
最近在学习加密防破解和注册功能。
以前网上搜了一段取硬盘序列号的源码,
有时候会取出乱码。
今天又找了一段,可以取IDE和SIDC的,
修改了下,在D2010中无任何警告提示,找了几个网友试也能取出来。
为了更有效检测效果,所以附送上源码,
希望大家编译以后 把硬盘序列号和什么操作系统列出来,大家一起完善它吧
(大家都用得上)
我先:
硬盘序列号:MP2ZXAXLH62V3S
操作系统: XP SP3
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//------ 取IDE硬盘序列号
function GetIdeHDSerialNo: Ansistring;
const
IDENTIFY_BUFFER_SIZE = 512;
type
TIDERegs = packed record
bFeaturesReg: Byte; //Used for specifying SMART "commands".
bSectorCountReg: Byte; //IDE sector count register
bSectorNumberReg: Byte; //IDE sector number register
bCylLowReg: Byte; //IDE low order cylinder value
bCylHighReg: Byte; //IDE high order cylinder value
bDriveHeadReg: Byte; //IDE drive/head register
bCommandReg: Byte; //Actual IDE command.
bReserved: Byte; //reserved for future use. Must be zero.
end;
TSendCmdInParams = packed record
cBufferSize: DWORD; //Buffer size in bytes
irDriveRegs: TIDERegs; //Structure with drive register values.
bDriveNumber: Byte; //Physical drive number to send command to (0,1,2,3).
bReserved: array[0..2] of Byte;
dwReserved: array[0..3] of DWORD;
bBuffer: array[0..0] of Byte; //Input buffer.
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 AnsiChar;
wBufferType: Word;
wBufferSize: Word;
wECCSize: Word;
sFirmwareRev: array[0..7] of AnsiChar;
sModelNumber: array[0..39] of AnsiChar;
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;
TDriverStatus = packed record
bDriverError: Byte; //驱动器返回的错误代码,无错则返回0
bIDEStatus: Byte; //IDE出错寄存器的内容,只有当bDriverError 为 SMART_IDE_ERROR 时有效
bReserved: array[0..1] of Byte;
dwReserved: array[0..1] of DWORD;
end;
TSendCmdOutParams = packed record
cBufferSize: DWORD; //bBuffer的大小
DriverStatus: TDriverStatus; //驱动器状态
bBuffer: array[0..0] of Byte; //用于保存从驱动器读出的数据的缓冲区,实际长度由cBufferSize决定
end;
var
hDevice: THandle;
cbBytesReturned: DWORD;
//ptr : PChar;
SCIP: TSendCmdInParams;
aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
procedure ChangeByteOrder(var Data; Size: Integer);
var
ptr: PAnsiChar;
i: Integer;
c: AnsiChar;
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;
begin
Result := '';
if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then
begin //Windows NT, Windows 2000
//提示:改变名称可适用于其它驱动器,如第二个驱动器: '\\.\PhysicalDrive1\'
hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
end else //Version Windows 95 OSR2, Windows 98
hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then Exit;
try
FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
cbBytesReturned := 0;
//Set up data structures for IDENTIFY command.
with SCIP do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
//bDriveNumber := 0;
with irDriveRegs do
begin
bSectorCountReg := 1;
bSectorNumberReg := 1;
//if Win32Platform=VER_PLATFORM_WIN32_NT then bDriveHeadReg := $A0
//else bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4);
bDriveHeadReg := $A0;
bCommandReg := $EC;
end;
end;
if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then
Exit;
finally
CloseHandle(hDevice);
end;
with PIdSector(@IdOutCmd.bBuffer)^ do
begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
(PAnsiChar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;
Result := sSerialNumber;
//Result := Trim(StrPas(@sSerialNumber));
end;
end;
//------ 取SCSI硬盘序列号
function GetScsiHDSerialNo: AnsiString;
type
TScsiPassThrough = record
Length: Word;
ScsiStatus: Byte;
PathId: Byte;
TargetId: Byte;
Lun: Byte;
CdbLength: Byte;
SenseInfoLength: Byte;
DataIn: Byte;
DataTransferLength: ULONG;
TimeOutValue: ULONG;
DataBufferOffset: DWORD;
SenseInfoOffset: ULONG;
Cdb: array[0..15] of Byte;
end;
TScsiPassThroughWithBuffers = record
spt: TScsiPassThrough;
bSenseBuf: array[0..31] of Byte;
bDataBuf: array[0..191] of Byte;
end;
var
dwReturned: DWORD;
len: DWORD;
sDeviceName: Ansistring;
hDevice: THandle;
Buffer: array[0..SizeOf(TScsiPassThroughWithBuffers) + SizeOf(TScsiPassThrough) - 1] of Byte;
sptwb: TScsiPassThroughWithBuffers absolute Buffer;
begin
Result := '';
sDeviceName := 'C:';
hDevice := CreateFileA(PAnsiChar('\\.\' + sDeviceName), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then Exit;
try
FillChar(Buffer, SizeOf(Buffer), #0);
with sptwb.spt do
begin
Length := SizeOf(TScsiPassThrough);
CdbLength := 6; // CDB6GENERIC_LENGTH
SenseInfoLength := 24;
DataIn := 1; // SCSI_IOCTL_DATA_IN
DataTransferLength := 192;
TimeOutValue := 2;
DataBufferOffset := PAnsiChar(@sptwb.bDataBuf) - PAnsiChar(@sptwb);
SenseInfoOffset := PAnsiChar(@sptwb.bSenseBuf) - PAnsiChar(@sptwb);
Cdb[0] := $12; // OperationCode := SCSIOP_INQUIRY;
Cdb[1] := $01; // Flags := CDB_INQUIRY_EVPD; Vital product data
Cdb[2] := $80; // PageCode Unit serial number
Cdb[4] := 192; // AllocationLength
end;
len := sptwb.spt.DataBufferOffset + sptwb.spt.DataTransferLength;
if DeviceIoControl(hDevice, $0004D004, @sptwb, SizeOf(TScsiPassThrough),
@sptwb, len, dwReturned, nil) and ((PAnsiChar(@sptwb.bDataBuf) + 1)^ = #$80) then
SetString(Result, PAnsiChar(@sptwb.bDataBuf) + 4, Ord((PAnsiChar(@sptwb.bDataBuf) + 3)^));
//Result := Result;
finally
CloseHandle(hDevice);
end;
end;
//------ 取硬盘序列号(IDE和SISC)
function F_GetHDSerialNo: string;
begin
Result := Trim(WideString(GetIdeHDSerialNo));
if Length(Result) = 0 then
Result := Trim(WideString(GetScsiHDSerialNo));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := F_GetHDSerialNo; //调用这个函数
end;
end.
[最优解释]
帮顶。试试。
经测试硬盘号:WD-WCAVY2203570
[其他解释]
经测试代码:
WD-WCANK1247357
6VM1CPBN
STA207MV02UT0D
9VMFGBHL
[其他解释]
jf....
[其他解释]
这个东西要怎么完善。、?
[其他解释]
经win7系统测试,完好。
[其他解释]
JF 回去试试
------其他解决方案--------------------
SCSI, Raid卡,多硬盘的朋友可以一起帮忙测试吗
[其他解释]
硬盘序列号或网卡,用那一个加密软件可靠一些?
[其他解释]
先收藏一下,谢谢楼主
[其他解释]
不知道是否稳定,会不会出现提取不出来的现象
[其他解释]
感谢大家。
我那几个网友也是WD-XXX 开头的多
就是多些人测试 不同硬盘 不同系统
这样才能知道代码的不同
[其他解释]
WD是硬盘的标识而已
[其他解释]
WD是指西部数据么?-。-
[其他解释]
没有人气 就结了吧
[其他解释]
支持SATA?
[其他解释]
没用,WIN7下SATA的读不到。