zoukankan      html  css  js  c++  java
  • 加密授权验证学习之一 ——获取计算机CPUID序列号

    最近项目中需要对CPUID、硬盘序列号、网卡物理地址进行加密授权验证,网上这方面的资料代码很多,但很多都有错或者不能正确获取,通过整理与学习,将自己已经正确获得的代码分享出来吧。

    code:

    #include <iostream>
    #include <string>
    #include <windows.h>
    
    using namespace std;
    
    string GetCPUID()
    {
    	std::string strCPUId;
    	unsigned long s1, s2;
    	char buf[32] = { 0 };
    	__asm{
    		mov eax, 01h   //eax=1:取CPU序列号
    			xor edx, edx
    			cpuid
    			mov s1, edx
    			mov s2, eax
    	}
    	if (s1) {
    		memset(buf, 0, 32);
    		sprintf_s(buf, 32, "%08X", s1);
    		strCPUId += buf;
    	}
    	if (s2) {
    		memset(buf, 0, 32);
    		sprintf_s(buf, 32, "%08X", s2);
    		strCPUId += buf;
    	}
    	__asm{
    		mov eax, 03h
    			xor ecx, ecx
    			xor edx, edx
    			cpuid
    			mov s1, edx
    			mov s2, ecx
    	}
    	if (s1) {
    		memset(buf, 0, 32);
    		sprintf_s(buf, 32, "%08X", s1);
    		strCPUId += buf;
    	}
    	if (s2) {
    		memset(buf, 0, 32);
    		sprintf_s(buf, 32, "%08X", s2);
    		strCPUId += buf;
    	}
    	return strCPUId;
    }
    
    int main()
    {
    	cout << "CPUID:" << GetCPUID() << endl;
    	getchar();
    	return 0;
    }
    
    

    为了验证获取结果和计算机的是不是一致,可以通过计算机的命令提示符进行查看。

    在搜索框内输入cmd,然后输入命令 wmic cpu get ProcessorID 来查看ID信息。

    https://blog.csdn.net/zkz10086/article/details/81505254?utm_medium=distribute.pc_relevant.none-task-blog-title-3&spm=1001.2101.3001.4242

  • 相关阅读:
    Android将ScrollView移动到最底部
    Android权限之sharedUserId和签名
    python接口使用及工具函数
    python模块(json、os、sys、random、string、time、hashlib)
    python内置函数
    python模块、函数变量及递归
    python数据类型集合及函数
    python文件操作及修改
    python字符类型操作及文件操作
    jmeter压测
  • 原文地址:https://www.cnblogs.com/xihong2014/p/13693673.html
Copyright © 2011-2022 走看看