全副身家求硬盘序列号函数(100分)

  • 主题发起人 主题发起人 superplayboy
  • 开始时间 开始时间
试试这一个,已发给你。
 
唉,大都是在DFW上贴了N遍的了,利用VXD来做的
我的帖子已经说过,恐怕只有汇编才可以解决,你看到例程凡是没有汇编
代码的基本上都是不行的了
 
这儿有个DLL版的,见过没有?不知对你有没帮助。
http://www.playicq.com/dispdoc.php?t=&id=1205
 
这个是和那个DISKSN控件同一个作者写的,但是我对DLL的不感兴趣,太容易被破了
 
晚上自己试试。。。。。。

自己写东西~~~不用那个vxd。。。呼呼NT
 
to superplayboy:
我想要那个forD5的比较完美的空件,可以吗?
booy@etang.com
谢谢
 
to booy:
到这里下载吧:http://tj-gmjf.com/dandy/
 
并不是每一台工作站都有硬盘的,像无盘网络的工作站终端,嘿不要说了就是无盘
而有个朋友提到用网卡的ID,但也并不是每台计算机都会配置一块网卡的
唯一的方法就是获取主板号吧,不管是有、无盘都会有一块主板的
愿让参考源码吗??pdc_diy_163@163.com
 
再次写出这个函数:
---------------------------------------------
Function GetIdeSN : Pchar; StdCall;
type
TSrbIoControl = Packed record
HeaderLength : ULONG;
Signature : Array[0..7] of Char;
Timeout : ULONG;
ControlCode : ULONG;
ReturnCode : ULONG;
Length : ULONG;
end;
SRB_IO_CONTROL = TSrbIoControl;
PSrbIoControl = ^TSrbIoControl;

TIDERegs = Packed record
bFeaturesReg : Byte;
bSectorCountReg : Byte;
bSectorNumberReg : Byte;
bCylLowReg : Byte;
bCylHighReg : Byte;
bDriveHeadReg : Byte;
bCommandReg : Byte;
bReserved : Byte;
end;
IDEREGS = TIDERegs;
PIDERegs = ^TIDERegs;

TSendCmdInParams = Packed record
cBufferSize : DWORD;
irDriveRegs : TIDERegs;
bDriveNumber : Byte;
bReserved : Array[0..2] of Byte;
dwReserved : Array[0..3] of DWORD;
bBuffer : Array[0..0] of Byte;
end;
SENDCMDINPARAMS = TSendCmdInParams;
PSendCmdInParams = ^TSendCmdInParams;

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 : ULONG;
wMultSectorStuff : Word;
ulTotalAddressableSectors : ULONG;
wSingleWordDMA : Word;
wMultiWordDMA : Word;
bReserved : Array[0..127] of Byte;
end;
PIdSector = ^TIdSector;

const
IDE_ID_FUNCTION = $EC;
IDENTIFY_BUFFER_SIZE = 512;
DFP_RECEIVE_DRIVE_DATA = $0007c088;
IOCTL_SCSI_MINIPORT = $0004d008;
IOCTL_SCSI_MINIPORT_IDENTIFY = $001b0501;
DataSize = sizeof(TSendCmdInParams) - 1 + IDENTIFY_BUFFER_SIZE;
BufferSize = SizeOf(SRB_IO_CONTROL) + DataSize;
W9xBufferSize = IDENTIFY_BUFFER_SIZE + 16;
var
hDevice : THandle;
cbBytesReturned : DWORD;
pInData : PSendCmdInParams;
pOutData : Pointer;
S : String;
Buffer : Array[0..BufferSize - 1] of Byte;
srbControl : TSrbIoControl absolute Buffer;

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;

begin
Result := 'THE_SCSI_HARDDISK';
FillChar(Buffer, BufferSize, #0);
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
hDevice := CreateFile('//./Scsi0:', 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
srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL);
System.Move('SCSIDISK', srbControl.Signature, 8);
srbControl.Timeout := 2;
srbControl.Length := DataSize;
srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY;
pInData := PSendCmdInParams(PChar(@Buffer) + SizeOf(SRB_IO_CONTROL));
pOutData := pInData;
with pInData^ do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegs do
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl(hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil) then
Exit;
finally
CloseHandle(hDevice);
end;
end
else
begin
hDevice := CreateFile('//./SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
if hDevice=INVALID_HANDLE_VALUE then
Exit;
try
pInData := PSendCmdInParams(@Buffer);
pOutData := PChar(@pInData^.bBuffer);
with pInData^ do
begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
bDriveNumber := 0;
with irDriveRegs do
begin
bFeaturesReg := 0;
bSectorCountReg := 1;
bSectorNumberReg := 1;
bCylLowReg := 0;
bCylHighReg := 0;
bDriveHeadReg := $A0;
bCommandReg := IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl(hDevice, DFP_RECEIVE_DRIVE_DATA, pInData, SizeOf(TSendCmdInParams)-1, pOutData, W9xBufferSize, cbBytesReturned, nil) then
Exit;
finally
CloseHandle(hDevice);
end;
end;

with PIdSector(PChar(pOutData) + 16)^ do
begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
SetString(S, sSerialNumber, SizeOf(sSerialNumber));
Result := Pchar(S);
end;
end;
 
楼上的,看到这句代码了么?
hDevice := CreateFile('//./SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);

需要smartvsd.vxd支持的
 
nt以上应该没有问题的了。
好像有个98下跳转0级的,我没有调试,你可以找找:)
 
我有一个硬盘序列号源码,给分或者告诉我如何给软件做注册码(经典得那种)lsssxs@360c.ncom
 
把硬盘序列号源码的来一个兄弟! ztaif@163.com
 
关注下列问题,一定对你有益:
http://delphibbs.com/delphibbs/dispq.asp?lid=1743719
http://delphibbs.com/delphibbs/dispq.asp?lid=1742072
http://delphibbs.com/delphibbs/dispq.asp?lid=1655569
http://delphibbs.com/delphibbs/dispq.asp?lid=1786356
 
unit ISDNUNIT;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TSrbIoControl=packed record
HeaderLength: ULONG;
Signature: Array[0..7] of char;
Timeout: ULONG;
ControlCode: ULONG;
ReturnCode: ULONG;
Length: ULONG;
END;
SRB_IO_CONTROL=TSrbIoControl;
PSrbIoControl=^TSrbIoControl;

TIDERegs=packed record
bFeaturesReg: Byte;
bSectorCountReg: Byte;
bSectorNumberReg: byte;
bCyllowReg: byte;
bCylhighreg:byte;
bDriveHeadReg: byte;
bCommandReg: byte;
bReserved: byte;
end;
IDEREGS=TIDERegs;
PIDERegs=^TIDERegs;

TSendCmdInParams=packed record
cBufferSize: DWORD;
irDriveRegs: TIDEREGS;
bDriveNumber:byte;
bReserved: Array[0..2] of byte;
dwReserved: Array[0..3] of DWORD;
bBUFFER: array[0..10] of byte;
end;
SENDCMDINPARAMS=TSendCmdInParams;
PSendcmdinparams=^Tsendcmdinparams;

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;
wreservedL:word;
wPIOTiming:word;
wDMATiming:word;
wBS:WORD;
wNUMcurrentCYls:word;
wNUMcurrentHeads:word;
wNUMCurrentsectorsPerTRACK:WORD;
ulCurrentSectorCapacity:ULONG;
wMultSectorStuff:Word;
ulTotalAddressableSectors:ULONG;
wSingleWordDMA:Word;
wMultiwordDMA:word;
bReserved: Array[0..127] of byte;
end;
PIdSector=^TidSECTOR;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }


end;
// procedure ChangeByteorder(var data; Size:INTEGER);
// Function readhdserial:string;
// FUNCTION ENCRyPT(serial:string):string;
var
Form1: TForm1;
serial:string;
inputserial:string;
CONST
IDENTIFY_BUFFER_SIZE=512;
DataSize=sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;
IOCTL_SCSI_MINIPORT=$0004d008;
IOCTL_SCSI_MINIPORT_IDENTIFY=$001b0501;
IDE_ID_FUNCTION=$EC;
BufferSize=1280;
implementation

{$R *.DFM}

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 readhdserial:string;
var
hDevice:THandle;
cbBYTESReturned:DWORD;
pindata:PSendCmdInParams;
//pide:Pideregs;
pOutData:Pointer;
Buffer:Array[0..BufferSize-1] of Byte;
srbCONTROL:tSrbIoControl absolute Buffer;
begin
result:='';
Fillchar(Buffer,buffersize,#0);
hDevice:=CreateFile('//./Scsi0:',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
srbControl.HeaderLength:=sizeof(SRB_IO_CONTROL);
System.Move('SCSIDISK',srbControl.signature,8);
srbcontrol.timeout:=2;
srbcontrol.Length:=datasize;
srbcontrol.ControlCode:=IOCTL_SCSI_MINIPORT_IDENTIFY;
pInData:=PSendCmdInparams(pchar(@buffer)+sizeof(SRB_IO_CONTROL));
pOutData:=pInData;
with pInDATA^ DO
begin
cBuffersize:=IDENTIFY_BUFFER_SIZE;
bDriveNumber:=0;
// irDriveRegs:=0;
with irDriveRegs do
begin
bFeaturesreg:=1;
bsectorcountreg:=1;
bsectornumberreg:=1;
bcyllowreg:=0;
bcylhighreg:=0;
bdriveheadreg:=$A0;
bcommandreg:=IDE_ID_FUNCTION;
end;
end;
if not DeviceIoControl(hDevice,IOCTL_SCSI_MINIPORT,
@Buffer,BufferSize,@buffer,buffersize,cbbytesreturned,nil) then

exit;
with Pidsector(pchar(poutdata)+16)^ do
begin
changebyteorder(sSerialNUMber,sizeof(sserialnumber));
setstring(result,sserialnumber,sizeof(sserialnumber));
end;
finally
closehandle(hdevice);
end;
end;

function encrypt(serial:string):string;
var
i:DwoRD;
LEN:DWORD;
R:DWORD;
begin
R:=0;
LEN:=LENGTH(SERIAL);
FOR I:=1 TO LEN DO
BEGIN
R:=R+DWORD(SERIAL);
R:=R * 10;
END;
RESULT:=INTTOSTR(R);
END;
 
两个单元:在98/me/2000/xp测试通过。
biosHelp.pas:
unit BiosHelp;

{$ALIGN ON}
{$MINENUMSIZE 4}

interface

uses
Windows;

type
PRomBiosDump = ^TRomBiosDump;
TRomBiosDump = array [$000F0000..$000FFFFF] of Byte;

type
TReadRomBiosMethod = (
rrbmAutomatic, { Autodetect OS type and use proper method }
rrbmGeneric, { Use 16-bit COM program to dump the BIOS }
rrbmMemory, { Read from memory (Win9x) }
rrbmPhysical { Read from physical memory object (WinNT) }
);

function ReadRomBios(var Dump: TRomBiosDump; Method: TReadRomBiosMethod;
Timeout: DWORD = INFINITE): Boolean;

function GetRomBiosBuffer(const Dump: TRomBiosDump; Address: Pointer;
var Buffer; BufferSize: Cardinal): Cardinal;
function GetRomBiosString(const Dump: TRomBiosDump; Address: Pointer): string;
function GetRomBiosLongLong(const Dump: TRomBiosDump; Address: Pointer):
LONGLONG;
function GetRomBiosDWord(const Dump: TRomBiosDump; Address: Pointer): DWORD;
function GetRomBiosWord(const Dump: TRomBiosDump; Address: Pointer): Word;
function GetRomBiosByte(const Dump: TRomBiosDump; Address: Pointer): Byte;

implementation

{##############################################################################
#
# #
# GENERIC METHOD #
# #
# Create an temporary folder, save an 16bit COM program (RomDump.com) into it,
#
# execute program redirected to an file (Rom.dmp, RomDump.com simply dumps the
#
# memory range F000:0000-F000:FFFF to STDOUT), read dump file into the buffer,
#
# and finally cleanup all temporary files and directories. #
# #
# (the function RomDumpCode is x86 specific, which i wrote to generate 16-bit #
# code with the help of the 23-bit Delphi compiler, never try to execute the #
# pseudo-code in your program! it will not work in 32-bit protected mode) #
# #
###############################################################################
}

{ *INTERNAL* - Pseudo 16-bit code }

type
PRomDumpCodeInfo = ^TRomDumpCodeInfo;
TRomDumpCodeInfo = (rdciStart, rdciEnd, rdciSize);

function _RomDumpCode(Info: TRomDumpCodeInfo): Pointer;
var
CodeStart: Pointer;
CodeEnd: Pointer;
begin
asm
JMP @@End

{ *BEGIN* 16-bit code }
{ -- never use it in your program! -- }
{ COM which writes ROM-BIOS to StdOut }
@@Start:
{ Dump F000:0000-F000:FFFE }
XOR eDX, eDX // DS = 0xF000 ; Data segment
MOV DH, 0F0h
MOV DS, eDX
XOR eDX, eDX // DX = 0x0000 ; Data offset
XOR eCX, eCX // CX = 0xFFFF ; Data length
DEC eCX
XOR eBX, eBX // BX = 0x0001 ; STDOUT (file handle)
INC eBX
MOV AH, 40h // DosCall(0x40) ; INT21, DOS_WRITE_TO_HANDLE
INT 21h
JC @@Exit // On error exit ; AL = Error code
{ Dump F000:FFFF }
XOR eDX, eDX // DS = 0xF000 ; Data segment
MOV DH, 0F0h
MOV DS, eDX
XOR eDX, eDX // DX = 0xFFFF ; Data offset
DEC eDX
XOR eCX, eCX // CX = 0x0001 ; Data length
INC eCX
MOV eBX, eCX // BX = 0x0001 ; STDOUT (file handle)
MOV AH, 40h // DosCall(0x40) ; INT21, DOS_WRITE_TO_HANDLE
INT 21h
JC @@Exit // On error exit ; AL = Error code
MOV AL, 0 // no error ; AL = 0
@@Exit:
MOV AH, 4Ch // DosCall(0x4C) ; INT21, DOS_TERMINATE_EXE
INT 21h
@@End:
{ *END* 16-bit code }

MOV CodeStart, OFFSET @@Start
MOV CodeEnd, OFFSET @@End
end;
case Info of
rdciStart:
Result := CodeStart;
rdciEnd:
Result := CodeEnd;
rdciSize:
Result := Pointer(Cardinal(CodeEnd) - Cardinal(CodeStart));
else
Result := nil;
end;
end;

{ *INTERNAL* - Save 16-bit code to file }

function _RomDumpCodeToFile(const Filename: string): Boolean;
var
ComFile: THandle;
Size: Cardinal;
begin
Result := False;
ComFile := CreateFile(PChar(Filename), GENERIC_WRITE, FILE_SHARE_READ, nil,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if ComFile <> INVALID_HANDLE_VALUE then
try
Result := WriteFile(ComFile, _RomDumpCode(rdciStart)^,
Cardinal(_RomDumpCode(rdciSize)), Size, nil) and
(Size = Cardinal(_RomDumpCode(rdciSize)));
if not Result then
DeleteFile(PChar(Filename));
finally
CloseHandle(ComFile);
end;
end;

{ *INTERNAL* - Execute 16-bit code redirected to file }

function _RomDumpCodeExecute(const Com, Dmp: string; Timeout: DWORD): Boolean;
var
ComSpec: string;
si: TStartupInfo;
pi: TProcessInformation;
begin
Result := False;
SetLength(ComSpec, MAX_PATH);
SetLength(ComSpec,
GetEnvironmentVariable('ComSpec', PChar(@ComSpec[1]), MAX_PATH));
if Length(ComSpec) > 0 then
begin
FillChar(si, SizeOf(TStartupInfo), 0);
si.cb := SizeOf(TStartupInfo);
si.dwFlags := STARTF_USESHOWWINDOW;
si.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(ComSpec + ' /C ' + Com + ' > ' + Dmp),
nil, nil, False, CREATE_NEW_CONSOLE or CREATE_NEW_PROCESS_GROUP, nil,
nil, si, pi) then
try
Result := WaitForSingleObject(pi.hProcess, Timeout) <> WAIT_TIMEOUT;
finally
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end;
end;
end;

function DirectoryExists(const Dir: string): Boolean;
var
Attr: DWORD;
begin
Attr := GetFileAttributes(PChar(Dir));
Result := (Attr <> $FFFFFFFF) and
(Attr and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY);
end;

{ Get BIOS dump the generic way }

function ReadRomBios16(var Buffer: TRomBiosDump; Timeout: DWORD): Boolean;
const
TempSub = '~RomDmp';
ComName = 'RomDump.com';
DmpName = 'Rom.dmp';
var
TempPath: string;
TempDir: string;
TempIdx: Integer;
TempIdxStr: string;
ComFile: string;
DmpFile: string;
DmpHandle: THandle;
Written: DWORD;
begin
Result := False;
SetLength(TempPath, MAX_PATH);
SetLength(TempPath, GetTempPath(MAX_PATH, PChar(@TempPath[1])));
if Length(TempPath) > 0 then
begin
if (TempPath[Length(TempPath)] <> '/') then
TempPath := TempPath + '/';
TempIdx := 0;
repeat
Inc(TempIdx);
Str(TempIdx, TempIdxStr);
TempDir := TempPath + TempSub + TempIdxStr;
until not DirectoryExists(TempDir);
if CreateDirectory(PChar(TempDir), nil) then
try
TempDir := TempDir + '/';
ComFile := TempDir + ComName;
DmpFile := TempDir + DmpName;
if _RomDumpCodeToFile(ComFile) then
try
if _RomDumpCodeExecute(ComFile, DmpFile, Timeout) then
begin
DmpHandle := CreateFile(PChar(DmpFile), GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if DmpHandle <> INVALID_HANDLE_VALUE then
try
FillChar(Buffer, SizeOf(TRomBiosDump), 0);
Result := ReadFile(DmpHandle, Buffer, SizeOf(TRomBiosDump),
Written, nil) and (Written = SizeOf(TRomBiosDump));
finally
CloseHandle(DmpHandle);
end;
end;
finally
DeleteFile(PChar(DmpFile));
DeleteFile(PChar(ComFile));
end;
finally
RemoveDirectory(PChar(TempDir));
end;
end;
end;

{##############################################################################
#
# #
# DIRECT METHOD (Win9x) #
# #
# Due to the fact that Windows 95/98/ME maps the BIOS into every Win32 process
#
# for read access it is very simple to fill the buffer from memory. #
# #
###############################################################################
}

function ReadRomBios9x(var Buffer: TRomBiosDump): Boolean;
begin
Result := False;
try
FillChar(Buffer, SizeOf(TRomBiosDump), 0);
Move(Pointer(Low(TRomBiosDump))^, Buffer, SizeOf(TRomBiosDump));
Result := True;
except
// ignore exceptions
end
end;

{##############################################################################
#
# #
# PHYSICAL MEMORY METHOD (WinNT) #
# #
# On Windows NT the ROM BIOS is only available through the named kernel object
#
# '/Device/PhysicalMemory'. Because it is impossible to open kernel objects in
#
# user mode with standard Win32 API functions we make use of NT's nativeAPI in
#
# NtDll.dll ("NT-Layer") namely ZwOpenSection. #
# #
# (note: mostly there are two versions of every function ZwXxx and NtXxx. The #
# only difference in kernel mode is that the NtXxx version works in conside- #
# ration to security while ZwXxx not. But in user mode both work like NtXxx.)
#
# #
# At first the section is opened with ZwOpenSection. Normally we would proceed
#
# ZwMapViewOfSection, ZwUnmapViewOfSection, and NtClose. But the functions are
#
# more complex and there is no needing for it. With the handle (because we are
#
# in the "very simple" user mode =) we now use MapViewOfFile, UnmapViewOfFile,
#
# and CloseHandle to map an memory window (the ROM BIOS) into our process. #
# #
# Due to the fact that ZwOpenSection returns NT error-codes in case of failure
#
# we have to translate it to an Win32 error-code (RtlNtStatusToDosError). #
# All NT specific functions are dynamically loaded -- because the applications
#
# should start on Win9x systems =) #
# #
###############################################################################
}

{ For more information see Windows 2000/XP DDK }
{ It works on Windows NT 4.0 too, use NtDll.dll }

type
NTSTATUS = Integer;

const
STATUS_SUCCESS = NTSTATUS(0);
STATUS_INVALID_HANDLE = NTSTATUS($C0000008);
STATUS_ACCESS_DENIED = NTSTATUS($C0000022);

type
PUnicodeString = ^TUnicodeString;
TUnicodeString = packed record
Length: Word;
MaximumLength: Word;
Buffer: PWideChar;
end;

const
OBJ_INHERIT = $00000002;
OBJ_PERMANENT = $00000010;
OBJ_EXCLUSIVE = $00000020;
OBJ_CASE_INSENSITIVE = $00000040;
OBJ_OPENIF = $00000080;
OBJ_OPENLINK = $00000100;
OBJ_KERNEL_HANDLE = $00000200;
OBJ_VALID_ATTRIBUTES = $000003F2;

type
PObjectAttributes = ^TObjectAttributes;
TObjectAttributes = record
Length: ULONG;
RootDirectory: THandle;
ObjectName: PUnicodeString;
Attributes: ULONG;
SecurityDescriptor: PSecurityDescriptor;
SecurityQualityOfService: PSecurityQualityOfService;
end;

const
ObjectPhysicalMemoryDeviceName = '/Device/PhysicalMemory';
ObjectPhysicalMemoryName: TUnicodeString = (
Length: Length(ObjectPhysicalMemoryDeviceName) * 2;
MaximumLength: Length(ObjectPhysicalMemoryDeviceName) * 2 + 2;
Buffer: ObjectPhysicalMemoryDeviceName;
);
ObjectPhysicalMemoryAccessMask: ACCESS_MASK = SECTION_MAP_READ;
ObjectPhysicalMemoryAttributes: TObjectAttributes =(
Length: SizeOf(TObjectAttributes);
RootDirectory: 0;
ObjectName: @ObjectPhysicalMemoryName;
Attributes: OBJ_CASE_INSENSITIVE;
SecurityDescriptor: nil;
SecurityQualityOfService: nil;
);

type
TFNZwOpenSection = function(out SectionHandle: THandle;
DesiredAccess: ACCESS_MASK; ObjectAttributes: PObjectAttributes): NTSTATUS;
stdcall;
TFNRtlNtStatusToDosError = function(Status: NTSTATUS): DWORD; stdcall;

const
ntdll = 'ntdll.dll';

var
ZwOpenSection: TFNZwOpenSection;
RtlNtStatusToDosError: TFNRtlNtStatusToDosError;

function ReadRomBiosNt(var Buffer: TRomBiosDump; Timeout: DWORD): Boolean;
var
NtLayer: HMODULE;
Status: NTSTATUS;
Section: THandle;
View: Pointer;
begin
Result := False;
NtLayer := GetModuleHandle(ntdll);
if NtLayer = 0 then
SetLastError(ERROR_CALL_NOT_IMPLEMENTED)
else
begin
if not Assigned(ZwOpenSection) then
ZwOpenSection := GetProcAddress(NtLayer, 'ZwOpenSection');
if not Assigned(RtlNtStatusToDosError) then
RtlNtStatusToDosError := GetProcAddress(NtLayer,
'RtlNtStatusToDosError');
if not (Assigned(ZwOpenSection) and Assigned(RtlNtStatusToDosError)) then
SetLastError(ERROR_CALL_NOT_IMPLEMENTED)
else
begin
Status := ZwOpenSection(Section, ObjectPhysicalMemoryAccessMask,
@ObjectPhysicalMemoryAttributes);
case Status of
STATUS_SUCCESS:
try
View := MapViewOfFile(Section, ObjectPhysicalMemoryAccessMask, 0,
Low(TRomBiosDump), SizeOf(TRomBiosDump));
if Assigned(View) then
try
FillChar(Buffer, SizeOf(TRomBiosDump), 0);
Move(View^, Buffer, SizeOf(TRomBiosDump));
Result := True;
finally
UnmapViewOfFile(View);
end;
finally
CloseHandle(Section);
end;
STATUS_ACCESS_DENIED:
Result := ReadRomBios16(Buffer, Timeout);
else
SetLastError(RtlNtStatusToDosError(Status))
end;
end;
end;
end;

{##############################################################################
#
# #
# ReadRomBios #
# #
###############################################################################
}

function ReadRomBios(var Dump: TRomBiosDump; Method: TReadRomBiosMethod;
Timeout: DWORD = INFINITE): Boolean;
begin
Result := False;
case Method of
rrbmAutomatic:
if (Integer(GetVersion) < 0) then
try
Result := ReadRomBios9x(Dump);
except
Result := ReadRomBios16(Dump, Timeout);
end
else
Result := ReadRomBiosNt(Dump, Timeout);
rrbmGeneric:
Result := ReadRomBios16(Dump, Timeout);
rrbmMemory:
Result := ReadRomBios9x(Dump);
rrbmPhysical:
Result := ReadRomBiosNt(Dump, Timeout);
else
SetLastError(ERROR_INVALID_PARAMETER);
end;
end;

{##############################################################################
#
# #
# Utilities to simplify the access to data as generic standard types #
# #
###############################################################################
}

function GetRomBiosBuffer(const Dump: TRomBiosDump; Address: Pointer;
var Buffer; BufferSize: Cardinal): Cardinal;
//Dump就是 ReadRomBios 读出来的数组,
//Address就是起始的读取的地址,BufferSize就是你要读取的大小。
begin
Result := 0;
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump)) then
begin
Result := BufferSize;
if (Cardinal(Address) + BufferSize > High(TRomBiosDump)) then
Result := High(TRomBiosDump) - Cardinal(Address) + 1;
Move(Dump[Cardinal(Address)], Buffer, Result);
end;
end;

function GetRomBiosString(const Dump: TRomBiosDump; Address: Pointer): string;
begin
Result := '';
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump)) then
Result := string(PChar(@Dump[Cardinal(Address)]));
end;

function GetRomBiosLongLong(const Dump: TRomBiosDump; Address: Pointer):
LONGLONG;
type
PLongLong = ^LONGLONG;
begin
Result := 0;
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump) - SizeOf(LONGLONG) + 1) then
Result := PLongLong(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosDWord(const Dump: TRomBiosDump; Address: Pointer): DWORD;
begin
Result := 0;
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump) - SizeOf(DWORD) + 1) then
Result := PDWORD(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosWord(const Dump: TRomBiosDump; Address: Pointer): Word;
begin
Result := 0;
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump) - SizeOf(Word) + 1) then
Result := PWord(@Dump[Cardinal(Address)])^;
end;

function GetRomBiosByte(const Dump: TRomBiosDump; Address: Pointer): Byte;
begin
Result := 0;
if (Cardinal(Address) >= Low(TRomBiosDump)) and
(Cardinal(Address) <= High(TRomBiosDump) - SizeOf(Byte) + 1) then
Result := PByte(@Dump[Cardinal(Address)])^;
end;

end.

对bioshelp调用单元:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses bioshelp;
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
RBD: TRomBiosDump;
begin
if ReadRomBios(RBD, rrbmAutomatic) then
begin
edit1.Text := GetRomBiosString(RBD, Ptr($ffff5)); // bios date
edit2.Text := GetRomBiosString(RBD, Ptr($ffa68)); // bios name
edit3.Text := GetRomBiosString(RBD, Ptr($fe061)); // bios version
edit4.Text := GetRomBiosString(RBD, Ptr($FEC71)); // bios serial number
edit5.Text := GetRomBiosString(RBD, Ptr($fe091)); // bios copyringht
end
end;
end.
 
to zjxuji:
如果使用相同的主板,并且BIOS版本也相同的话,得到的BIOS SN也就一样了,即使不使用相同的主板,
只要刷了相同的BIOS就可以得到一样的BIOS SN,不适合用来做加密。
 
后退
顶部