比
比尔.丐痴
Unregistered / Unconfirmed
GUEST, unregistred user!
我写的一个软件中为了防止盗版,采用读取CPU序列号,计算之后认证的方式。但是在安装使用的时候我竟然发现了有相同的CPU序列号。我曾在一个单位的20台联想PIII800的机子里安装了软件(该软件为C/S结构),发现了有三台电脑的CPU序列号一模一样。难道CPU也可以盗版?一下是我获取CPU序列号的代码例子,例子中分别用了四标签来显示CPU序列号中四段。
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons;
type
TDemoForm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Bevel1: TBevel;
Label5: TLabel;
procedure BitBtn1Click(Sender: TObject);
end;
var
DemoForm: TDemoForm;
implementation
{$R *.DFM}
type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;
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;
procedure TDemoForm.BitBtn1Click(Sender: TObject);
var
CPUID : TCPUID;
I : Integer;
S : TVendor;
begin
for I := Low(CPUID) to High(CPUID) do
CPUID := -1;
CPUID := GetCPUID;
Label1.Caption := 'CPUID[1] = ' + IntToHex(CPUID[1],8);
Label2.Caption := 'CPUID[2] = ' + IntToHex(CPUID[2],8);
Label3.Caption := 'CPUID[3] = ' + IntToHex(CPUID[3],8);
Label4.Caption := 'CPUID[4] = ' + IntToHex(CPUID[4],8);
S := GetCPUVendor;
Label5.Caption := S;
end;
end.
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons;
type
TDemoForm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Bevel1: TBevel;
Label5: TLabel;
procedure BitBtn1Click(Sender: TObject);
end;
var
DemoForm: TDemoForm;
implementation
{$R *.DFM}
type
TCPUID = array[1..4] of Longint;
TVendor = array [0..11] of char;
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;
procedure TDemoForm.BitBtn1Click(Sender: TObject);
var
CPUID : TCPUID;
I : Integer;
S : TVendor;
begin
for I := Low(CPUID) to High(CPUID) do
CPUID := -1;
CPUID := GetCPUID;
Label1.Caption := 'CPUID[1] = ' + IntToHex(CPUID[1],8);
Label2.Caption := 'CPUID[2] = ' + IntToHex(CPUID[2],8);
Label3.Caption := 'CPUID[3] = ' + IntToHex(CPUID[3],8);
Label4.Caption := 'CPUID[4] = ' + IntToHex(CPUID[4],8);
S := GetCPUVendor;
Label5.Caption := S;
end;
end.