adminysh

[系统应用] Delphi 获取CPUid号作为硬件机器码

type
  TCPUID = array[1..4] of Longint;   //获取CPUID用
  TVendor = array [0..11] of char;   //获取CPUID用

function GetCPUInfo:string;       //获取CPU序列号

function tform1.GetCPUInfo:string;
var
CPUID: TCPUID;
I: Integer;

Function GetCPUID: TCPUID; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Resukt}
MOV EAX,1
DW $A20F {CPUID Command}
STOSD {CPUID[1]}
MOV EAX,EBX
STOSD {CPUID[2]}
MOV EAX,ECX
STOSD {CPUID[3]}
MOV EAX,EDX
STOSD {CPUID[4]}
POP EDI {Restore registers}
POP EBX
end;

Function GetCPUVendor: TVendor; assembler; register;
asm
PUSH EBX {Save affected register}
PUSH EDI
MOV EDI,EAX {@Result (TVendor)}
MOV EAX,0
DW $A20F {CPUID Command}
MOV EAX,EBX
XCHG EBX,ECX {save ECX result}
MOV ECX,4
@1:
STOSB
SHR EAX,8
LOOP @1
MOV EAX,EDX
MOV ECX,4
@2:
STOSB
SHR EAX,8
LOOP @2
MOV EAX,EBX
MOV ECX,4
@3:
STOSB
SHR EAX,8
LOOP @3
POP EDI {Restore registers}
POP EBX
end;

begin
for I := Low(CPUID) to High(CPUID) do
CPUID[I] := -1;
CPUID := GetCPUID;
Result := IntToHex(CPUID[1], 8) + IntToHex(CPUID[3], 8)
+ IntToHex(CPUID[4], 8);
end;

#1楼
发帖时间:2013-8-21   |   查看数:0   |   回复数:0
游客组