分享C++获取机器码源代码 支持win10最新
分享C++获取机器码源代码 支持win10最新
bool getDevcieInfo(char* cmd, list<string> &resultList)
{
char buffer;
bool ret = false;
FILE* pipe = _popen(cmd, "r"); //打开管道,并执行命令
if (!pipe)
return ret;
char *name = { "UUID", "ProcessorId", "SerialNumber" };
int len0 = strlen(name), len1 = strlen(name), len2 = strlen(name);
bool isOk = false;
while (!feof(pipe)) {
if (fgets(buffer, BUFFER_SIZE, pipe)) {
if (strncmp(name, buffer, len0) == 0
|| strncmp(name, buffer, len1) == 0
|| strncmp(name, buffer, len2) == 0) // 能够正确获取信息
{
isOk = true;
continue;
}
if (isOk == false
|| strcmp("\r\n", buffer) == 0) //去掉windows无用的空行
{
continue;
}
ret = true;
resultList.push_back(string(buffer));
}
}
_pclose(pipe); // 关闭管道
return ret;
}
string getDeviceFingerPrint()
{
list<string> strList;
list<string>::iterator it;
hash<string> str_hash;
size_t num;
char tmp = { 0 };
if (getDevcieInfo("wmic csproduct get UUID", strList)) {
num = str_hash(*strList.begin());
sprintf(tmp, "%u", num);
return string(tmp);
}
string otherStr("");
strList.clear();
if (getDevcieInfo("wmic cpu get processorid", strList)) {
otherStr.append(*strList.begin());
}
strList.clear();
if (getDevcieInfo("wmic bios get serialnumber", strList)) {
otherStr.append(*strList.begin());
}
strList.clear();
if (getDevcieInfo("wmic diskdrive get serialnumber", strList)) {
string allDiskNum("");
for (it = strList.begin(); it != strList.end(); it++) {
allDiskNum.append(*it);
}
otherStr.append(*strList.begin());
}
cout << str_hash(otherStr) << endl;
num = str_hash(otherStr);
sprintf(tmp, "%u", num);
return string(tmp);
}
页:
[1]