How to obtain the serial number of a specified CPU in a multi-core, multi-CPU system
Skyjacker
(Please keep it intact and indicate the author and source)
http://www.cnpack.org
Cnpack IV QQ group:130970
2007-01-23
Thanks: Passion,bahamut, Good morning, air, skyjacker ...
Without the Bahamut, there is no such article.
In multi-CPU and multicore, different serial numbers are randomly obtained. This gives us a lot of trouble to make keygen based on the CPU serial number.
Windows 2000/XP allows you to set the affinity of processes and threads. In other words, you can control which CPU can run certain threads. This is called hard affinity. Windows provides a function setprocessaffinitymask that sets affinity. Use it to control the acquisition of the serial number of the specified CPU.
This article is divided into 2 parts:
1, how to get the serial number of the CPU.
2. How to obtain the serial number of the specified CPU or the specified CPU core.
1, how to get the serial number of the CPU.
Use the CPUID command to get.
Before calling the CPUID, the function code is stored in the EAX. After calling the CPUID, Eax,ebx,ecx,edx stores the various characteristic information of the CPU. This information is what we commonly call CPU serial numbers.
mov eax, 0//Get manufacturer Info
Cpuid
mov eax, 1//Get the serial number of the CPU
Cpuid
The following three functions are available for reference:
[C-sharp]View Plaincopy
- function Newcpuid: string;
- Const
- CPUINFO = ' CPU Manufacturer:%s serial number:%x ';
- Var
- S:ARRAY[0..19] of Char;
- Mycpuid:integer;
- Begin
- Fillchar (S, 20, 0);
- Asm
- Push EBX
- Push ECX
- Push edx
- mov eax, 0
- Cpuid
- mov dword ptr s[0], ebx
- mov dword ptr s[4], edx
- mov dword ptr s[8], ecx
- mov eax, 1
- Cpuid
- mov mycpuid, edx
- Pop edx
- Pop ecx
- Pop ebx
- End
- Result: = Format (CPUINFO, [S, Mycpuid]);
- End
- function Getcpuid:tcpuid; Assembler; Register
- Asm
- PUSH EBX {Save affected Register}
- PUSH EDI
- MOV EDI, EAX [email={@Resukt]{@Resukt [/email]}
- MOV EAX, 1
- DW $A 20F {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
- Get the serial number of the CPU:
- function Getcncpuid (): string;
- Const
- CPUINFO = '%.8x-%.8x-%.8x-%.8x ';
- Var
- Ieax:integer;
- Iebx:integer;
- Iecx:integer;
- Iedx:integer;
- Begin
- Asm
- Push EBX
- Push ECX
- Push edx
- mov eax, 1
- DW $A 20F//cpuid
- mov ieax, eax
- mov iebx, ebx
- mov iecx, ecx
- mov iedx, edx
- Pop edx
- Pop ecx
- Pop ebx
- End
- Result: = Format (CPUINFO, [Ieax, IEBX, IECX, Iedx]);
- End
2. How to obtain the serial number of the specified CPU or the specified CPU core.
Depending on how Windows can set the affinity of processes and threads, the Setprocessaffinitymask function is used to control which CPU runs the process that obtains the sequence number, and therefore gets the serial number of the specified CPU. For compatibility with single CPUs, it is recommended to always get the serial number of the first CPU.
[C-sharp]View Plaincopy
- Procedure SetCPU (H:thandle; Cpuno:integer);
- Cpuno: Determines the number of serial numbers for the first few CPU cores.
- Var
- processaffinity:cardinal;
- _systemaffinity:cardinal;
- Begin
- Getprocessaffinitymask (H, processaffinity, _systemaffinity);
- Processaffinity: = Cpuno; //this Sets the process to only run on CPU 0
- //for CPU 1 only use 2 and for CPUs 1 & 2 use 3
- Setprocessaffinitymask (H, processaffinity)
- End
How to use:
SetCPU (getcurrentprocess,1); First CPU core of the first CPU
ShowMessage (GETCNCPUID);
PostScript: This article originates from a discussion of the Cnpack group's question about obtaining the ID of a multicore CPU.
Thanks to all the members of the Cnpack group.
BS ' Good morning Air ' says, "You spend a lot of time in your short life doing this worthless thing"-_-!! Super BS, BS, BS ... ^_^
For i:=0 to 10000000000000000000000000000 do
BS;
Appendix "Good Morning Air" quotations:
' Give up, API's not for you '
' You spend a lot of time in your short life doing this worthless thing. '
Reference: http://blog.csdn.net/iseekcode/article/details/5284803
How to obtain the serial number of a specified CPU in a multi-core, multi-CPU system