//--------------------------------------------------------------------------- #pragma hdrstop #include "WebActivationLibrary.h" // tab file used for Seedx library #include "seedx.h" #include "seedx.tab" //--------------------------------------------------------------------------- #pragma package(smart_init) // functions to get MAC address //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Prints the MAC address stored in a 6 byte array to stdout void PrintMACaddress(char* dest, unsigned char MACData[]) { char buffer[13]; sprintf(dest, "%02X%02X%02X%02X%02X%02X", MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]); } //--------------------------------------------------------------------------- // Fetches the MAC address and prints it String GetMACaddress() { char dest[16]; String out; IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs DWORD dwBufLen = sizeof(AdapterInfo); // Save the memory size of buffer DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo AdapterInfo, // [out] buffer to receive data &dwBufLen); // [in] size of receive data buffer if (dwStatus != ERROR_SUCCESS) { // If Failure to Get Adapter Info, EnableNetworkAdapter(); // Check Network Adapter DWORD dwStatus = GetAdaptersInfo( // & Try to Call GetAdapterInfo AGAIN AdapterInfo, &dwBufLen); if (dwStatus != ERROR_SUCCESS) { out = _T("000000000000"); return out; // If Fail, return NULL } } PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info do { PrintMACaddress(dest, pAdapterInfo->Address); // Print MAC address if(strcmp(dest, "000000000000")) break;//if connected device pAdapterInfo = pAdapterInfo->Next; // Progress through linked list } while(pAdapterInfo); // Terminate if last adapter out = dest; return out; } //--------------------------------------------------------------------------- // MAC address¸¦ ¾ò±â À§ÇØ ³×Æ®¿öÅ© ¾î´ðÅ͸¦ ÄÒ´Ù. //(»ç¿ë ¾ÈÇÔ »óÅÂÀÏ ¶§) int EnableNetworkAdapter(void) { bool status = false; //true:success, false:fail CoInitialize(0); INetConnectionManager *pMan = 0; HRESULT hres = CoCreateInstance(CLSID_ConnectionManager, 0, CLSCTX_ALL, __uuidof(INetConnectionManager), (void**)&pMan); if (SUCCEEDED(hres)) { IEnumNetConnection *pEnum = 0; hres = pMan->EnumConnections(NCME_DEFAULT, &pEnum); if (SUCCEEDED(hres)) { INetConnection *pCon = 0; ULONG count; while (pEnum->Next(1, &pCon, &count) == S_OK) { NETCON_PROPERTIES *pProps = 0; hres = pCon->GetProperties(&pProps); if (SUCCEEDED(hres)) { if (pProps->Status == NCS_CONNECTED) status = true; else if (pProps->Status == NCS_DISCONNECTED){ pCon->Connect(); if (pProps->Status == NCS_CONNECTED) status = true; } if (pProps) { CoTaskMemFree(pProps->pszwName); CoTaskMemFree(pProps->pszwDeviceName); CoTaskMemFree(pProps); } } pCon->Release(); } pEnum->Release(); } pMan->Release(); } CoUninitialize(); return status; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // functions that check the informations from the server //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- int checkRemainTime(TComponent* AOwner , String MAC) { // server·ÎºÎÅÍ RemainTimeÀ» ¹Þ¾Æ ÃÊ ½Ã°£À¸·Î return // (MACaddress, Program&Version Á¤º¸¸¦ ±â¹ÝÀ¸·Î À¥¿¡¼­ ó¸®) TIdHTTP *IdHTTP = new TIdHTTP(AOwner); TIdMultiPartFormDataStream* pData = NULL; String response; pData = new TIdMultiPartFormDataStream(); pData->AddFormField("hddserial", MAC); pData->AddFormField("program", PRG_VSN); response = IdHTTP->Post(ADDRESS_CHECK, pData); delete pData; pData = NULL; delete IdHTTP; int value = 0; if (TryStrToInt(response, value)) { return value; } else return -100; } //--------------------------------------------------------------------------- int checkRemainTime(TApplication *App) // overloading { TApplication *Application; Application = App; String MACaddress = GetMACaddress(); return checkRemainTime(Application, MACaddress); } //--------------------------------------------------------------------------- bool __fastcall checkInetConnect() { EnableNetworkAdapter(); // Internet¿¡ ¿¬°á µÇ¾î ÀÖ´ÂÁö È®ÀÎ HINTERNET lhInet = NULL, lhUrl = NULL; String psURL = YWURL; try { lhInet = InternetOpen(_T("CheckInet function"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (lhInet) { lhUrl = InternetOpenUrl(lhInet, PChar(psURL.c_str()), NULL, 0, INTERNET_FLAG_RELOAD, 0); if (!lhUrl) throw -1; if (lhUrl) InternetCloseHandle(lhUrl); lhUrl = NULL; if (lhInet) InternetCloseHandle(lhInet); lhInet = NULL; } else throw -1; } catch(...) { if (lhUrl) InternetCloseHandle(lhUrl); if (lhInet) InternetCloseHandle(lhInet); return false; } return true; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // functions that can hash the key //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- AnsiString keyHash(AnsiString key) { // verifying key information if(key.Length() != 27) return "INVALID"; if(key[11] != '-' || key[22] != '-') return "INVALID"; // remove useless '-' character from the key AnsiString tkey = key.SubString(1, 10) + key.SubString(12, 10) + key.SubString(23, 5); // descrypt and arrange string tkey = descryptStr(tkey); tkey = arrangeStr(tkey, 5); return tkey; } //--------------------------------------------------------------------------- AnsiString arrangeStr(AnsiString source, int num) { AnsiString* parts; AnsiString result; // get the number of the parts int partnum = source.Length() / num; parts = new AnsiString[partnum]; // get parts for(int i=0; i0; i--) result += source[i]; return result; } //--------------------------------------------------------------------------- AnsiString descryptStr(AnsiString source) { AnsiString result = source.UpperCase(); // replace the charater with the hashed characted for(int i=0; i