[C++] HardwareID Protection
Hier ist eine HardwareID Protection die ich vor nen paar Wochen geschrieben hab, funktioniert gut, vielleicht ein bisschen Tuning für euch nötig.
Kommentierte lines mit */ müssen/können entfernt werden, und mit // kommentiert müssen/können geändert werden.
Code:
/*#include <vcl.h>
*/
#include <Windows.h>
//#include <hashlibpp.h>
char hwid[MAX_PATH] = ""; //this hwid will be generated
BOOL HWCheck();
BOOL HWInfos();
int main()
{
if(HWCheck() != 0)
{
return -1; //error, dont continue
}
return 0; //all is ok
}
BOOL HWCheck()
{
//const std::string hwhashcheck = "13a27d9e33b4a0d0e0fdd32d7f2775f3"; //customer hwid to check with hwid (current one)
if(HWInfos() != 0)
{
//couldnt get system-infos to generate hwinfo
MessageBox(NULL, "Couldn't get System-infos, exiting", "ERROR:", MB_OK | MB_ICONSTOP);
return -1;
}
/*
//MD5 the hwid
hashwrapper *md5 = new md5wrapper();
std::string hwhashid = md5->getHashFromString(hwid);
delete md5;
*/
//MessageBox(NULL, hwhashid.c_str(), "HardwareID:", MB_OK | MB_ICONINFORMATION);
//if(strcmp(hwhashid.c_str(),hwhashcheck.c_str()) != 0)
{
//hwinfo doesnt match
MessageBox(NULL, "Your current HW profile doesn't match with the owners", "ERROR:", MB_OK | MB_ICONSTOP);
return -1;
}
//hwinfo matches
MessageBox(NULL, "Authorized to continue program", "SUCCESS:", MB_OK | MB_ICONINFORMATION);
return 0; //all is ok
}
BOOL HWInfos()
{
//PRODUCT ID
char proid[MAX_PATH];
HKEY hKey;
DWORD nSize = sizeof(proid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
{
//couldnt open regkey
return -1;
}
if(RegQueryValueEx(hKey, "ProductId", NULL, NULL, (LPBYTE)proid,&nSize) != ERROR_SUCCESS)
{
//couldnt query regvalue
return -1;
}
strcat(hwid,proid); //add productid to hwid
RegCloseKey(hKey);
//BUILD LAB
char buildlab[MAX_PATH];
HKEY hKey2;
DWORD nSize2 = sizeof(proid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey2) != ERROR_SUCCESS)
{
//couldnt open regkey
return -1;
}
if(RegQueryValueEx(hKey2, "BuildLab", NULL, NULL, (LPBYTE)buildlab,&nSize2) != ERROR_SUCCESS)
{
//couldnt query regkey
return -1;
}
strcat(hwid,buildlab); //add build lab to hwid
RegCloseKey(hKey2);
//CPU INFO
int sum;
char cpuinfo[MAX_PATH];
SYSTEM_INFO temp;
GetSystemInfo(&temp );
sum = temp.dwProcessorType + temp.wProcessorLevel + temp.wProcessorRevision;
itoa(sum, cpuinfo, 10); //converts the ints to strings
strcat(hwid,cpuinfo); //add cpu info to hwid
//VOLUME SN
char rootdrive[MAX_PATH], vsnc[MAX_PATH];
DWORD vsn;
GetEnvironmentVariable("HOMEDRIVE",rootdrive,sizeof(rootdrive));
strcat(rootdrive,"\\");
if(GetVolumeInformation(rootdrive, 0, 0, &vsn, 0, 0, 0, 0) == 0)
{
//couldnt get volume serial number
return -1;
}
itoa(vsn, vsnc, 10); //converts the ints to strings
strcat(hwid,vsnc); //add volume serial number to hwid
//HW PROFILE
HINSTANCE DLL = LoadLibraryA("ADVAPI32.DLL");
if(!DLL)
{
//coudlnt load .dll
return -1;
}
typedef BOOL (WINAPI *GetHwProfileFn)(LPHW_PROFILE_INFOA);
if (GetHwProfileFn fn = (GetHwProfileFn)::GetProcAddress(DLL, "GetCurrentHwProfileA"))
{
HW_PROFILE_INFOA profile;
if ((fn)(&profile))
{
char dockinfo[MAX_PATH];
itoa(profile.dwDockInfo, dockinfo, 10); //converts the ints to strings
strcat(hwid,dockinfo);
strcat(hwid,profile.szHwProfileGuid);
strcat(hwid,profile.szHwProfileName);
FreeLibrary(DLL);
}
else
{
//error
FreeLibrary(DLL);
return -1;
}
}
else
{
//error while getting proc adress
FreeLibrary(DLL);
return -1;
}
return 0;
}