//--------------------------------------------------------------------------- #pragma hdrstop #include "TexLock.h" //--------------------------------------------------------------------------- #ifdef LOCK_TEX //--------------------------------------------------------------------------- #include "SeedX.h" #include "CRC.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- char *pMessage01, *pMessage02, *pMessage03, *pMessage04, *pMessage05, *pMessage06, *pMessage07, *pMessage08, *pMessage09; // ¸Þ½ÃÁö¸¦ º¹È£È­Çؼ­ ´ãÀ» Àü¿ª º¯¼ö //--------------------------------------------------------------------------- // ½ÇÇà ÁßÀÎ ÇÁ·Î¼¼½ºÀÇ ¸ñ·ÏÀ» ¾ò¾î¿Â´Ù // ½ÇÇà ÁßÀÎ ÇÁ·Î¼¼½ºÀÇ ¸ñ·ÏÀ» ¾ò¾î¿Â´Ù bool CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lpParam) { HANDLE hSnapshot = NULL; HANDLE hProcess = NULL; PROCESSENTRY32 pe32; bool bContinue = false; DWORD dwPID; Char *WindowTitle = NULL; Char *WindowClass = NULL; String strWindowTitle; //String strWindowClass; TStringList *TitleList = NULL; // ½ÇÇà ÁßÀÎ ÇÁ·Î¼¼½ºÀÇ ¸ñ·Ï°ú ºñ±³¸¦ À§ÇÑ Àü¿ª º¯¼ö String strStatusFilePath, strLockFilePath; bool bFind; if (hWnd && IsWindowVisible(hWnd) && ((GetWindowLong(hWnd, GWL_HWNDPARENT) == 0) || (HWND(GetWindowLong(hWnd, GWL_HWNDPARENT)) == GetDesktopWindow)) && (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == 0) { WindowTitle = new Char[256]; //WindowClass = new char[256]; GetWindowText(hWnd, WindowTitle, 255); // ÇÁ·Î¼¼½ºÀÇ Ä¸¼ÇÀ» ¾ò¾î¿Â´Ù //GetClassName(hWnd, WindowClass, 255); // ÇÁ·Î¼¼½ºÀÇ Å¬·¡½º¸íÀ» ¾ò¾î¿Â´Ù strWindowTitle = WindowTitle; //strWindowClass = String(WindowClass); strWindowTitle = strWindowTitle.UpperCase(); //strWindowClass = strWindowClass.UpperCase(); bFind = false; TitleList = (TStringList *)lpParam; for (int i = 0; i < TitleList->Count; i++) { if (strWindowTitle.Pos(TitleList->Strings[i].UpperCase()) > 0) { bFind = true; break; } } if (WindowTitle) { delete []WindowTitle; WindowTitle = NULL; } if (WindowClass) { delete []WindowClass; WindowClass = NULL; } if (bFind) { // ÀÔ·ÂµÈ °ª°ú Çϳª¶óµµ °°À¸¸é Á¾·á GetWindowThreadProcessId(hWnd, &dwPID); // ÇÁ·Î¼¼½º ID¸¦ ¾ò¾î¿À¸ç pe32.dwSize = sizeof(PROCESSENTRY32); hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); bContinue = Process32First(hSnapshot, &pe32); while (bContinue) { if (pe32.th32ProcessID == dwPID) { // µ¿ÀÏÇÑ ÇÁ·Î¼¼½ºÀÇ ÇÚµéÀ» ¾ò±âÀ§ÇÑ ÀÛ¾÷ÀÌ´Ù //hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pe32.th32ProcessID); hProcess = OpenProcess(PROCESS_TERMINATE, false, pe32.th32ProcessID); if (hProcess) { // ¸Þ½ÃÁö ¹Ú½º¸¦ È£ÃâÇÏÁö ¾Êµµ·Ï ÇÑ´Ù (¸Þ½ÃÁö ¹Ú½º°¡ ¶° ÀÖ´Â µ¿¾È µð¹ö±×ÇÒ ¼ö Àֱ⠶§¹®) //Application->MessageBox(pMessage06, pMessage01, MB_ICONSTOP); TerminateProcess(hProcess, 0); // ÇÁ·Î¼¼½ºÀÇ ÇÚµéÀ» ÀÌ¿ëÇÑ ÇÁ·Î¼¼½º Á¾·á CloseHandle(hProcess); #ifdef LOCK_HASP // for Client strStatusFilePath = ExtractFilePath(Application->ExeName) + "Status.dat"; SaveToStatusFile(strStatusFilePath, TEXLOCK_MESSAGE01); // ÇØÅ· ÄÚµå ±â·Ï strLockFilePath = ExtractFilePath(Application->ExeName) + "YoungWooCnI.DLL"; DeleteFile(strLockFilePath.c_str()); // ÆÄÀÏ»èÁ¦ #endif Application->Terminate(); Application->ProcessMessages(); \ } break; } bContinue = Process32Next(hSnapshot, &pe32); } if (hSnapshot) { CloseHandle(hSnapshot); } } } return true; } //--------------------------------------------------------------------------- char __fastcall LoadFromStatusFile(String strFilePath) { HANDLE hFile = NULL; DWORD dwRead; int nStatusLen = 0, nRandom = 0, nVersion = 0; char cReturn = -1; char pData[MAX_PATH]; // ³Ë³ËÇÏ°Ô Àâ´Â´Ù MAX_PATH = 250 memset(pData, 0, sizeof(char)*MAX_PATH); if (FileExists(strFilePath)) { if ((hFile = CreateFile(strFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_FLAG_WRITE_THROUGH, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (!ReadFile(hFile, &nVersion, sizeof(int), &dwRead, NULL)) goto fail; if (nVersion == 100) { if (!ReadFile(hFile, &nStatusLen, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(hFile, pData, sizeof(char)*nStatusLen, &dwRead, NULL)) goto fail; } if (hFile) { CloseHandle(hFile); hFile = NULL; } } randomize(); nRandom = random(99); if (nStatusLen < 34) { // Modified Status.dat (Status.dat ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 2 : 8; } else if (memcmp(pData, TEXLOCK_MESSAGE09, nStatusLen) == 0) { // Modified Status.dat (Status.dat ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 2 : 8; } else if (memcmp(pData, TEXLOCK_MESSAGE01, nStatusLen) == 0) { // Debug Detect!! (¸®¹ö½º ¿£Áö´Ï¾î¸µ ÅøÀÌ ¹ß°ßµÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 1 : 9; } else if (memcmp(pData, TEXLOCK_MESSAGE04, nStatusLen) == 0) { // Congratulations!! (ÀÎÁõ ¼º°ø »óÅÂ) cReturn = nRandom % 2 == 0 ? 4 : 6; } else if (memcmp(pData, TEXLOCK_MESSAGE07, nStatusLen) == 0) { // Install Complete!! (¼³Ä¡ ¿Ï·áµÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 7 : 3; } else if (memcmp(pData, TEXLOCK_MESSAGE08, nStatusLen) == 0) { // Modified YoungWooCnI.DLL (YoungWooCnI.DLL ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 0 : 5; } else { // Modified Status.dat (Status.dat ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) cReturn = nRandom % 2 == 0 ? 2 : 8; } return cReturn; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } return cReturn; } //--------------------------------------------------------------------------- bool __fastcall SaveToStatusFile(String strFilePath, String strStatus) { HANDLE hFile = NULL; DWORD dwWrite; int nStatusLen, nRandom, nVersion = 100; char cReturn = -1; char pData[MAX_PATH]; // ³Ë³ËÇÏ°Ô Àâ´Â´Ù MAX_PATH = 250 String strData; memset(pData, 0, sizeof(char)*MAX_PATH); if ((hFile = CreateFile(strFilePath.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (!WriteFile(hFile, &nVersion, sizeof(int), &dwWrite, NULL)) goto fail; // Version == 100 nStatusLen = strStatus.Length(); if (!WriteFile(hFile, &nStatusLen, sizeof(int), &dwWrite, NULL)) goto fail; for (int i = 0; i < strStatus.Length(); i++) { pData[i] = strStatus.c_str()[i]; } if (!WriteFile(hFile, pData, sizeof(char)*nStatusLen, &dwWrite, NULL)) goto fail; if (hFile) { CloseHandle(hFile); hFile = NULL; } return true; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } return false; } //--------------------------------------------------------------------------- #if !(defined(LOCK_CRYPKEY) || defined(LOCK_HASP) || defined(LOCK_IFC)) // for Server __fastcall TTexLock::TTexLock(String strKeyFilePath) { FileVersion = 100; KeyFilePath = strKeyFilePath; CheckReverseEngineeringTools(); } //--------------------------------------------------------------------------- __fastcall TTexLock::~TTexLock() { } //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- #ifdef LOCK_HASP // for Client __fastcall TTexLock::TTexLock(TApplication *App, String strPath, unsigned int nDoubleLock) { HANDLE hFile = NULL; String strLockFileName; WIN32_FIND_DATA FileData; BYTE *pMessage = NULL; DWORD dwMessageSize; unsigned short nIVKeyIndex; int nEncodeSize; BYTE IVKey[32] = {'e', 'o', 'g', 'k', 's', 'a', 'l', 's', 'r', 'n', 'r' , 'd', 'u', 'd', 'd', 'n', 'T', 'l', 'd', 'p', 's', 'd', 'k', 'd', 'l' , 'r', 'o', 'q', 'k', 'f', 'q', 'n'}; DWORD pRoundKey[32]; Application = App; pAuthorizationKey = NULL; pVerificationKey = NULL; dwAuthorizationKeySize = 0; dwVerificationKeySize = 0; KeyVersion = 1; FileVersion = 100; StatusFilePath = ExtractFilePath(strPath) + "Status.dat"; KeyFilePath = ExtractFilePath(strPath) + "Key.dat"; FullPath = strPath; DoubleLock = nDoubleLock; SeedEncRoundKey(pRoundKey, IVKey); /* // ¸Þ½ÃÁö ¸¸µé±â String msg = "Debugger Detect!!"; BYTE *pResult; pResult = new BYTE[msg.Length()]; for (int i = 0; i < msg.Length(); i++) pResult[i] = msg.c_str()[i]; SeedEncrypt(pResult, pRoundKey); msg = CodeToBitShiftString(4, pResult, msg.Length(), false); */ dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE01, &pMessage); pMessage01 = new BYTE[dwMessageSize+1]; memcpy(pMessage01, pMessage, dwMessageSize); SeedDecrypt(pMessage01, pRoundKey); pMessage01[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE02, &pMessage); pMessage02 = new BYTE[dwMessageSize+1]; memcpy(pMessage02, pMessage, dwMessageSize); SeedDecrypt(pMessage02, pRoundKey); pMessage02[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE03, &pMessage); pMessage03 = new BYTE[dwMessageSize+1]; memcpy(pMessage03, pMessage, dwMessageSize); SeedDecrypt(pMessage03, pRoundKey); pMessage03[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE04, &pMessage); pMessage04 = new BYTE[dwMessageSize+1]; memcpy(pMessage04, pMessage, dwMessageSize); SeedDecrypt(pMessage04, pRoundKey); pMessage04[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE05, &pMessage); pMessage05 = new BYTE[dwMessageSize+1]; memcpy(pMessage05, pMessage, dwMessageSize); SeedDecrypt(pMessage05, pRoundKey); pMessage05[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE06, &pMessage); pMessage06 = new BYTE[dwMessageSize+1]; memcpy(pMessage06, pMessage, dwMessageSize); SeedDecrypt(pMessage06, pRoundKey); pMessage06[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE07, &pMessage); pMessage07 = new BYTE[dwMessageSize+1]; memcpy(pMessage07, pMessage, dwMessageSize); SeedDecrypt(pMessage07, pRoundKey); pMessage07[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE08, &pMessage); pMessage08 = new BYTE[dwMessageSize+1]; memcpy(pMessage08, pMessage, dwMessageSize); SeedDecrypt(pMessage08, pRoundKey); pMessage08[dwMessageSize] = '\0'; dwMessageSize = BitShiftStringToCode(4, TEXLOCK_MESSAGE09, &pMessage); pMessage09 = new BYTE[dwMessageSize+1]; memcpy(pMessage09, pMessage, dwMessageSize); SeedDecrypt(pMessage09, pRoundKey); pMessage09[dwMessageSize] = '\0'; if (pMessage) { delete []pMessage; pMessage = NULL; } strLockFileName = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; if (FileExists(strLockFileName) == false) { hFile = CreateFile(strLockFileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_HIDDEN, NULL); GetFileTime(hFile, &CreateTime, &AccessTime, &WriteTime); if (hFile) { CloseHandle(hFile); hFile = NULL; } } else { hFile = FindFirstFile(strLockFileName.c_str(), &FileData); CreateTime = FileData.ftCreationTime; AccessTime = FileData.ftLastAccessTime; WriteTime = FileData.ftLastWriteTime; FindClose(hFile); } // Reverse Engineering ToolÀÌ °¨ÁöµÇ¸é ÇÁ·Î±×·¥ Á¾·á CheckReverseEngineeringTools(); } //--------------------------------------------------------------------------- __fastcall TTexLock::~TTexLock() { HANDLE hFile = NULL; String strLockFilePath; if (pMessage01) { delete []pMessage01; pMessage01 = NULL; } if (pMessage02) { delete []pMessage02; pMessage02 = NULL; } if (pMessage03) { delete []pMessage03; pMessage03 = NULL; } if (pMessage04) { delete []pMessage04; pMessage04 = NULL; } if (pMessage05) { delete []pMessage05; pMessage05 = NULL; } if (pMessage06) { delete []pMessage06; pMessage06 = NULL; } if (pMessage07) { delete []pMessage07; pMessage07 = NULL; } if (pMessage08) { delete []pMessage08; pMessage08 = NULL; } if (pMessage09) { delete []pMessage09; pMessage09 = NULL; } if (pAuthorizationKey) { delete []pAuthorizationKey; pAuthorizationKey = NULL; } if (pVerificationKey) { delete []pVerificationKey; pVerificationKey = NULL; } strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; if (FileExists(strLockFilePath)) { hFile = CreateFile(strLockFilePath.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN, NULL); SetFileTime(hFile, &CreateTime, &AccessTime, &WriteTime); if (hFile) { CloseHandle(hFile); hFile = NULL; } } } //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- void __fastcall TTexLock::KillReverseEngineeringTool(TStringList *strExcutionNameList) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); HANDLE hProcess = NULL; PROCESSENTRY32 pe32; bool bContinue = false; char WindowsCaption[255]; String strWindowsCaption; int nIndex = 0; String strLockFilePath; pe32.dwSize = sizeof(PROCESSENTRY32); // ÇÁ·Î±×·¥ÀÇ À̸§°ú °°À» °æ¿ì Á¾·á if (strExcutionNameList) { bContinue = Process32First(hSnapshot, &pe32); while (bContinue) { strWindowsCaption = pe32.szExeFile; strWindowsCaption = strWindowsCaption.UpperCase(); nIndex = -1; for (int i = 0; i < strExcutionNameList->Count; i++) { if (strWindowsCaption.Pos(strExcutionNameList->Strings[i].UpperCase()) > 0) { nIndex = i; break; } } if (nIndex >= 0) { // PROCESS_ALL_ACCESS ´ë½Å¿¡ PROCESS_TERMINATE¸¦ ÀÌ¿ëÇØ¾ß Á¤»óÀûÀ¸·Î Á¾·á½Ãų ¼ö ÀÖ´Ù hProcess = OpenProcess(PROCESS_TERMINATE, false, pe32.th32ProcessID); if (hProcess) { TerminateProcess(hProcess, 0); // ÇÁ·Î¼¼½ºÀÇ ÇÚµéÀ» ÀÌ¿ëÇÑ ÇÁ·Î¼¼½º Á¾·á CloseHandle(hProcess); #ifdef LOCK_HASP // for Client SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE01); // ÇØÅ· ÄÚµå ±â·Ï strLockFilePath = ExtractFilePath(Application->ExeName) + "YoungWooCnI.DLL"; DeleteFile(strLockFilePath.c_str()); // ÆÄÀÏ»èÁ¦ #endif Application->Terminate(); Application->ProcessMessages(); \ } break; } bContinue = Process32Next(hSnapshot, &pe32); } if (hSnapshot) { CloseHandle(hSnapshot); hSnapshot= NULL; } } } //--------------------------------------------------------------------------- void __fastcall KillReverseEngineeringTool(TStringList *strExcutionNameList) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); HANDLE hProcess = NULL; PROCESSENTRY32 pe32; bool bContinue = false; char WindowsCaption[255]; String strWindowsCaption; int nIndex = 0; String strLockFilePath; pe32.dwSize = sizeof(PROCESSENTRY32); // ÇÁ·Î±×·¥ÀÇ À̸§°ú °°À» °æ¿ì Á¾·á if (strExcutionNameList) { bContinue = Process32First(hSnapshot, &pe32); while (bContinue) { strWindowsCaption = pe32.szExeFile; strWindowsCaption = strWindowsCaption.UpperCase(); nIndex = -1; for (int i = 0; i < strExcutionNameList->Count; i++) { if (strWindowsCaption.Pos(strExcutionNameList->Strings[i].UpperCase()) > 0) { nIndex = i; break; } } if (nIndex >= 0) { hProcess = OpenProcess(PROCESS_TERMINATE, false, pe32.th32ProcessID); if (hProcess) { TerminateProcess(hProcess, 0); // ÇÁ·Î¼¼½ºÀÇ ÇÚµéÀ» ÀÌ¿ëÇÑ ÇÁ·Î¼¼½º Á¾·á CloseHandle(hProcess); #ifdef LOCK_HASP // for Client String strStatusFilePath = ExtractFilePath(Application->ExeName) + "Status.dat"; SaveToStatusFile(strStatusFilePath, TEXLOCK_MESSAGE01); // ÇØÅ· ÄÚµå ±â·Ï strLockFilePath = ExtractFilePath(Application->ExeName) + "YoungWooCnI.DLL"; DeleteFile(strLockFilePath.c_str()); // ÆÄÀÏ»èÁ¦ #endif Application->Terminate(); Application->ProcessMessages(); \ } break; } bContinue = Process32Next(hSnapshot, &pe32); } if (hSnapshot) { CloseHandle(hSnapshot); hSnapshot= NULL; } } } //--------------------------------------------------------------------------- int __fastcall TTexLock::LoadFromKeyFile(unsigned short nIVKeyIndex, BYTE *pIVKey) { HANDLE hFile = NULL; DWORD dwRead; int nVersion = 0; // IVKey if ((hFile = CreateFile(KeyFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_FLAG_WRITE_THROUGH, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } // Version Check if (!ReadFile(hFile, &nVersion, sizeof(int), &dwRead, NULL)) goto fail; if (FileVersion == nVersion) { if (SetFilePointer(hFile, nIVKeyIndex+sizeof(int), NULL, FILE_BEGIN)== 0xFFFFFFFF) goto fail; if (!ReadFile(hFile, pIVKey, sizeof(BYTE)*SeedBlockSize, &dwRead, NULL)) goto fail; // IVKey } if (hFile) { CloseHandle(hFile); hFile = NULL; } return 0; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } return nVersion; } //--------------------------------------------------------------------------- int __fastcall LoadFromKeyFile(int FileVersion, String KeyFilePath, unsigned short nIVKeyIndex, BYTE *pIVKey) { HANDLE hFile = NULL; DWORD dwRead; int nVersion = 0; // IVKey if ((hFile = CreateFile(KeyFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_FLAG_WRITE_THROUGH, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } // Version Check if (!ReadFile(hFile, &nVersion, sizeof(int), &dwRead, NULL)) goto fail; if (FileVersion == nVersion) { if (SetFilePointer(hFile, nIVKeyIndex+sizeof(int), NULL, FILE_BEGIN)== 0xFFFFFFFF) goto fail; if (!ReadFile(hFile, pIVKey, sizeof(BYTE)*SeedBlockSize, &dwRead, NULL)) goto fail; // IVKey } if (hFile) { CloseHandle(hFile); hFile = NULL; } return 0; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } return nVersion; } //--------------------------------------------------------------------------- int __fastcall TTexLock::Decrypt(BYTE **pCode, int nLen, unsigned short nIVKeyIndex) { BYTE *pResult = NULL; BYTE IVKey[SeedBlockSize]; DWORD pRoundKey[32]; if (LoadFromKeyFile(nIVKeyIndex, IVKey) != 0) { return -1; } pResult = new BYTE[nLen]; memset(pResult, 0, sizeof(BYTE)*nLen); memcpy(pResult, *pCode, sizeof(BYTE)*nLen); if (*pCode) delete [](*pCode); SeedEncRoundKey(pRoundKey, IVKey); SeedDecrypt(pResult, pRoundKey); *pCode = pResult; return nLen; } //--------------------------------------------------------------------------- int __fastcall Decrypt(int FileVersion, String KeyFilePath, BYTE **pCode, int nLen, unsigned short nIVKeyIndex) { BYTE *pResult = NULL; BYTE IVKey[SeedBlockSize]; DWORD pRoundKey[32]; if (LoadFromKeyFile(FileVersion, KeyFilePath, nIVKeyIndex, IVKey) != 0) { return -1; } pResult = new BYTE[nLen]; memset(pResult, 0, sizeof(BYTE)*nLen); memcpy(pResult, *pCode, sizeof(BYTE)*nLen); if (*pCode) delete [](*pCode); SeedEncRoundKey(pRoundKey, IVKey); SeedDecrypt(pResult, pRoundKey); *pCode = pResult; return nLen; } //--------------------------------------------------------------------------- int __fastcall TTexLock::CharNumToIntNum(char cNumber) { int nNumber = 0; if ('A' <= cNumber && cNumber <= 'Z') { nNumber = cNumber - 'A' + 0x0A; } else if ('a' <= cNumber && cNumber <= 'z') { nNumber = cNumber - 'a' + 0x0A; } else if ('0' <= cNumber && cNumber <= '9') { nNumber = cNumber - '0'; } return nNumber; } //--------------------------------------------------------------------------- int __fastcall CharNumToIntNum(char cNumber) { int nNumber = 0; if ('A' <= cNumber && cNumber <= 'Z') { nNumber = cNumber - 'A' + 0x0A; } else if ('a' <= cNumber && cNumber <= 'z') { nNumber = cNumber - 'a' + 0x0A; } else if ('0' <= cNumber && cNumber <= '9') { nNumber = cNumber - '0'; } return nNumber; } //--------------------------------------------------------------------------- String __fastcall TTexLock::CodeToString(BYTE *pCode, int nLength, bool bSpace) { String strKeyCode = ""; for (int i = 0; i < nLength; i++) { if (bSpace && (i != 0) && (i % 4 == 0)) strKeyCode += " "; if (0x00 <= pCode[i] && pCode[i] <= 0x09) strKeyCode += char(pCode[i] + '0'); else if (0x0A <= pCode[i] && pCode[i] <= 0x0F) strKeyCode += char(pCode[i] - 0x0A + 'A'); } return strKeyCode; } //--------------------------------------------------------------------------- String __fastcall CodeToString(BYTE *pCode, int nLength, bool bSpace) { String strKeyCode = ""; for (int i = 0; i < nLength; i++) { if (bSpace && (i != 0) && (i % 4 == 0)) strKeyCode += " "; if (0x00 <= pCode[i] && pCode[i] <= 0x09) strKeyCode += char(pCode[i] + '0'); else if (0x0A <= pCode[i] && pCode[i] <= 0x0F) strKeyCode += char(pCode[i] - 0x0A + 'A'); } return strKeyCode; } //--------------------------------------------------------------------------- int __fastcall TTexLock::StringToCode(String strCode, BYTE **pCode) { int nLength = strCode.Length(); if (strCode.IsEmpty()) return -1; strCode = strCode.UpperCase(); if (*pCode) { delete [](*pCode); *pCode = NULL; } *pCode = new BYTE[nLength]; memset(*pCode, 0, sizeof(BYTE)*nLength); for (int i = 0; i < nLength; i++) { if ('0' <= strCode.c_str()[i] && strCode.c_str()[i] <= '9') { *((*pCode)+i) = (strCode.c_str()[i] - '0'); } else if ('A' <= strCode.c_str()[i] && strCode.c_str()[i] <= 'Z') { *((*pCode)+i) = (strCode.c_str()[i] - 'A' + 0x0A); } } return nLength; } //--------------------------------------------------------------------------- int __fastcall StringToCode(String strCode, BYTE **pCode) { int nLength = strCode.Length(); if (strCode.IsEmpty()) return -1; strCode = strCode.UpperCase(); if (*pCode) { delete [](*pCode); *pCode = NULL; } *pCode = new BYTE[nLength]; memset(*pCode, 0, sizeof(BYTE)*nLength); for (int i = 0; i < nLength; i++) { if ('0' <= strCode.c_str()[i] && strCode.c_str()[i] <= '9') { *((*pCode)+i) = (strCode.c_str()[i] - '0'); } else if ('A' <= strCode.c_str()[i] && strCode.c_str()[i] <= 'Z') { *((*pCode)+i) = (strCode.c_str()[i] - 'A' + 0x0A); } } return nLength; } //--------------------------------------------------------------------------- int __fastcall TTexLock::BitShiftStringToCode(BYTE cBit, String strShifted, BYTE **pCode) { BYTE cShiftMask, *pShiftString = NULL, *pPointer = NULL; int nByteCount, nLength, nPreInc, nCount; cShiftMask = 0; nCount = 0; while (nCount < cBit) { cShiftMask <<= 1; cShiftMask |= 1; nCount++; } if (strShifted.IsEmpty() || StringToCode(strShifted, &pShiftString) < 0) return -1; nLength = strShifted.Length(); nByteCount = (sizeof(BYTE)*nLength*cBit+7)/8; if (*pCode) delete [](*pCode); *pCode = new BYTE[nByteCount]; memset(*pCode, 0, sizeof(BYTE)*nByteCount); nCount = 0; pPointer = *pCode; nPreInc = 0; while (nCount < nLength) { if (nPreInc != (cBit*nCount/8)) { nPreInc = cBit*nCount/8; pPointer = pPointer+1; } *pPointer <<= ((cBit*nCount)%8); *pPointer |= (pShiftString[nCount] & cShiftMask); nCount++; } if (pShiftString) delete []pShiftString; pShiftString = NULL; return nByteCount; } //--------------------------------------------------------------------------- String __fastcall TTexLock::CodeToBitShiftString(BYTE cBit, BYTE *pCode, int nLength, bool bSeparate) { String strShifted; BYTE cShiftMask, *pShiftString = NULL; int nByteCount, nCount; cShiftMask = 0; nCount = 0; while (nCount < cBit) { cShiftMask <<= 1; cShiftMask |= 1; nCount++; } if (cBit > 0) { // Bit Shift nByteCount = (8/cBit)*nLength; } else { // Hexa nByteCount = nLength; cBit = 8; cShiftMask = 0xFF; } pShiftString = new BYTE[nByteCount]; memset(pShiftString, 0, sizeof(BYTE)*nByteCount); nCount = nByteCount-1; while (nCount >= 0) { pShiftString[nCount] = (((pCode[cBit*nCount/8]) >> ((cBit*(nByteCount-nCount-1))%8)) & cShiftMask); nCount--; } strShifted = CodeToString(pShiftString, nByteCount, bSeparate); if (pShiftString) { delete []pShiftString; pShiftString = NULL; } return strShifted; } //--------------------------------------------------------------------------- void __fastcall TTexLock::CheckReverseEngineeringTools() { TStringList *strTitleList = new TStringList; // Reverse Engineering Tool Kill // http://www.drvi.com/DrVirus/sub02/sub02_01_view.php?no=262 ¿¡ Ç¥±âµÇ¾îÀÖ´Â µð¹ö±ë ÇÁ·Î±×·¥ ¸ñ·Ï strTitleList->Add("EXESPY"); strTitleList->Add("WXR95"); strTitleList->Add("REGMON"); strTitleList->Add("FILE MONITOR"); strTitleList->Add("REGMONEX"); strTitleList->Add("WINDOW DETECTIVE"); strTitleList->Add("DEBUGVIEW"); strTitleList->Add("RESSPY"); strTitleList->Add("ADVANCED REGISTRY TRACER"); strTitleList->Add("REGSNAP"); strTitleList->Add("MEMSPY"); strTitleList->Add("MEMORY DOCTOR"); strTitleList->Add("PROCDUMP32"); strTitleList->Add("MEMORY EDITOR"); strTitleList->Add("FROGSICE"); strTitleList->Add("SMU WINSPECTOR"); strTitleList->Add("MEMORY DUMPER"); strTitleList->Add("MEMORYMONITOR"); strTitleList->Add("NUMEGA SOFTICE LOADER"); strTitleList->Add("URSOFT W32DASM"); strTitleList->Add("OllyDbg"); strTitleList->Add("TRW2000"); strTitleList->Add("DEDE"); // Delphi Decompiler strTitleList->Add("HACK"); strTitleList->Add("CRACK"); strTitleList->Add("WINICE"); strTitleList->Add("bdasm"); strTitleList->Add("W32DSM89"); strTitleList->Add("SyserApp"); strTitleList->Add("softice"); strTitleList->Add("frogsice"); strTitleList->Add("icedump"); strTitleList->Add("hexworkshop"); strTitleList->Add("fileinsight"); strTitleList->Add("hiew"); strTitleList->Add("wisdec"); strTitleList->Add("hedit"); strTitleList->Add("wxr95"); strTitleList->Add("newfiletime"); strTitleList->Add("apispy"); strTitleList->Add("fdbg"); strTitleList->Add("hdbg"); strTitleList->Add("opentrap"); strTitleList->Add("WINICE"); strTitleList->Add("frmspy"); strTitleList->Add("idag"); strTitleList->Add("protectionid"); strTitleList->Add("exeinfope"); strTitleList->Add("pexplorer"); strTitleList->Add("peid"); // ÇÁ·Î¼¼½ºÀÇ Ä¸¼ÇÀ̳ª ½ÇÇàÆÄÀϸíÀÌ °°À» °æ¿ì Á¾·á if (strTitleList) { //EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)strTitleList); KillReverseEngineeringTool(strTitleList); } if (strTitleList) { strTitleList->Clear(); delete strTitleList; } strTitleList = NULL; } //--------------------------------------------------------------------------- void __fastcall CheckReverseEngineeringTools() { TStringList *strTitleList = new TStringList; // Reverse Engineering Tool Kill // http://www.drvi.com/DrVirus/sub02/sub02_01_view.php?no=262 ¿¡ Ç¥±âµÇ¾îÀÖ´Â µð¹ö±ë ÇÁ·Î±×·¥ ¸ñ·Ï strTitleList->Add("EXESPY"); strTitleList->Add("WXR95"); strTitleList->Add("REGMON"); strTitleList->Add("FILE MONITOR"); strTitleList->Add("REGMONEX"); strTitleList->Add("WINDOW DETECTIVE"); strTitleList->Add("DEBUGVIEW"); strTitleList->Add("RESSPY"); strTitleList->Add("ADVANCED REGISTRY TRACER"); strTitleList->Add("REGSNAP"); strTitleList->Add("MEMSPY"); strTitleList->Add("MEMORY DOCTOR"); strTitleList->Add("PROCDUMP32"); strTitleList->Add("MEMORY EDITOR"); strTitleList->Add("FROGSICE"); strTitleList->Add("SMU WINSPECTOR"); strTitleList->Add("MEMORY DUMPER"); strTitleList->Add("MEMORYMONITOR"); strTitleList->Add("NUMEGA SOFTICE LOADER"); strTitleList->Add("URSOFT W32DASM"); strTitleList->Add("OllyDbg"); strTitleList->Add("TRW2000"); strTitleList->Add("DEDE"); // Delphi Decompiler strTitleList->Add("HACK"); strTitleList->Add("CRACK"); strTitleList->Add("WINICE"); strTitleList->Add("bdasm"); strTitleList->Add("W32DSM89"); strTitleList->Add("SyserApp"); strTitleList->Add("softice"); strTitleList->Add("frogsice"); strTitleList->Add("icedump"); strTitleList->Add("hexworkshop"); strTitleList->Add("fileinsight"); strTitleList->Add("hiew"); strTitleList->Add("wisdec"); strTitleList->Add("hedit"); strTitleList->Add("wxr95"); strTitleList->Add("newfiletime"); strTitleList->Add("apispy"); strTitleList->Add("fdbg"); strTitleList->Add("hdbg"); strTitleList->Add("opentrap"); strTitleList->Add("WINICE"); strTitleList->Add("frmspy"); strTitleList->Add("idag"); strTitleList->Add("protectionid"); strTitleList->Add("exeinfope"); strTitleList->Add("pexplorer"); strTitleList->Add("peid"); // ÇÁ·Î¼¼½ºÀÇ Ä¸¼ÇÀ̳ª ½ÇÇàÆÄÀϸíÀÌ °°À» °æ¿ì Á¾·á if (strTitleList) { //EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)strTitleList); KillReverseEngineeringTool(strTitleList); } if (strTitleList) { strTitleList->Clear(); delete strTitleList; } strTitleList = NULL; } //--------------------------------------------------------------------------- ////////////////////////// ---------- /////////////////////////////////////// ////////////////////////// for Server /////////////////////////////////////// ////////////////////////// ---------- /////////////////////////////////////// //--------------------------------------------------------------------------- #if !(defined(LOCK_CRYPKEY) || defined(LOCK_HASP) || defined(LOCK_IFC)) // for Server int __fastcall TTexLock::Encrypt(BYTE **pCode, int nLen, unsigned short nIVKeyIndex) { BYTE *pResult = NULL; BYTE IVKey[SeedBlockSize]; DWORD pRoundKey[32]; if (LoadFromKeyFile(nIVKeyIndex, IVKey) != 0) { return -1; } pResult = new BYTE[nLen]; memset(pResult, 0, sizeof(BYTE)*nLen); memcpy(pResult, *pCode, sizeof(BYTE)*nLen); if (*pCode) delete [](*pCode); SeedEncRoundKey(pRoundKey, IVKey); SeedEncrypt(pResult, pRoundKey); *pCode = pResult; return nLen; } //--------------------------------------------------------------------------- String __fastcall TTexLock::EncryptCombinationKey(String strCombinationKey) { BYTE *pCombinationKey = NULL, *pEncryptKey = NULL; String strEncode; int nLen = 0; unsigned short nIVKeyIndex; if (strCombinationKey.IsEmpty()) return ""; randomize(); nIVKeyIndex = (unsigned short)random(65535-SeedBlockSize); pCombinationKey = new BYTE[strCombinationKey.Length()]; //memcpy(pCombinationKey, strCombinationKey.c_str(), sizeof(BYTE)*strCombinationKey.Length()); for (int i = 0; i < strCombinationKey.Length(); i++) { pCombinationKey[i] = strCombinationKey.c_str()[i]; } nLen = Encrypt(&pCombinationKey, strCombinationKey.Length(), nIVKeyIndex); if (0 < nLen) { // ÀÎÁõŰ ÀúÀå (µÚ¿¡ 2Byte : IV Key) Index·Î »ç¿ë) pEncryptKey = new BYTE[nLen+2]; pEncryptKey[nLen] = (nIVKeyIndex >> 8) & 0x00FF; // »óÀ§¹ÙÀÌÆ® pEncryptKey[nLen+1] = (nIVKeyIndex & 0x00FF); // ÇÏÀ§¹ÙÀÌÆ® memcpy(pEncryptKey, pCombinationKey, nLen); nLen += 2; strEncode = CodeToBitShiftString(4, pEncryptKey, nLen, false); } else { // TODO : ¸Þ½ÃÁö } if (pCombinationKey) delete []pCombinationKey; pCombinationKey = NULL; if (pEncryptKey) delete []pEncryptKey; pEncryptKey = NULL; return strEncode; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CheckCRC(String strCode, String strCheckCRC) { BYTE *pCode = NULL; DWORD dwCodeLen; unsigned short nCrc16; BYTE CRC16[5]; String strCRC; dwCodeLen = StringToCode(strCode, &pCode); memset(CRC16, 0, sizeof(BYTE)*5); nCrc16 = 0; nCrc16 = Crc16(pCode, dwCodeLen); // ½ÇÁ¦·Î ¼ø¼­°¡ ¿ª¼øÀÌ µÇ¾ßÇÏÁö¸¸ ½±°Ô ÁüÀÛÇÒ ¼ö ¾øµµ·Ï ÀÌ·¸°Ô µÐ´Ù CRC16[0] = nCrc16 & 0x0F; CRC16[1] = (nCrc16 >> 4) & 0x0F; CRC16[2] = (nCrc16 >> 8) & 0x0F; CRC16[3] = (nCrc16 >> 12) & 0x0F; CRC16[4] = '\0'; strCRC = CodeToString(CRC16, 4, false); if (pCode) { delete []pCode; pCode = NULL; } if (strCRC == strCheckCRC) { return true; } else { return false; } } //--------------------------------------------------------------------------- String __fastcall TTexLock::ParsingKey(String strKey, String &strCombinationKey , String &strHDDDrvVolSN, BYTE &cVersion, unsigned int &nDoubleLock) { BYTE *pCombinationKey = NULL; BYTE HDDDrvVolSN[8]; String strCheckCRC; char cStatus = 'F'; String strReturn = ""; strCombinationKey = strKey.SubString(1, strKey.Length()-4); strCheckCRC = strKey.SubString(strKey.Length()-3, 4); if (CheckCRC(strCombinationKey, strCheckCRC)) { pCombinationKey = new BYTE[strCombinationKey.Length()]; for (int i = 0; i < strCombinationKey.Length(); i++) { pCombinationKey[i] = CharNumToIntNum(strCombinationKey.c_str()[i]); } // ¹æ¹ý 1. // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // V : Version // D : DoubleLockNumber // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] S[1] ~D[4] S[6] V[0] S[0] ~S[5] ~S[4] ~D[3] S[2] ~D[0] S[3] // // ¹æ¹ý 2. // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // W : Write File Time // V : Key Version // D : DoubleLockNumber // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] W[2] ~D[4] S[6] V[0] ~W[0] ~S[5] ~S[4] ~D[3] W[4] ~D[0] ~W[6] nDoubleLock = (~pCombinationKey[13] & 0x0F); nDoubleLock |= ((pCombinationKey[3] & 0x0F) << 4); nDoubleLock |= ((pCombinationKey[0] & 0x0F) << 8); nDoubleLock |= ((~pCombinationKey[11] & 0x0F) << 12); nDoubleLock |= ((~pCombinationKey[5] & 0x0F) << 16); nDoubleLock |= ((~pCombinationKey[2] & 0x0F) << 20); // HDD Drive Volume Serial Number HDDDrvVolSN[0] = (~pCombinationKey[1] & 0x0F); HDDDrvVolSN[1] = (pCombinationKey[6] & 0x0F); HDDDrvVolSN[2] = (~pCombinationKey[9] & 0x0F); HDDDrvVolSN[3] = (~pCombinationKey[10] & 0x0F); HDDDrvVolSN[4] = (pCombinationKey[14] & 0x0F); HDDDrvVolSN[5] = (pCombinationKey[12] & 0x0F); HDDDrvVolSN[6] = (pCombinationKey[4] & 0x0F); HDDDrvVolSN[7] = (pCombinationKey[8] & 0x0F); strHDDDrvVolSN = CodeToString(HDDDrvVolSN, 8, false); // KeyVersion cVersion = (pCombinationKey[7] & 0x0F); // ÇØÅ· »óÅ ÄÚµå °Ë»ç cStatus = HDDDrvVolSN[3]; if (cStatus == 0 || cStatus == 5) { // Modified Status.dat (Status.dat ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) strReturn = "Modified \'YoungWooCnI.DLL\'"; } else if (cStatus == 2 || cStatus == 8) { // Deleted YoungWooCnI.DLL (YoungWooCnI.DLL ÆÄÀÏÀÌ »èÁ¦µÈ »óÅÂ) strReturn = "Modified \'Status.dat\'"; } else if (cStatus == 1 || cStatus == 9) { // Debug Detect!! (¸®¹ö½º ¿£Áö´Ï¾î¸µ ÅøÀÌ ¹ß°ßµÈ »óÅÂ) strReturn = "Debugger Detected!!"; } else { strReturn = "Success"; } } else { strCombinationKey = ""; strCheckCRC = ""; strHDDDrvVolSN = ""; cVersion = 0; nDoubleLock = 0; strReturn = "Invalid Combination Key."; } if (pCombinationKey) delete []pCombinationKey; pCombinationKey = NULL; return strReturn; } //--------------------------------------------------------------------------- /* String __fastcall TTexLock::GetAuthorizationKey(String strCombinationKey, unsigned int nDoubleLock) { String strDoubleLock, strAuthorizationKey; BYTE DoubleLock[7]; // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // V : Version // D : DoubleLockNumber // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] S[1] ~D[6] S[6] V[0] S[0] ~S[5] ~S[4] ~D[3] S[2] ~D[0] S[3] // DoubleLockNumber DoubleLock[0] = (~nDoubleLock & 0x0F); DoubleLock[1] = ((nDoubleLock >> 4) & 0x0F); DoubleLock[2] = ((nDoubleLock >> 8) & 0x0F); DoubleLock[3] = ((~nDoubleLock >> 12) & 0x0F); DoubleLock[4] = ((~nDoubleLock >> 16) & 0x0F); DoubleLock[5] = ((~nDoubleLock >> 20) & 0x0F); DoubleLock[6] = '\0'; strDoubleLock = CodeToString(DoubleLock, 6, false); strCombinationKey.c_str()[13] = strDoubleLock.c_str()[0]; strCombinationKey.c_str()[3] = strDoubleLock.c_str()[1]; strCombinationKey.c_str()[0] = strDoubleLock.c_str()[2]; strCombinationKey.c_str()[11] = strDoubleLock.c_str()[3]; strCombinationKey.c_str()[5] = strDoubleLock.c_str()[4]; strCombinationKey.c_str()[2] = strDoubleLock.c_str()[5]; strAuthorizationKey = EncryptCombinationKey(strCombinationKey); return strAuthorizationKey; } */ //--------------------------------------------------------------------------- String __fastcall TTexLock::GetAuthorizationKey(String strCombinationKey, unsigned int nDoubleLock) { String strDoubleLock, strAuthorizationKey; BYTE DoubleLock[7]; // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // V : Version // D : DoubleLockNumber // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] S[1] ~D[6] S[6] V[0] S[0] ~S[5] ~S[4] ~D[3] S[2] ~D[0] S[3] // DoubleLockNumber DoubleLock[0] = (~nDoubleLock & 0x0F); DoubleLock[1] = ((nDoubleLock >> 4) & 0x0F); DoubleLock[2] = ((nDoubleLock >> 8) & 0x0F); DoubleLock[3] = ((~nDoubleLock >> 12) & 0x0F); DoubleLock[4] = ((~nDoubleLock >> 16) & 0x0F); DoubleLock[5] = ((~nDoubleLock >> 20) & 0x0F); DoubleLock[6] = '\0'; strDoubleLock = CodeToString(DoubleLock, 6, false); strCombinationKey.c_str()[13] = strDoubleLock.c_str()[0]; strCombinationKey.c_str()[3] = strDoubleLock.c_str()[1]; strCombinationKey.c_str()[0] = strDoubleLock.c_str()[2]; strCombinationKey.c_str()[11] = strDoubleLock.c_str()[3]; strCombinationKey.c_str()[5] = strDoubleLock.c_str()[4]; strCombinationKey.c_str()[2] = strDoubleLock.c_str()[5]; strAuthorizationKey = EncryptCombinationKey(strCombinationKey); return strAuthorizationKey; } //--------------------------------------------------------------------------- String __fastcall TTexLock::GetEncrypt(String strCombinationKey) { String strAuthorizationKey; strAuthorizationKey = EncryptCombinationKey(strCombinationKey); return strAuthorizationKey; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::SaveToKeyFile(int nVersion, String strKeyFileName) { HANDLE hFile = NULL; DWORD dwWrite; BYTE KeyData[SeedBlockSize]; if (strKeyFileName.IsEmpty()) goto fail; if ((hFile = CreateFile(strKeyFileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_WRITE_THROUGH, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (!WriteFile(hFile, &nVersion, sizeof(int), &dwWrite, NULL)) goto fail; // Key ÆÄÀÏ ¹öÀü randomize(); for (int i = 0; i < 4096; i++) { memset(KeyData, 0, sizeof(BYTE)*SeedBlockSize); for (int j = 0; j < SeedBlockSize; j++) { KeyData[j] = (BYTE)random(255); } if (!WriteFile(hFile, KeyData, sizeof(BYTE)*SeedBlockSize, &dwWrite, NULL)) goto fail; // 65536°³ÀÇ Key¸¦ ÀúÀåÇÑ´Ù } if (hFile) CloseHandle(hFile); hFile = NULL; return true; fail: if (hFile) CloseHandle(hFile); hFile = NULL; return false; } //--------------------------------------------------------------------------- #endif // for Server //--------------------------------------------------------------------------- ////////////////////////// ---------- /////////////////////////////////////// ////////////////////////// for Client /////////////////////////////////////// ////////////////////////// ---------- /////////////////////////////////////// //--------------------------------------------------------------------------- #ifdef LOCK_HASP // for Client String __fastcall TTexLock::MakeCRC(BYTE **pCode, DWORD *dwCodeSize) { unsigned short nCrc16; BYTE CRC16[5]; String strCRC; memset(CRC16, 0, sizeof(BYTE)*5); nCrc16 = 0; nCrc16 = Crc16(*pCode, *dwCodeSize); // ½ÇÁ¦·Î ¼ø¼­°¡ ¿ª¼øÀÌ µÇ¾ßÇÏÁö¸¸ ½±°Ô ÁüÀÛÇÒ ¼ö ¾øµµ·Ï ÀÌ·¸°Ô µÐ´Ù CRC16[0] = nCrc16 & 0x0F; CRC16[1] = (nCrc16 >> 4) & 0x0F; CRC16[2] = (nCrc16 >> 8) & 0x0F; CRC16[3] = (nCrc16 >> 12) & 0x0F; CRC16[4] = '\0'; strCRC = CodeToString(CRC16, 4, false); return strCRC; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CheckFileTime(FILETIME ftCreateTime, FILETIME ftAccessTime, FILETIME ftWriteTime) { // AccessTimeÀ¸·Î üũÇϰԵǸé Á¤¸» °­·ÂÇØÁöÁö¸¸, // V3 µî ¹é½Å/º¸¾È ÇÁ·Î±×·¥ÀÌ °Ë»çÀÇ ¸ñÀûÀ¸·Î Á¢±ÙÇßÀ» ¶§ // AccessTimeÀÌ º¯°æµÇ¾î ´Ù½Ã ÀÎÁõ ¹Þ¾Æ¾ßÇÏ´Â °æ¿ì°¡ »ý±ä´Ù // AccessTimeÀº ÀÏ´Ü Ã¼Å©ÇÏÁö ¾Ê´Â °ÍÀ¸·Î ÇÑ´Ù. if (CreateTime.dwLowDateTime == ftCreateTime.dwLowDateTime /*&& AccessTime.dwLowDateTime == ftAccessTime.dwLowDateTime*/ && WriteTime.dwLowDateTime == ftWriteTime.dwLowDateTime) { return true; } else { return false; } } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CheckWriteFileTime(FILETIME ftWriteTime) { if ((WriteTime.dwLowDateTime & 0x0F0F0F0F) == (ftWriteTime.dwLowDateTime & 0x0F0F0F0F)) { return true; } else { return false; } } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CheckVolumeSerialNumber(DWORD dwVolSerialNum, bool bAll) { DWORD dwVolumeSerialNumber; String strDrv; strDrv = ExtractFileDrive(FullPath) + "\\"; // ½ÇÇàÆÄÀϰú °°ÀÌ ÀÖ´Â µð½ºÅ©µå¶óÀ̺êÀÇ ¼Ó¼ºÀ» ±¸ÇÔ (¹Ýµå½Ã Çϵåµð½ºÅ© µå¶óÀ̺꿡¼­¸¸ ±¸µ¿) switch (GetDriveType(strDrv.c_str())) { case DRIVE_FIXED: // The disk cannot be removed from the drive. break; case 0: //The drive type cannot be determined. case 1: // The root directory does not exist. case DRIVE_REMOVABLE: // The drive can be removed from the drive. case DRIVE_REMOTE: // The drive is a remote (network) drive. case DRIVE_CDROM: // The drive is a CD-ROM drive. case DRIVE_RAMDISK: // The drive is a RAM disk. //Application->MessageBox(String(pMessage06).c_str(), String(pMessage01).c_str(), MB_ICONSTOP); SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE01); return false; } // ÇÁ·Î±×·¥ÀÌ ¼³Ä¡µÇ¾î ÀÖ´Â DriveÀÇ Hard Disk Serial Number¸¦ ¾ò¾î¿È GetVolumeInformation(strDrv.c_str(), NULL, 0, &dwVolumeSerialNumber, NULL, NULL, NULL, 0); if (bAll) { if (dwVolumeSerialNumber == dwVolSerialNum) { return true; } else { return false; } } else { //if ((dwVolumeSerialNumber & 0xFFFF0000) == (dwVolSerialNum & 0xFFFF0000)) { if ((dwVolumeSerialNumber & 0xFFF00000) == (dwVolSerialNum & 0xFFF00000)) { return true; } else { return false; } } } //--------------------------------------------------------------------------- bool __fastcall CheckVolumeSerialNumber(String FullPath, DWORD dwVolSerialNum, bool bAll) { DWORD dwVolumeSerialNumber; String strDrv; strDrv = ExtractFileDrive(FullPath) + "\\"; // ½ÇÇàÆÄÀϰú °°ÀÌ ÀÖ´Â µð½ºÅ©µå¶óÀ̺êÀÇ ¼Ó¼ºÀ» ±¸ÇÔ (¹Ýµå½Ã Çϵåµð½ºÅ© µå¶óÀ̺꿡¼­¸¸ ±¸µ¿) switch (GetDriveType(strDrv.c_str())) { case DRIVE_FIXED: // The disk cannot be removed from the drive. break; case 0: //The drive type cannot be determined. case 1: // The root directory does not exist. case DRIVE_REMOVABLE: // The drive can be removed from the drive. case DRIVE_REMOTE: // The drive is a remote (network) drive. case DRIVE_CDROM: // The drive is a CD-ROM drive. case DRIVE_RAMDISK: // The drive is a RAM disk. //Application->MessageBox(String(pMessage06).c_str(), String(pMessage01).c_str(), MB_ICONSTOP); String strStatusFilePath = ExtractFilePath(Application->ExeName) + "Status.dat"; SaveToStatusFile(strStatusFilePath, TEXLOCK_MESSAGE01); return false; } // ÇÁ·Î±×·¥ÀÌ ¼³Ä¡µÇ¾î ÀÖ´Â DriveÀÇ Hard Disk Serial Number¸¦ ¾ò¾î¿È GetVolumeInformation(strDrv.c_str(), NULL, 0, &dwVolumeSerialNumber, NULL, NULL, NULL, 0); if (bAll) { if (dwVolumeSerialNumber == dwVolSerialNum) { return true; } else { return false; } } else { //if ((dwVolumeSerialNumber & 0xFFFF0000) == (dwVolSerialNum & 0xFFFF0000)) { if ((dwVolumeSerialNumber & 0xFFF00000) == (dwVolSerialNum & 0xFFF00000)) { return true; } else { return false; } } } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CheckProtectCardNumber(unsigned int nDBL) { if ((nDBL & DoubleLock) == DoubleLock) { return true; } else { return false; } } //--------------------------------------------------------------------------- String __fastcall TTexLock::MakeCombinationKey(BYTE **pCombinationKey, DWORD *dwCombinationKeySize) { String strKeyCode; HANDLE hFile = NULL; DWORD dwVolumeSerialNumber; String strDrv; String strLockFilePath; unsigned int nDoubleLock; BYTE *KeyCode = NULL; char cStatus = 'F'; int nCount; strDrv = ExtractFileDrive(FullPath) + "\\"; // ½ÇÇàÆÄÀϰú °°ÀÌ ÀÖ´Â µð½ºÅ©µå¶óÀ̺êÀÇ ¼Ó¼ºÀ» ±¸ÇÔ (¹Ýµå½Ã Çϵåµð½ºÅ© µå¶óÀ̺꿡¼­¸¸ ±¸µ¿) switch (GetDriveType(strDrv.c_str())) { case DRIVE_FIXED: // The disk cannot be removed from the drive. break; case 0: //The drive type cannot be determined. case 1: // The root directory does not exist. case DRIVE_REMOVABLE: // The drive can be removed from the drive. case DRIVE_REMOTE: // The drive is a remote (network) drive. case DRIVE_CDROM: // The drive is a CD-ROM drive. case DRIVE_RAMDISK: // The drive is a RAM disk. //Application->MessageBox(String(pMessage06).c_str(), String(pMessage01).c_str(), MB_ICONSTOP); SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE01); goto fail; } // ÇÁ·Î±×·¥ÀÌ ¼³Ä¡µÇ¾î ÀÖ´Â DriveÀÇ Hard Disk Serial Number¸¦ ¾ò¾î¿È GetVolumeInformation(strDrv.c_str(), NULL, 0, &dwVolumeSerialNumber, NULL, NULL, NULL, 0); strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } nDoubleLock = DoubleLock; KeyCode = new BYTE[COMBINATIONKEY_LENGTH]; cStatus = LoadFromStatusFile(StatusFilePath); // ¹æ¹ý 1. // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // V : Key Version // D : DoubleLockNumber // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] S[1] ~D[4] S[6] V[0] S[0] ~S[5] ~S[4] ~D[3] S[2] ~D[0] S[3] /* KeyCode[0] = ((nDoubleLock >> 8) & 0x0F); KeyCode[1] = ((~dwVolumeSerialNumber >> 28) & 0x0F); KeyCode[2] = ((~nDoubleLock >> 20) & 0x0F); KeyCode[3] = ((nDoubleLock >> 4) & 0x0F); KeyCode[4] = ((dwVolumeSerialNumber >> 4) & 0x0F); KeyCode[5] = ((~nDoubleLock >> 16) & 0x0F); KeyCode[6] = ((dwVolumeSerialNumber >> 24) & 0x0F); KeyCode[7] = (KeyVersion & 0x0F); KeyCode[8] = (dwVolumeSerialNumber & 0x0F); KeyCode[9] = ((~dwVolumeSerialNumber >> 20) & 0x0F); KeyCode[10] = ((~dwVolumeSerialNumber >> 16) & 0x0F); KeyCode[11] = ((~nDoubleLock >> 12) & 0x0F); KeyCode[12] = ((dwVolumeSerialNumber >> 8) & 0x0F); KeyCode[13] = ((~nDoubleLock) & 0x0F); KeyCode[14] = ((dwVolumeSerialNumber >> 12) & 0x0F); */ // ¹æ¹ý 2. // KeyCode ¾Ïȣȭ (15¹ÙÀÌÆ®¸¦ ÃʰúÇÒ °æ¿ì, CryptCode°¡ µÎ ¹è·Î ´Ã¾î³ª±â¶§¹®¿¡ 15¹ÙÀÌÆ®¸¸ »ç¿ëÇÑ´Ù) // S : HDD Serial Number // W : Write File Time // V : Key Version // D : DoubleLockNumber // T : Status Number // [] : Position // // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // D[2] ~S[7] ~D[5] D[1] W[2] ~D[4] S[6] V[0] ~W[0] ~S[5] ~S[4] ~D[3] W[4] ~D[0] ~W[6] KeyCode[0] = ((nDoubleLock >> 8) & 0x0F); KeyCode[1] = ((~dwVolumeSerialNumber >> 28) & 0x0F); KeyCode[2] = ((~nDoubleLock >> 20) & 0x0F); KeyCode[3] = ((nDoubleLock >> 4) & 0x0F); KeyCode[4] = ((WriteTime.dwLowDateTime >> 8) & 0x0F); KeyCode[5] = ((~nDoubleLock >> 16) & 0x0F); KeyCode[6] = ((dwVolumeSerialNumber >> 24) & 0x0F); KeyCode[7] = (KeyVersion & 0x0F); KeyCode[8] = (~WriteTime.dwLowDateTime & 0x0F); KeyCode[9] = ((~dwVolumeSerialNumber >> 20) & 0x0F); //KeyCode[10] = ((~dwVolumeSerialNumber >> 16) & 0x0F); // ÇØÅ· »óÅ ÄÚµå·Î º¯°æ KeyCode[10] = (~cStatus & 0x0F); // ÇØÅ· »óÅ ÄÚµå KeyCode[11] = ((~nDoubleLock >> 12) & 0x0F); KeyCode[12] = ((WriteTime.dwLowDateTime >> 16) & 0x0F); KeyCode[13] = ((~nDoubleLock) & 0x0F); KeyCode[14] = ((~WriteTime.dwLowDateTime >> 24) & 0x0F); if (pCombinationKey && dwCombinationKeySize) { if (*pCombinationKey) delete [](*pCombinationKey); *dwCombinationKeySize = COMBINATIONKEY_LENGTH; *pCombinationKey = new BYTE[(*dwCombinationKeySize)]; // Á¶ÇÕŰ ÀúÀå memcpy(*pCombinationKey, KeyCode, sizeof(BYTE)*(*dwCombinationKeySize)); } strKeyCode = CodeToString(KeyCode, COMBINATIONKEY_LENGTH, true); if (hFile) CloseHandle(hFile); hFile = NULL; if (KeyCode) delete []KeyCode; KeyCode = NULL; return strKeyCode; fail: if (hFile) CloseHandle(hFile); hFile = NULL; if (KeyCode) delete []KeyCode; KeyCode = NULL; return ""; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CompareCombinationKeyAndAuthorizationKey(String strAuthorizationKey) { BYTE *pCombinationKey = NULL, *pEncode = NULL, *pTemp = NULL; //BYTE cProgramKeyIndex, cIVKeyIndex; unsigned short nProgramKeyIndex, nIVKeyIndex; unsigned int nDoubleLock; DWORD dwCombinationKeySize, dwTempKeySize, dwCombiKeySize, dwVoulmeSerialNumber; char cStatus = 'F'; FILETIME ftWriteFimeTime; BYTE cKeyVersion; int nEncodeSize; String strCombinationKey; int nIndex; bool bReturn = true; if (strAuthorizationKey.IsEmpty()) goto fail; // Á¶ÇÕŰ »ý¼º MakeCombinationKey(&pCombinationKey, &dwCombinationKeySize); if (pCombinationKey && dwCombinationKeySize > 0) { if (strAuthorizationKey.Length() != AUTHORIZATIONKEY_LENGTH) goto fail; // ÀÎÁõŰ ÀúÀå (µÚ¿¡ 2Byte : IV Key) Index·Î »ç¿ë) dwAuthorizationKeySize = BitShiftStringToCode(4, strAuthorizationKey, &pAuthorizationKey); nIVKeyIndex = ((pAuthorizationKey[dwAuthorizationKeySize-2] & 0x00FF) << 8) | (pAuthorizationKey[dwAuthorizationKeySize-1] & 0x00FF); pEncode = new BYTE[dwAuthorizationKeySize-2]; memcpy(pEncode, pAuthorizationKey, dwAuthorizationKeySize-2); nEncodeSize = Decrypt(&pEncode, dwAuthorizationKeySize-2, nIVKeyIndex); // Á¶ÇÕŰ¿Í ÀÎÁõŰÀÇ ºñ±³ if (nEncodeSize > 0) { strCombinationKey = CodeToString(pCombinationKey, dwCombinationKeySize, false); if (nEncodeSize == (int)(dwCombinationKeySize+4)) { // 4¸¦ ´õÇÑ ÀÌÀ¯´Â CRC ºÎºÐÀ» ºñ±³ÇÏÁö ¾Ê±â À§ÇØ nIndex = 0; nDoubleLock = 0; while (nIndex < dwCombinationKeySize) { // TexProÀÇ °æ¿ì Textile, Weave, Knit, Pile, CarpetÀ¸·Î ±¸¼ºµÇ¾î Àִµ¥ 3PackÀ̾ú´Ù°¡ 5PackÀ¸·Î ´Ã·Á¼­ ÀÎÁõÀÌ // ÇÊ¿äÇÒ °æ¿ìµµ ÀÖ´Ù. (Áï, ³Ñ°ÜÁØ ÇÁ·Î±×·¥ ProtectCardNumber¸¦ Æ÷ÇÔÇÏ´Â ´õ Å« °ªÀÌ ¿Ã ¼öµµ ÀÖ´Ù) // À̸¦ ÀúÀåÇϱâ À§ÇØ °Ç³Ê¶Ú´Ù // Index 10À» °Ç³Ê¶ç´Â ÀÌÀ¯´Â ÇØÅ·ÄÚµå ó¸® ¶§¹® if (nIndex == 0 || nIndex == 2 || nIndex == 3 || nIndex == 5 || nIndex == 11 || nIndex == 13 || nIndex == 10) { nIndex++; continue; } else if ((bReturn &= (strCombinationKey.c_str()[nIndex] == pEncode[nIndex])) == true) { nIndex++; } else { goto fail; } } // ¹æ¹ý 1. /* pTemp = new BYTE[8]; pTemp[0] = CharNumToIntNum(pDecode[13]); pTemp[1] = CharNumToIntNum(pDecode[3]); pTemp[2] = CharNumToIntNum(pDecode[0]); pTemp[3] = CharNumToIntNum(pDecode[11]); pTemp[4] = CharNumToIntNum(pDecode[5]); pTemp[5] = CharNumToIntNum(pDecode[2]); nDoubleLock = (~pTemp[0] & 0x0F); nDoubleLock |= ((pTemp[1] & 0x0F) << 4); nDoubleLock |= ((pTemp[2] & 0x0F) << 8); nDoubleLock |= ((~pTemp[3] & 0x0F) << 12); nDoubleLock |= ((~pTemp[4] & 0x0F) << 16); nDoubleLock |= ((~pTemp[5] & 0x0F) << 20); bReturn &= CheckProtectCardNumber(nDoubleLock); pTemp[0] = CharNumToIntNum(pDecode[7]); cKeyVersion = (pTemp[0] & 0x0F); bReturn &= (KeyVersion == cKeyVersion); pTemp[0] = CharNumToIntNum(pDecode[8]); pTemp[1] = CharNumToIntNum(pDecode[4]); pTemp[2] = CharNumToIntNum(pDecode[12]); pTemp[3] = CharNumToIntNum(pDecode[14]); pTemp[4] = CharNumToIntNum(pDecode[10]); pTemp[5] = CharNumToIntNum(pDecode[9]); pTemp[6] = CharNumToIntNum(pDecode[6]); pTemp[7] = CharNumToIntNum(pDecode[1]); dwVoulmeSerialNumber = (pTemp[0] & 0x0F); dwVoulmeSerialNumber |= ((pTemp[1] & 0x0F) << 4); dwVoulmeSerialNumber |= ((pTemp[2] & 0x0F) << 8); dwVoulmeSerialNumber |= ((pTemp[3] & 0x0F) << 12); dwVoulmeSerialNumber |= ((~pTemp[4] & 0x0F) << 16); dwVoulmeSerialNumber |= ((~pTemp[5] & 0x0F) << 20); dwVoulmeSerialNumber |= ((pTemp[6] & 0x0F) << 24); dwVoulmeSerialNumber |= ((~pTemp[7] & 0x0F) << 28); */ // ¹æ¹ý 2. pTemp = new BYTE[8]; pTemp[0] = CharNumToIntNum(pEncode[13]); pTemp[1] = CharNumToIntNum(pEncode[3]); pTemp[2] = CharNumToIntNum(pEncode[0]); pTemp[3] = CharNumToIntNum(pEncode[11]); pTemp[4] = CharNumToIntNum(pEncode[5]); pTemp[5] = CharNumToIntNum(pEncode[2]); nDoubleLock = (~pTemp[0] & 0x0F); nDoubleLock |= ((pTemp[1] & 0x0F) << 4); nDoubleLock |= ((pTemp[2] & 0x0F) << 8); nDoubleLock |= ((~pTemp[3] & 0x0F) << 12); nDoubleLock |= ((~pTemp[4] & 0x0F) << 16); nDoubleLock |= ((~pTemp[5] & 0x0F) << 20); bReturn &= CheckProtectCardNumber(nDoubleLock); pTemp[0] = CharNumToIntNum(pEncode[7]); cKeyVersion = (pTemp[0] & 0x0F); bReturn &= (KeyVersion == cKeyVersion); pTemp[0] = CharNumToIntNum(pEncode[10]); pTemp[1] = CharNumToIntNum(pEncode[9]); pTemp[2] = CharNumToIntNum(pEncode[6]); pTemp[3] = CharNumToIntNum(pEncode[1]); // ÇØÅ· »óÅ ÄÚµå cStatus = (~pTemp[0] & 0x0F); //dwVoulmeSerialNumber = ((~pTemp[0] & 0x0F) << 16); dwVoulmeSerialNumber = 0; dwVoulmeSerialNumber |= ((~pTemp[1] & 0x0F) << 20); dwVoulmeSerialNumber |= ((pTemp[2] & 0x0F) << 24); dwVoulmeSerialNumber |= ((~pTemp[3] & 0x0F) << 28); bReturn &= CheckVolumeSerialNumber(dwVoulmeSerialNumber, false); pTemp[0] = CharNumToIntNum(pEncode[8]); pTemp[1] = CharNumToIntNum(pEncode[4]); pTemp[2] = CharNumToIntNum(pEncode[12]); pTemp[3] = CharNumToIntNum(pEncode[14]); ftWriteFimeTime.dwLowDateTime = ((~pTemp[0] & 0x0F)); ftWriteFimeTime.dwLowDateTime |= ((pTemp[1] & 0x0F) << 8); ftWriteFimeTime.dwLowDateTime |= ((pTemp[2] & 0x0F) << 16); ftWriteFimeTime.dwLowDateTime |= ((~pTemp[3] & 0x0F) << 24); // TODO : ¼öÁ¤ ½Ã°£ üũ´Â ³Ê¹« °­·ÂÇϱ⠶§¹®¿¡ üũÇÏÁö ¾Êµµ·Ï ÇÑ´Ù. //bReturn &= CheckWriteFileTime(ftWriteFimeTime); if (pTemp) { delete []pTemp; pTemp = NULL; } } else { bReturn = false; } } else { bReturn = false; } if (pCombinationKey) { delete []pCombinationKey; pCombinationKey = NULL; } if (pEncode) { delete []pEncode; pEncode = NULL; } // Verification Key¸¦ ¸¸µç´Ù MakeVerificationKey(); } return bReturn; fail: if (pCombinationKey) delete []pCombinationKey; pCombinationKey = NULL; if (pEncode) delete []pEncode; pEncode = NULL; return false; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- bool __fastcall TTexLock::CompareCombinationKeyAndAuthorizationKey(BYTE **pFileAuthorizationKey, DWORD *dwFileAuthorizationKeySize) { BYTE *pCombinationKey = NULL, *pEncode = NULL, *pTemp = NULL; //BYTE cProgramKeyIndex, cIVKeyIndex; unsigned short nProgramKeyIndex, nIVKeyIndex; unsigned int nDoubleLock; DWORD dwCombinationKeySize, dwTempKeySize, dwCombiKeySize, dwVoulmeSerialNumber; char cStatus = 'F'; FILETIME ftWriteFimeTime; BYTE cKeyVersion; int nEncodeSize; String strCombinationKey; int nIndex; bool bReturn = true; // Á¶ÇÕŰ »ý¼º MakeCombinationKey(&pCombinationKey, &dwCombinationKeySize); if (pCombinationKey && (*pFileAuthorizationKey) && dwCombinationKeySize > 0 && (*dwFileAuthorizationKeySize) > 0) { // ÀÎÁõŰ ÀúÀå (µÚ¿¡ 2Byte : IV Key) Index·Î »ç¿ë) nIVKeyIndex = ((*((*pFileAuthorizationKey) + (*dwFileAuthorizationKeySize) - 2) & 0x00FF) << 8) | (*((*pFileAuthorizationKey) + (*dwFileAuthorizationKeySize) - 1) & 0x00FF); pEncode = new BYTE[(*dwFileAuthorizationKeySize)-2]; memcpy(pEncode, (*pFileAuthorizationKey), (*dwFileAuthorizationKeySize)-2); nEncodeSize = Decrypt(&pEncode, (*dwFileAuthorizationKeySize)-2, nIVKeyIndex); // Á¶ÇÕŰ¿Í ÀÎÁõŰÀÇ ºñ±³ if (nEncodeSize > 0) { strCombinationKey = CodeToString(pCombinationKey, dwCombinationKeySize, false); if (nEncodeSize == (int)dwCombinationKeySize+4) { // 4¸¦ ´õÇÑ ÀÌÀ¯´Â CRC ºÎºÐÀ» ºñ±³ÇÏÁö ¾Ê±â À§ÇØ nIndex = 0; while (nIndex < dwCombinationKeySize) { // TexProÀÇ °æ¿ì Textile, Weave, Knit, Pile, CarpetÀ¸·Î ±¸¼ºµÇ¾î Àִµ¥ 3PackÀ̾ú´Ù°¡ 5PackÀ¸·Î ´Ã·Á¼­ ÀÎÁõÀÌ // ÇÊ¿äÇÒ °æ¿ìµµ ÀÖ´Ù. (Áï, ³Ñ°ÜÁØ ÇÁ·Î±×·¥ ProtectCardNumber¸¦ Æ÷ÇÔÇÏ´Â ´õ Å« °ªÀÌ ¿Ã ¼öµµ ÀÖ´Ù) // À̸¦ ÀúÀåÇϱâ À§ÇØ °Ç³Ê¶Ú´Ù // Index 10À» °Ç³Ê¶ç´Â ÀÌÀ¯´Â ÇØÅ·ÄÚµå ó¸® ¶§¹® if (nIndex == 0 || nIndex == 2 || nIndex == 3 || nIndex == 5 || nIndex == 11 || nIndex == 13 || nIndex == 10) { nIndex++; continue; } else if ((bReturn &= (strCombinationKey.c_str()[nIndex] == pEncode[nIndex])) == true) { nIndex++; } else { goto modified; } } // ¹æ¹ý 1. /* pTemp = new BYTE[8]; pTemp[0] = CharNumToIntNum(pDecode[13]); pTemp[1] = CharNumToIntNum(pDecode[3]); pTemp[2] = CharNumToIntNum(pDecode[0]); pTemp[3] = CharNumToIntNum(pDecode[11]); pTemp[4] = CharNumToIntNum(pDecode[5]); pTemp[5] = CharNumToIntNum(pDecode[2]); nDoubleLock = (~pTemp[0] & 0x0F); nDoubleLock |= ((pTemp[1] & 0x0F) << 4); nDoubleLock |= ((pTemp[2] & 0x0F) << 8); nDoubleLock |= ((~pTemp[3] & 0x0F) << 12); nDoubleLock |= ((~pTemp[4] & 0x0F) << 16); nDoubleLock |= ((~pTemp[5] & 0x0F) << 20); bReturn &= CheckProtectCardNumber(nDoubleLock); pTemp[0] = CharNumToIntNum(pDecode[7]); cKeyVersion = (pTemp[0] & 0x0F); bReturn &= (KeyVersion == cKeyVersion); pTemp[0] = CharNumToIntNum(pDecode[8]); pTemp[1] = CharNumToIntNum(pDecode[4]); pTemp[2] = CharNumToIntNum(pDecode[12]); pTemp[3] = CharNumToIntNum(pDecode[14]); pTemp[4] = CharNumToIntNum(pDecode[10]); pTemp[5] = CharNumToIntNum(pDecode[9]); pTemp[6] = CharNumToIntNum(pDecode[6]); pTemp[7] = CharNumToIntNum(pDecode[1]); dwVoulmeSerialNumber = (pTemp[0] & 0x0F); dwVoulmeSerialNumber |= ((pTemp[1] & 0x0F) << 4); dwVoulmeSerialNumber |= ((pTemp[2] & 0x0F) << 8); dwVoulmeSerialNumber |= ((pTemp[3] & 0x0F) << 12); dwVoulmeSerialNumber |= ((~pTemp[4] & 0x0F) << 16); dwVoulmeSerialNumber |= ((~pTemp[5] & 0x0F) << 20); dwVoulmeSerialNumber |= ((pTemp[6] & 0x0F) << 24); dwVoulmeSerialNumber |= ((~pTemp[7] & 0x0F) << 28); */ // ¹æ¹ý 2. pTemp = new BYTE[8]; pTemp[0] = CharNumToIntNum(pEncode[13]); pTemp[1] = CharNumToIntNum(pEncode[3]); pTemp[2] = CharNumToIntNum(pEncode[0]); pTemp[3] = CharNumToIntNum(pEncode[11]); pTemp[4] = CharNumToIntNum(pEncode[5]); pTemp[5] = CharNumToIntNum(pEncode[2]); nDoubleLock = (~pTemp[0] & 0x0F); nDoubleLock |= ((pTemp[1] & 0x0F) << 4); nDoubleLock |= ((pTemp[2] & 0x0F) << 8); nDoubleLock |= ((~pTemp[3] & 0x0F) << 12); nDoubleLock |= ((~pTemp[4] & 0x0F) << 16); nDoubleLock |= ((~pTemp[5] & 0x0F) << 20); bReturn &= CheckProtectCardNumber(nDoubleLock); pTemp[0] = CharNumToIntNum(pEncode[7]); cKeyVersion = (pTemp[0] & 0x0F); bReturn &= (KeyVersion == cKeyVersion); // ÇØÅ· »óÅ ÄÚµå (»ç¿ëÇÏÁö´Â ¾ÊÀ½) cStatus = (~pEncode[10] & 0x0F); //pTemp[0] = CharNumToIntNum(pEncode[10]); pTemp[1] = CharNumToIntNum(pEncode[9]); pTemp[2] = CharNumToIntNum(pEncode[6]); pTemp[3] = CharNumToIntNum(pEncode[1]); //dwVoulmeSerialNumber = ((~pTemp[0] & 0x0F) << 16); dwVoulmeSerialNumber = 0; dwVoulmeSerialNumber |= ((~pTemp[1] & 0x0F) << 20); dwVoulmeSerialNumber |= ((pTemp[2] & 0x0F) << 24); dwVoulmeSerialNumber |= ((~pTemp[3] & 0x0F) << 28); bReturn &= CheckVolumeSerialNumber(dwVoulmeSerialNumber, false); pTemp[0] = CharNumToIntNum(pEncode[8]); pTemp[1] = CharNumToIntNum(pEncode[4]); pTemp[2] = CharNumToIntNum(pEncode[12]); pTemp[3] = CharNumToIntNum(pEncode[14]); ftWriteFimeTime.dwLowDateTime = ((~pTemp[0] & 0x0F)); ftWriteFimeTime.dwLowDateTime |= ((pTemp[1] & 0x0F) << 8); ftWriteFimeTime.dwLowDateTime |= ((pTemp[2] & 0x0F) << 16); ftWriteFimeTime.dwLowDateTime |= ((~pTemp[3] & 0x0F) << 24); // TODO : ¼öÁ¤ ½Ã°£ üũ´Â ³Ê¹« °­·ÂÇϱ⠶§¹®¿¡ üũÇÏÁö ¾Êµµ·Ï ÇÑ´Ù. //bReturn &= CheckWriteFileTime(ftWriteFimeTime); if (pTemp) { delete []pTemp; pTemp = NULL; } } else { bReturn = false; } } else { bReturn = false; } } if (pCombinationKey) { delete []pCombinationKey; pCombinationKey = NULL; } if (pEncode) { delete []pEncode; pEncode = NULL; } return bReturn; modified: SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); if (pCombinationKey) { delete []pCombinationKey; pCombinationKey = NULL; } if (pEncode) { delete []pEncode; pEncode = NULL; } return false; } //--------------------------------------------------------------------------- String __fastcall TTexLock::MakeAdditionKey(BYTE **pAdditionKey, DWORD *dwAdditionKeySize) { String strKeyCode; HANDLE hFile = NULL; DWORD dwVolumeSerialNumber; String strDrv; String strLockFilePath; unsigned int nDoubleLock; BYTE *KeyCode = NULL; strDrv = ExtractFileDrive(FullPath) + "\\"; // ½ÇÇàÆÄÀϰú °°ÀÌ ÀÖ´Â µð½ºÅ©µå¶óÀ̺êÀÇ ¼Ó¼ºÀ» ±¸ÇÔ (¹Ýµå½Ã Çϵåµð½ºÅ© µå¶óÀ̺꿡¼­¸¸ ±¸µ¿) switch (GetDriveType(strDrv.c_str())) { case DRIVE_FIXED: // The disk cannot be removed from the drive. break; case 0: //The drive type cannot be determined. case 1: // The root directory does not exist. case DRIVE_REMOVABLE: // The drive can be removed from the drive. case DRIVE_REMOTE: // The drive is a remote (network) drive. case DRIVE_CDROM: // The drive is a CD-ROM drive. case DRIVE_RAMDISK: // The drive is a RAM disk. //Application->MessageBox(String(pMessage06).c_str(), String(pMessage01).c_str(), MB_ICONSTOP); SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE01); goto fail; } // ÇÁ·Î±×·¥ÀÌ ¼³Ä¡µÇ¾î ÀÖ´Â DriveÀÇ Hard Disk Serial Number¸¦ ¾ò¾î¿È GetVolumeInformation(strDrv.c_str(), NULL, 0, &dwVolumeSerialNumber, NULL, NULL, NULL, 0); strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } // KeyCode ¾Ïȣȭ // S : HDD Serial Number // C : Create File Time // W : Write File Time // [] : Position // 0 1 2 3 4 5 6 7 8 9 // ~C[6] W[3] ~S[4] ~S[3] S[0] W[0] ~W[7] C[0] C[1] ~W[1] // 10 11 12 13 14 15 16 17 18 19 // ~W[2] S[7] S[2] ~C[4] C[3] W[4] ~S[6] S[1] ~W[6] ~S[5] // 20 21 22 23 // ~C[2] ~C[5] W[5] ~C[7] KeyCode = new BYTE[ADDITIONKEY_LENGTH]; KeyCode[0] = ((~CreateTime.dwLowDateTime >> 24) & 0x0F); KeyCode[1] = ((WriteTime.dwLowDateTime >> 12) & 0x0F); KeyCode[2] = ((~dwVolumeSerialNumber >> 16) & 0x0F); KeyCode[3] = ((~dwVolumeSerialNumber >> 12) & 0x0F); KeyCode[4] = ((dwVolumeSerialNumber) & 0x0F); KeyCode[5] = ((WriteTime.dwLowDateTime) & 0x0F); KeyCode[6] = ((~WriteTime.dwLowDateTime >> 28) & 0x0F); KeyCode[7] = ((CreateTime.dwLowDateTime) & 0x0F); KeyCode[8] = ((CreateTime.dwLowDateTime >> 4) & 0x0F); KeyCode[9] = ((~WriteTime.dwLowDateTime >> 4) & 0x0F); KeyCode[10] = ((~WriteTime.dwLowDateTime >> 8) & 0x0F); KeyCode[11] = ((dwVolumeSerialNumber >> 28) & 0x0F); KeyCode[12] = ((dwVolumeSerialNumber >> 8) & 0x0F); KeyCode[13] = ((~CreateTime.dwLowDateTime >> 16) & 0x0F); KeyCode[14] = ((CreateTime.dwLowDateTime >> 12) & 0x0F); KeyCode[15] = ((WriteTime.dwLowDateTime >> 16) & 0x0F); KeyCode[16] = ((~dwVolumeSerialNumber >> 24) & 0x0F); KeyCode[17] = ((dwVolumeSerialNumber >> 4) & 0x0F); KeyCode[18] = ((~WriteTime.dwLowDateTime >> 24) & 0x0F); KeyCode[19] = ((~dwVolumeSerialNumber >> 20) & 0x0F); KeyCode[20] = ((~CreateTime.dwLowDateTime >> 8) & 0x0F); KeyCode[21] = ((~CreateTime.dwLowDateTime >> 20) & 0x0F); KeyCode[22] = ((WriteTime.dwLowDateTime >> 20) & 0x0F); KeyCode[23] = ((~CreateTime.dwLowDateTime >> 28) & 0x0F); if (pAdditionKey && dwAdditionKeySize) { if (*pAdditionKey) { delete [](*pAdditionKey); } *dwAdditionKeySize = ADDITIONKEY_LENGTH; *pAdditionKey = new BYTE[(*dwAdditionKeySize)]; // Ãß°¡Å° ÀúÀå memcpy(*pAdditionKey, KeyCode, sizeof(BYTE)*(*dwAdditionKeySize)); } strKeyCode = CodeToString(KeyCode, ADDITIONKEY_LENGTH, true); if (hFile) { CloseHandle(hFile); hFile = NULL; } if (KeyCode) { delete []KeyCode; KeyCode = NULL; } return strKeyCode; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } if (KeyCode) { delete []KeyCode; KeyCode = NULL; } if (*pAdditionKey) { delete [](*pAdditionKey); *pAdditionKey = NULL; } return strKeyCode; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::MakeVerificationKey() { BYTE *pAdditionKey = NULL; DWORD dwAdditionKeySize; int nAuthorizationKeyIndex; MakeAdditionKey(&pAdditionKey, &dwAdditionKeySize); if (pAuthorizationKey && pAdditionKey && dwAuthorizationKeySize > 0 && dwAdditionKeySize > 0) { if (pVerificationKey) delete []pVerificationKey; dwVerificationKeySize = dwAdditionKeySize; pVerificationKey = new BYTE[dwVerificationKeySize]; nAuthorizationKeyIndex = 0; for (int i = 0; i < (int)dwVerificationKeySize; i++) { if (nAuthorizationKeyIndex >= (int)dwAuthorizationKeySize) nAuthorizationKeyIndex = 0; switch (pAdditionKey[i]%4) { case 0: // AdditionKey ^ AuthorizationKey ¿¬»ê pVerificationKey[i] = pAdditionKey[i] ^ pAuthorizationKey[nAuthorizationKeyIndex]; break; case 1: // pAdditionKey¸¦ ȯÇüÅ¥¶ó »ý°¢Çϰí (AuthorizationKey[nIndex] % 8)¸¸Å­ RightShift ÇÔ pVerificationKey[i] = (pAdditionKey[i] >> (pAuthorizationKey[nAuthorizationKeyIndex] % 8)) | (pAdditionKey[i] << (8-(pAuthorizationKey[nAuthorizationKeyIndex] % 8))); break; case 2: // pAdditionKey ^ ~AuthorizationKey ¿¬»ê pVerificationKey[i] = pAdditionKey[i] ^ ~(pAuthorizationKey[nAuthorizationKeyIndex]); break; case 3: // pAdditionKey¸¦ ȯÇüÅ¥¶ó »ý°¢Çϰí (AuthorizationKey[nIndex] % 8)¸¸Å­ LeftShift ÇÔ pVerificationKey[i] = (pAdditionKey[i] << (pAuthorizationKey[nAuthorizationKeyIndex] % 8)) | (pAdditionKey[i] >> (8-(pAuthorizationKey[nAuthorizationKeyIndex] % 8))); break; } nAuthorizationKeyIndex++; } if (pAdditionKey) delete []pAdditionKey; pAdditionKey = NULL; return true; } else { if (pAdditionKey) delete []pAdditionKey; pAdditionKey = NULL; return false; } } //--------------------------------------------------------------------------- bool __fastcall TTexLock::CompareAdditionKeyAndVerificationKey(BYTE **pFileAuthorizationKey, DWORD *dwFileAuthorizationKeySize, BYTE **pFileVerificationKey, DWORD *dwFileVerificationKeySize) { BYTE *pAdditionKey = NULL, *pCheckVerificationKey = NULL; DWORD dwAdditionKeySize, dwCheckVerificationKeySize, dwVolumeSerialNumber; int nAuthorizationKeyIndex; FILETIME ftKeyCreateTime, ftKeyAccessTime, ftKeyWriteTime; MakeAdditionKey(&pAdditionKey, &dwAdditionKeySize); if (pAdditionKey && (*pFileAuthorizationKey) && (*pFileVerificationKey) && dwAdditionKeySize > 0 && (*dwFileAuthorizationKeySize) > 0 && (*dwFileVerificationKeySize) > 0) { if (pCheckVerificationKey) { delete []pCheckVerificationKey; } dwCheckVerificationKeySize = dwAdditionKeySize; pCheckVerificationKey = new BYTE[dwCheckVerificationKeySize]; nAuthorizationKeyIndex = 0; for (int i = 0; i < (int)dwCheckVerificationKeySize; i++) { if (nAuthorizationKeyIndex >= (int)(*dwFileAuthorizationKeySize)) nAuthorizationKeyIndex = 0; switch (pAdditionKey[i]%4) { case 0: // AdditionKey ^ AuthorizationKey ¿¬»ê pCheckVerificationKey[i] = pAdditionKey[i] ^ *((*pFileAuthorizationKey)+nAuthorizationKeyIndex); break; case 1: // AdditionKey¸¦ ȯÇüÅ¥¶ó »ý°¢Çϰí (AuthorizationKey[nIndex] % 8)¸¸Å­ RightShift ÇÔ pCheckVerificationKey[i] = (pAdditionKey[i] >> (*((*pFileAuthorizationKey)+nAuthorizationKeyIndex) % 8)) | (pAdditionKey[i] << (8-(*((*pFileAuthorizationKey)+nAuthorizationKeyIndex) % 8))); break; case 2: // AdditionKey ^ ~AuthorizationKey ¿¬»ê pCheckVerificationKey[i] = (pAdditionKey[i]) ^ ~(*((*pFileAuthorizationKey)+nAuthorizationKeyIndex)); break; case 3: // AdditionKey¸¦ ȯÇüÅ¥¶ó »ý°¢Çϰí (AuthorizationKey[nIndex] % 8)¸¸Å­ LeftShift ÇÔ pCheckVerificationKey[i] = (pAdditionKey[i] << (*((*pFileAuthorizationKey)+nAuthorizationKeyIndex) % 8)) | (pAdditionKey[i] >> (8-(*((*pFileAuthorizationKey)+nAuthorizationKeyIndex) % 8))); break; } // ÆÄÀÏÀÇ pFileVerificationKey¿Í °°Àº °á°ú°¡ ³ª¿Â´Ù¸é ÇöÀçÀÇ pAdditionKey¿Í µ¿ÀÏÇÏ´Ù´Â °ÍÀÌ º¸ÀåµÈ´Ù if (pCheckVerificationKey[i] != *((*pFileVerificationKey)+i)) { if (pAdditionKey) { delete []pAdditionKey; pAdditionKey = NULL; } if (pCheckVerificationKey) { delete []pCheckVerificationKey; pCheckVerificationKey = NULL; } return false; } nAuthorizationKeyIndex++; } // 0 1 2 3 4 5 6 7 8 9 // ~C[6] W[3] ~S[4] ~S[3] S[0] W[0] ~W[7] C[0] C[1] ~W[1] // 10 11 12 13 14 15 16 17 18 19 // ~W[2] S[7] S[2] ~C[4] C[3] W[4] ~S[6] S[1] ~W[6] ~S[5] // 20 21 22 23 // ~C[2] ~C[5] W[5] ~C[7] // ÆÄÀÏ »ý¼º, Á¢±Ù, ¼öÁ¤ ½Ã°£ ftKeyCreateTime.dwLowDateTime = (pAdditionKey[7] & 0x0F); ftKeyCreateTime.dwLowDateTime |= ((pAdditionKey[8] & 0x0F) << 4); ftKeyCreateTime.dwLowDateTime |= ((~pAdditionKey[20] & 0x0F) << 8); ftKeyCreateTime.dwLowDateTime |= ((pAdditionKey[14] & 0x0F) << 12); ftKeyCreateTime.dwLowDateTime |= ((~pAdditionKey[13] & 0x0F) << 16); ftKeyCreateTime.dwLowDateTime |= ((~pAdditionKey[21] & 0x0F) << 20); ftKeyCreateTime.dwLowDateTime |= ((~pAdditionKey[0] & 0x0F) << 24); ftKeyCreateTime.dwLowDateTime |= ((~pAdditionKey[23] & 0x0F) << 28); ftKeyWriteTime.dwLowDateTime = (pAdditionKey[5] & 0x0F); ftKeyWriteTime.dwLowDateTime |= ((~pAdditionKey[9] & 0x0F) << 4); ftKeyWriteTime.dwLowDateTime |= ((~pAdditionKey[10] & 0x0F) << 8); ftKeyWriteTime.dwLowDateTime |= ((pAdditionKey[1] & 0x0F) << 12); ftKeyWriteTime.dwLowDateTime |= ((pAdditionKey[15] & 0x0F) << 16); ftKeyWriteTime.dwLowDateTime |= ((pAdditionKey[22] & 0x0F) << 20); ftKeyWriteTime.dwLowDateTime |= ((~pAdditionKey[18] & 0x0F) << 24); ftKeyWriteTime.dwLowDateTime |= ((~pAdditionKey[6] & 0x0F) << 28); // ½Ã¸®¾ó ¹øÈ£ dwVolumeSerialNumber = (pAdditionKey[4] & 0x0F); dwVolumeSerialNumber |= ((pAdditionKey[17] & 0x0F) << 4); dwVolumeSerialNumber |= ((pAdditionKey[12] & 0x0F) << 8); dwVolumeSerialNumber |= ((~pAdditionKey[3] & 0x0F) << 12); dwVolumeSerialNumber |= ((~pAdditionKey[2] & 0x0F) << 16); dwVolumeSerialNumber |= ((~pAdditionKey[19] & 0x0F) << 20); dwVolumeSerialNumber |= ((~pAdditionKey[16] & 0x0F) << 24); dwVolumeSerialNumber |= ((pAdditionKey[11] & 0x0F) << 28); if (pAdditionKey) { delete []pAdditionKey; pAdditionKey = NULL; } if (pCheckVerificationKey) { delete []pCheckVerificationKey; pCheckVerificationKey = NULL; } // ÆÄÀÏ »ý¼º ½Ã°£, ¾²±â ½Ã°£, ½Ã¸®¾ó ¹øÈ£ if (CheckFileTime(ftKeyCreateTime, ftKeyAccessTime, ftKeyWriteTime) && CheckVolumeSerialNumber(dwVolumeSerialNumber)) { return true; } else { return false; } } else { if (pAdditionKey) { delete []pAdditionKey; pAdditionKey = NULL; } if (pCheckVerificationKey) { delete []pCheckVerificationKey; pCheckVerificationKey = NULL; } return false; } } //--------------------------------------------------------------------------- bool __fastcall TTexLock::LoadFromFile(BYTE **pFileAuthorizationKey, DWORD *dwFileAuthorizationKeySize, BYTE **pFileVerificationKey, DWORD *dwFileVerificationKeySize) { String strLockFilePath; HANDLE hFile = NULL; DWORD dwRead; int nVersion; unsigned int nFileSize = 0; char cStatus = 'F'; strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; // YoungWooCnI.DLL ÆÄÀÏÀº »èÁ¦µÇ¾úÀ¸³ª Status.datÀÇ ³»¿ëÀÌ Congratulations!! ÀÏ °æ¿ì if (FileExists(strLockFilePath) == false) { cStatus = LoadFromStatusFile(StatusFilePath); // 4, 6 : Congratulations!! (ÀÎÁõ ¼º°ø »óÅÂ) if (cStatus == 4 || cStatus == 6) SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); } if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_READ, 0, NULL, OPEN_ALWAYS , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } // YoungWooCnI.DLL ÆÄÀÏ ³»¿ëÀº ¸ðµÎ »èÁ¦µÇ¾úÀ¸³ª Status.datÀÇ ³»¿ëÀÌ Congratulations!! ÀÏ °æ¿ì if (GetFileSize(hFile, 0) <= 0) { cStatus = LoadFromStatusFile(StatusFilePath); // 4, 6 : Congratulations!! (ÀÎÁõ ¼º°ø »óÅÂ) if (cStatus == 4 || cStatus == 6) SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); goto fail; } if (!ReadFile(hFile, &nVersion, sizeof(int), &dwRead, NULL)) goto fail; // Version if (FileVersion == nVersion) { if (!ReadFile(hFile, dwFileAuthorizationKeySize, sizeof(DWORD), &dwRead, NULL)) goto fail; // AuthorizationData Length if (*dwFileAuthorizationKeySize > 0) { if (*pFileAuthorizationKey) { delete [](*pFileAuthorizationKey); *pFileAuthorizationKey = NULL; } *pFileAuthorizationKey = new BYTE[(*dwFileAuthorizationKeySize)]; if (!ReadFile(hFile, *pFileAuthorizationKey, sizeof(BYTE)*(*dwFileAuthorizationKeySize), &dwRead, NULL)) goto fail; // AuthorizationData } else { SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); goto fail; } if (dwRead != (*dwFileAuthorizationKeySize)) goto fail; if (!ReadFile(hFile, dwFileVerificationKeySize, sizeof(DWORD), &dwRead, NULL)) goto fail; // EncodeData Length if ((*dwFileVerificationKeySize) > 0) { if ((*pFileVerificationKey)) { delete [](*pFileVerificationKey); *pFileVerificationKey = NULL; } *pFileVerificationKey = new BYTE[(*dwFileVerificationKeySize)]; if (!ReadFile(hFile, *pFileVerificationKey, sizeof(BYTE)*(*dwFileVerificationKeySize), &dwRead, NULL)) goto fail; // EncodeData } else { SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); goto fail; } if (dwRead != (*dwFileVerificationKeySize)) goto fail; } else { SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE08); goto fail; } if (hFile) { CloseHandle(hFile); hFile = NULL; } return true; fail: *dwFileAuthorizationKeySize = 0; *dwFileVerificationKeySize = 0; if (*pFileAuthorizationKey) { delete [](*pFileAuthorizationKey); *pFileAuthorizationKey = NULL; } if (*pFileVerificationKey) { delete [](*pFileVerificationKey); *pFileVerificationKey = NULL; } if (hFile) { CloseHandle(hFile); hFile = NULL; } return false; } //--------------------------------------------------------------------------- String __fastcall TTexLock::GetCombinationKey() { String strCombinationKey, strCheckSum, strKey; BYTE *pCombinationKey = NULL; DWORD dwCombinationKeySize; strCombinationKey = MakeCombinationKey(&pCombinationKey, &dwCombinationKeySize); strCheckSum = MakeCRC(&pCombinationKey, &dwCombinationKeySize); strKey = strCombinationKey + " " + strCheckSum; if (pCombinationKey) { delete []pCombinationKey; pCombinationKey = NULL; } return strKey; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::Check(bool bShowMessage, String strAuthorizationKey) { BYTE *pFileAuthorizationKey = NULL, *pFileVerificationKey = NULL; DWORD dwFileAuthorizationKeySize, dwFileVerificationKeySize; char cStatus = 'F'; bool bReturn = true; CheckReverseEngineeringTools(); if (strAuthorizationKey.IsEmpty() == false) { if (CompareCombinationKeyAndAuthorizationKey(strAuthorizationKey)) { SaveToFile(); if (bShowMessage) { //Application->MessageBox(String(pMessage03).c_str(), String(pMessage04).c_str(), MB_ICONINFORMATION); SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE04); } bReturn &= true; } else { if (bShowMessage) { Application->MessageBox(String(pMessage05).c_str(), String(pMessage02).c_str(), MB_ICONWARNING); } bReturn &= false; } } else { if (LoadFromFile(&pFileAuthorizationKey, &dwFileAuthorizationKeySize, &pFileVerificationKey, &dwFileVerificationKeySize)) { if (CompareCombinationKeyAndAuthorizationKey(&pFileAuthorizationKey, &dwFileAuthorizationKeySize) && CompareAdditionKeyAndVerificationKey(&pFileAuthorizationKey, &dwFileAuthorizationKeySize, &pFileVerificationKey, &dwFileVerificationKeySize)) { if (pFileAuthorizationKey) { delete []pFileAuthorizationKey; pFileAuthorizationKey = NULL; } if (pFileVerificationKey) { delete []pFileVerificationKey; pFileVerificationKey = NULL; } if (bShowMessage) { //Application->MessageBox(String(pMessage03).c_str(), String(pMessage04).c_str(), MB_ICONINFORMATION); SaveToStatusFile(StatusFilePath, TEXLOCK_MESSAGE04); } bReturn &= true; } else { if (pFileAuthorizationKey) { delete []pFileAuthorizationKey; pFileAuthorizationKey = NULL; } if (pFileVerificationKey) { delete []pFileVerificationKey; pFileVerificationKey = NULL; } if (bShowMessage) { Application->MessageBox(String(pMessage05).c_str(), String(pMessage02).c_str(), MB_ICONWARNING); } bReturn &= false; } } else { if (pFileAuthorizationKey) { delete []pFileAuthorizationKey; pFileAuthorizationKey = NULL; } if (pFileVerificationKey) { delete []pFileVerificationKey; pFileVerificationKey = NULL; } if (bShowMessage) { Application->MessageBox(String(pMessage05).c_str(), String(pMessage02).c_str(), MB_ICONWARNING); } bReturn &= false; } } // ÇØÅ· »óÅ ÆÄÀÏÀ» °Ë»çÇÑ´Ù cStatus = LoadFromStatusFile(StatusFilePath); // 2, 8 : Modified Status.dat (Status.dat ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) // 1, 9 : Debug Detect!! (¸®¹ö½º ¿£Áö´Ï¾î¸µ ÅøÀÌ ¹ß°ßµÈ »óÅÂ) // 0, 5 : Modified YoungWooCnI.DLL (YoungWooCnI.DLL ÆÄÀÏÀÌ ¼öÁ¤µÈ »óÅÂ) if (cStatus == 2 || cStatus == 8 || cStatus == 1 || cStatus == 9 || cStatus == 0 || cStatus == 5) bReturn &= false; return bReturn; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::SaveToFile() { String strLockFilePath; HANDLE hFile = NULL; DWORD dwWrite; strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; // ÆÄÀÏÀ» »õ·Î ¸¸µê if (pAuthorizationKey && pVerificationKey && dwAuthorizationKeySize > 0 && dwVerificationKeySize > 0) { if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (!WriteFile(hFile, &FileVersion, sizeof(int), &dwWrite, NULL)) goto fail; // Version if (!WriteFile(hFile, &dwAuthorizationKeySize, sizeof(DWORD), &dwWrite, NULL)) goto fail; // AuthorizationData Length if (!WriteFile(hFile, pAuthorizationKey, sizeof(BYTE)*dwAuthorizationKeySize, &dwWrite, NULL)) goto fail; // AuthorizationData if (dwWrite != dwAuthorizationKeySize) goto fail; if (!WriteFile(hFile, &dwVerificationKeySize, sizeof(DWORD), &dwWrite, NULL)) goto fail; // EncodeData Length if (!WriteFile(hFile, pVerificationKey, sizeof(BYTE)*dwVerificationKeySize, &dwWrite, NULL)) goto fail; // EncodeData if (dwWrite != dwVerificationKeySize) goto fail; if (hFile) { CloseHandle(hFile); hFile = NULL; } return true; } else { return false; } fail: if (pAuthorizationKey) { delete []pAuthorizationKey; pAuthorizationKey = NULL; } if (pVerificationKey) { delete []pVerificationKey; pVerificationKey = NULL; } if (hFile) { CloseHandle(hFile); hFile = NULL; } return false; } //--------------------------------------------------------------------------- bool __fastcall TTexLock::ClearFile() { String strLockFilePath; HANDLE hFile = NULL; strLockFilePath = ExtractFilePath(FullPath) + "YoungWooCnI.DLL"; // ÆÄÀÏÀ» »õ·Î ¸¸µê if (FileExists(strLockFilePath)) { if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (hFile) { CloseHandle(hFile); hFile = NULL; } if ((hFile = CreateFile(strLockFilePath.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS , FILE_ATTRIBUTE_HIDDEN, NULL)) == INVALID_HANDLE_VALUE) { goto fail; } if (hFile) { CloseHandle(hFile); hFile = NULL; } } return true; fail: if (hFile) { CloseHandle(hFile); hFile = NULL; } return false; } //--------------------------------------------------------------------------- #endif // for Client //--------------------------------------------------------------------------- #endif // LOCK_TEX //---------------------------------------------------------------------------