#include <Nb30.h> #pragma comment(lib, "ws2_32.lib ") #pragma comment(lib, "netapi32.lib ") DLL_API int __cdecl getMAC(char * mac) { NCB ncb; typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff [30]; }ASTAT, *PASTAT; ASTAT Adapter; typedef struct _LANA_ENUM { UCHAR length; UCHAR lana[MAX_LANA]; }LANA_ENUM; LANA_ENUM lana_enum; UCHAR uRetCode; memset(&ncb, 0, sizeof(ncb)); memset(&lana_enum, 0, sizeof(lana_enum)); ncb.ncb_command = NCBENUM; ncb.ncb_buffer = (unsigned char *)&lana_enum; ncb.ncb_length = sizeof(LANA_ENUM); uRetCode = Netbios(&ncb); if(uRetCode != NRC_GOODRET) return uRetCode; for(int lana=0; lana <lana_enum.length; lana++) { ncb.ncb_command = NCBRESET; ncb.ncb_lana_num = lana_enum.lana[lana]; uRetCode = Netbios(&ncb); if(uRetCode == NRC_GOODRET) break; } if(uRetCode != NRC_GOODRET) return uRetCode; memset(&ncb, 0, sizeof(ncb)); ncb.ncb_command = NCBASTAT; ncb.ncb_lana_num = lana_enum.lana[0]; strcpy((char*)ncb.ncb_callname, "* "); ncb.ncb_buffer = (unsigned char *)&Adapter; ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios(&ncb); if(uRetCode != NRC_GOODRET) return uRetCode; sprintf(mac, "%02X%02X%02X%02X%02X%02X", Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); return 0; } DLL_API int __cdecl CheckKey(char *key) { if(key == NULL) { return -1; } char mac[200]; mac[0] = '/0'; if(GetPCCode(mac) != 0) { return -1; } //获取Key int lenth = strlen(mac); int nKey = 1; int i = 0; for(i = 0; i < lenth; i++) { nKey += (mac[i]^0xa9)*(i+1)*256; } char key2[255]; sprintf(key2, "%x", nKey);// return strcmp(key, key2); } DLL_API int __cdecl GetPCCode(char *code) { if(code == NULL) { return -1; } char mac[200]; mac[0] = '/0'; if(getMAC(mac) != 0) { return -1; } DWORD VolumeSerialNumber; GetVolumeInformation("c://",NULL,12,&VolumeSerialNumber,NULL,NULL,NULL,10); VolumeSerialNumber^=0x12345678; VolumeSerialNumber += 397; char pNum[10]; itoa(VolumeSerialNumber,pNum,16); strcat(mac, pNum); strcpy(code, mac); int lenth = strlen(mac); return 0; }
获取机器码 及 检测注册码是否有效
CString cstrMac; GetDlgItemText(IDC_EDIT1, cstrMac); cstrMac.TrimLeft(); cstrMac.TrimRight(); if(cstrMac.GetLength() == 0) { return; } //获取Key int nKey = 1; int i = 0; for(i = 0; i < cstrMac.GetLength(); i++) { nKey += (cstrMac.GetAt(i)^0xa9)*(i+1)*256; } char key[255]; sprintf(key, "%x", nKey);// this->SetDlgItemText(IDC_EDIT2, key);
根据机器码计算注册码(注册机)