How to obtain the serial number of a specified CPU in a multi-core, multi-CPU system

Source: Internet
Author: User

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
  1. function Newcpuid: string;
  2. Const
  3. CPUINFO = ' CPU Manufacturer:%s serial number:%x ';
  4. Var
  5. S:ARRAY[0..19] of Char;
  6. Mycpuid:integer;
  7. Begin
  8. Fillchar (S, 20, 0);
  9. Asm
  10. Push EBX
  11. Push ECX
  12. Push edx
  13. mov eax, 0
  14. Cpuid
  15. mov dword ptr s[0], ebx
  16. mov dword ptr s[4], edx
  17. mov dword ptr s[8], ecx
  18. mov eax, 1
  19. Cpuid
  20. mov mycpuid, edx
  21. Pop edx
  22. Pop ecx
  23. Pop ebx
  24. End
  25. Result: = Format (CPUINFO, [S, Mycpuid]);
  26. End
  27. function Getcpuid:tcpuid; Assembler; Register
  28. Asm
  29. PUSH EBX {Save affected Register}
  30. PUSH EDI
  31. MOV EDI, EAX [email={@Resukt]{@Resukt [/email]}
  32. MOV EAX, 1
  33. DW $A 20F {CPUID Command}
  34. STOSD {cpuid[1]}
  35. MOV EAX, EBX
  36. STOSD {cpuid[2]}
  37. MOV EAX, ECX
  38. STOSD {cpuid[3]}
  39. MOV EAX, EDX
  40. STOSD {Cpuid[4]}
  41. POP EDI {Restore Registers}
  42. POP EBX
  43. End
  44. Get the serial number of the CPU:
  45. function Getcncpuid (): string;
  46. Const
  47. CPUINFO = '%.8x-%.8x-%.8x-%.8x ';
  48. Var
  49. Ieax:integer;
  50. Iebx:integer;
  51. Iecx:integer;
  52. Iedx:integer;
  53. Begin
  54. Asm
  55. Push EBX
  56. Push ECX
  57. Push edx
  58. mov eax, 1
  59. DW $A 20F//cpuid
  60. mov ieax, eax
  61. mov iebx, ebx
  62. mov iecx, ecx
  63. mov iedx, edx
  64. Pop edx
  65. Pop ecx
  66. Pop ebx
  67. End
  68. Result: = Format (CPUINFO, [Ieax, IEBX, IECX, Iedx]);
  69. 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
  1. Procedure SetCPU (H:thandle; Cpuno:integer);
  2. Cpuno: Determines the number of serial numbers for the first few CPU cores.
  3. Var
  4. processaffinity:cardinal;
  5. _systemaffinity:cardinal;
  6. Begin
  7. Getprocessaffinitymask (H, processaffinity, _systemaffinity);
  8. Processaffinity: = Cpuno; //this Sets the process to only run on CPU 0
  9. //for CPU 1 only use 2 and for CPUs 1 & 2 use 3
  10. Setprocessaffinitymask (H, processaffinity)
  11. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.