前几天破解了一个软件, 软件的算法倒没什么, 不过学会了取 CPU 和 Harddisk 信息, 网上搜索一下, 取 Harddisk 信息的程序网上有, 取 CPU 信息的也有, 但没下面详细, 所以写了个 C++ 程序, 演示一下 嵌入汇编 和 CPUID 指令. 有兴趣的大侠可以跟一下 CPUZ 这类软件, 学到更多东西.
代码:
#include <windows.h> #include <iostream.h> #include <stdio.h> int main() { char OEMString[13]; char Company[64]; int iEAXValue,iEBXValue,iECXValue,iEDXValue; _asm { mov eax,0 cpuid mov DWORD PTR OEMString, ebx mov DWORD PTR OEMString+4, edx mov DWORD PTR OEMString+8, ecx } OEMString[12]=0; if ( !strcmp(OEMString, "GenuineIntel")) strcpy(Company, "Intel Corporation"); else if ( !strcmp(OEMString, "UMC UMC UMC ")) strcpy(Company, "United Microelectronics Corp."); else if ( !strcmp(OEMString, "AuthenticAMD")) strcpy(Company, "Advanced Micro Devices"); else if ( !strcmp(OEMString, "AMD ISBETTER")) strcpy(Company, "Advanced Micro Devices"); else if ( !strcmp(OEMString, "CyrixInstead")) strcpy(Company, "Cyrix Corp., VIA Inc."); else if ( !strcmp(OEMString, "NexGenDriven")) strcpy(Company, "NexGen Inc., Advanced Micro Devices"); else if ( !strcmp(OEMString, "CentaurHauls")) strcpy(Company, "IDT\\Centaur, Via Inc."); else if ( !strcmp(OEMString, "RiseRiseRise")) strcpy(Company, "Rise"); else if ( !strcmp(OEMString, "GenuineTMx86")) strcpy(Company, "Transmeta"); else if ( !strcmp(OEMString, "TransmetaCPU")) strcpy(Company, "Transmeta"); else if ( !strcmp(OEMString, "Geode By NSC")) strcpy(Company, "National Semiconductor"); cout<< "This CPU's OEM String is:"<< OEMString<< endl; cout<< "The cpu is product by "<<Company<<endl; _asm { mov eax,1 cpuid mov iEAXValue,eax mov iEBXValue,ebx mov iECXValue,ecx mov iEDXValue,edx } int iCPUType =(0x0000F000 & iEAXValue) >> 12; int iCPUFamily=(0x00000F00 & iEAXValue) >> 8; int iCPUModel =(0x000000F0 & iEAXValue) >> 4; int iCPUStep =(0x0000000F & iEAXValue); cout << "CPU Type is: " <<iCPUType <<endl; cout << "CPU Family is: " <<iCPUFamily <<endl; cout << "CPU Model is: " <<iCPUModel <<endl; cout << "CPU Stepping is: " <<iCPUStep <<endl; char Specification[49]; _asm { mov eax,0x80000002 cpuid mov DWORD PTR Specification, eax mov DWORD PTR Specification+4, ebx mov DWORD PTR Specification+8, ecx mov DWORD PTR Specification+12, edx } _asm { mov eax,0x80000003 cpuid mov DWORD PTR Specification+16, eax mov DWORD PTR Specification+20, ebx mov DWORD PTR Specification+24, ecx mov DWORD PTR Specification+28, edx } _asm { mov eax,0x80000004 cpuid mov DWORD PTR Specification+32, eax mov DWORD PTR Specification+36, ebx mov DWORD PTR Specification+40, ecx mov DWORD PTR Specification+44, edx } Specification[48]=0; cout << "CPU Specification is:" <<Specification <<endl; getchar(); return 0; }
我的运行结果:
This CPU's OEM String is:AuthenticAMD
The cpu is product by Advanced Micro Devices
CPU Type is:0
CPU Family is:6
CPU Model is:10
CPU Stepping is:0
CPU Specification is:AMD Athlon(tm) XP 3200+