// Returns zero if no cpuid instruction; else returns 1 // Returns completed pmc_info struct on success static int cpu_id(struct pmc_info *info) { unsigned int version, features; char v[12]; // NOTE: Earlier versions of this routine checked for the existence of // the cpuid instruction before proceeding. // It's 2006. I think we can assume that any processor this is running on // is post-486 and will thus have the cpuid instruction. // Get the Vendor String, features, and family/model/stepping info struct cpuidVals vals; GetCPUID(0, &vals); *(unsigned long *)(&v[0]) = vals.b; *(unsigned long *)(&v[4]) = vals.d; *(unsigned long *)(&v[8]) = vals.c; GetCPUID(1, &vals); features = vals.d; version = vals.a; strncpy(info->vendor, v, 12); info->features = features; info->family = (version >> 8) & 0x0000000F; // bits 11 - 8 info->model = (version >> 4) & 0x0000000F; // Bits 7 - 4 info->stepping=(version) & 0x0000000F; // bits 3 - 0 return 1; }
DWORD GetProcessorFeatures(void) { DWORD dwProcessorFeatures = 0; DWORD ProcessorInfo[4]; GetCPUID(1, ProcessorInfo); dwProcessorFeatures ^= ProcessorInfo[0]; dwProcessorFeatures ^= ProcessorInfo[1]; dwProcessorFeatures ^= ProcessorInfo[2]; dwProcessorFeatures ^= ProcessorInfo[3]; #ifdef _CPUID_GET_EXTENDED_INFO GetCPUID(0x80000001, ProcessorInfo); dwProcessorFeatures ^= ProcessorInfo[2]; dwProcessorFeatures ^= ProcessorInfo[3]; #endif return dwProcessorFeatures; }
bool checkLicense() { CString strcpuid = GetCPUID(); unsigned char szMDTemp[16]; MD5_CTX Md5; Md5.MD5Update((unsigned char *)strcpuid.GetBuffer(),strcpuid.GetLength()); Md5.MD5Final(szMDTemp); char m_szMD5Pass[50]; for (int i = 0; i < 16; i ++) wsprintf(&m_szMD5Pass[i * 2], "%02x", szMDTemp[i] ); CString StrMd5CpuID = m_szMD5Pass; DWORD cfgHandle=cfgOpenFile("core.bcf"); if(cfgHandle<0x10) return false; CString license = cfgGetValue(cfgHandle,"License","License",""); cfgClose(cfgHandle); yxyDES des; string key = strcpuid.GetBuffer(); des.InitializeKey(key); des.DecryptAnyLength(license.GetBuffer()); string strtmp = des.GetPlaintextAnyLength(); string lsecpuid; string date; if (strtmp.length() == 40) { lsecpuid = strtmp.substr(0, 32); date = strtmp.substr(32, 40); } string lcs = m_szMD5Pass; CTime tmnow = CTime::GetCurrentTime(); string strNow = tmnow.Format("%Y%m%d").GetBuffer(); if (lcs == lsecpuid && strNow <= date) return true; else { CString s; s.Format("您的服务器未注册或已过期,请与服务商联系。\n\n请将以下机器码发送给服务商,获取注册码文件:\n\n%s\n\n",strcpuid.GetBuffer()); MessageBox(NULL, s,"提示",MB_ICONERROR); s="机器码已复制到您的剪贴板中,直接Ctrl+V粘贴机器码!"; MessageBox(NULL, s,"提示",MB_ICONINFORMATION); OpenClipboard(NULL); EmptyClipboard(); HANDLE hData=GlobalAlloc(GMEM_MOVEABLE, strcpuid.GetLength()+5); if (hData==NULL) { CloseClipboard(); return TRUE; } LPTSTR szMemName=(LPTSTR)GlobalLock(hData); lstrcpy(szMemName,strcpuid); SetClipboardData(CF_TEXT,hData); GlobalUnlock(hData); GlobalFree(hData); CloseClipboard(); return false; } }
bool CMachineID::Init() { GetCPUID(); GetDiskID(); return true; }