123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #include "StdAfx.h"
- #include <tlhelp32.h>
- #include "Global.h"
- TCHAR g_szModulePath[MAX_PATH] = _T(""); // 软件目录;
- TCHAR g_szModuleFileName[MAX_PATH] = _T(""); // 软件全名称;
- TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串;
- // 服务端主机信息;
- TCHAR g_szHostComputerIP[MAX_PATH] = _T(""); // 服务端主机名称;
- DWORD g_dwNICP = 0; // 多网卡时的网卡索引号;
- DWORD g_dwTCPChatPort = 0; // 服务端主机通信TCP端口;
- DWORD g_dwTCPFilePort = 0; // 服务端主机文件传输端口;
- // 短信服务端主机信息;
- TCHAR g_szSMSServer[MAX_PATH] = _T(""); // 短信服务端主机名称;
- DWORD g_dwTCPSMSPort = 0; // 短信服务端主机通信端口;
- // 数据库信息;
- TCHAR g_szDBSource[MAX_PATH] = _T(""); // 数据库源(服务所在IP或计算机名);
- TCHAR g_szDBSourcePort[MAX_PATH] = _T(""); // 数据库源端口;
- DWORD g_dwDBServerPort = 0; // 数据库源端口;
- TCHAR g_szDBAccount[MAX_PATH] = _T(""); // 数据库登录用户;
- TCHAR g_szDBPassWord[MAX_PATH] = _T(""); // 数据库登录密码;
- TCHAR g_szDBName[MAX_PATH] = _T(""); // 数据库名称;
- Ado2Impl* g_AdoImpl = NULL;
- TCHAR g_szEncryS1[50] = _T("");
- CHAR g_szKeyPath[MAX_PATH] = {0};
- int g_nVersion = -1;
- BYTE g_byShotVersion[6][10] =
- {
- { 6, 0, 148, 11, 205, 50, 4, 171, 32, 39 }, // 儿童座席版;
- { 6, 0, 4, 29, 24, 247, 189, 95, 83, 76 }, // 婚纱座席版;
- { 6, 0, 4, 187, 103, 10, 59, 169, 240, 220 }, // 儿童企业版;
- { 6, 0, 137, 160, 230, 173, 202, 2, 117, 142 }, // 婚纱企业版;
- { 6, 0, 194, 199, 210, 67, 185, 1, 138, 195 }, // 儿童全能版;
- { 6, 0, 188, 145, 100, 47, 154, 177, 34, 205 }, // 婚纱全能版;
- };
- // endof------------6版本加密狗信息----------------;
- // start---------------加密表达式加密后的数组----------------------;
- BYTE g_byCalExVersion[7][114] =
- {
- // 儿童座席版;
- { 109, 0, 90, 15, 108, 138, 37, 190, 82, 8, 20, 252, 32, 162, 7, 8, 254, 255, 56, 245, 194, 4, 46, 120, 49, 120, 156, 27, 17, 164, 217,
- 79, 167, 146, 197, 69, 55, 117, 197, 149, 42, 217, 151, 195, 254, 145, 187, 197, 232, 188, 114, 223, 40, 229, 151, 245, 116, 177, 141, 94, 134, 14,
- 13, 169, 165, 94, 5, 216, 235, 60, 176, 38, 174, 121, 187, 174, 16, 30, 17, 20, 246, 34, 20, 252, 32, 162, 7, 8, 254, 255, 56, 245, 194,
- 4, 46, 120, 49, 120, 156, 27, 17, 164, 217, 79, 167, 146, 143, 132, 219, 173, 211, 2, 99, 180 },
- // 婚纱座席版;
- { 109, 0, 128, 13, 164, 143, 252, 87, 30, 48, 20, 21, 145, 114, 160, 96, 49, 127, 181, 32, 144, 213, 109, 99, 142, 219, 71, 26, 22, 220, 177,
- 179, 191, 82, 138, 45, 173, 160, 9, 83, 162, 106, 182, 175, 47, 92, 214, 78, 93, 21, 202, 165, 167, 200, 198, 172, 218, 74, 236, 194, 194, 228,
- 40, 27, 95, 60, 160, 173, 66, 185, 178, 7, 159, 220, 58, 71, 140, 19, 20, 37, 66, 84, 20, 21, 145, 114, 160, 96, 49, 127, 181, 32, 144,
- 213, 109, 99, 142, 219, 71, 26, 22, 220, 177, 179, 191, 82, 232, 182, 45, 27, 13, 195, 225, 204 },
- // 儿童企业版;
- { 109, 0, 229, 36, 223, 222, 213, 46, 70, 55, 240, 207, 237, 75, 226, 68, 133, 100, 42, 119, 89, 131, 79, 104, 158, 17, 172, 239, 4, 158, 201,
- 51, 62, 51, 94, 232, 14, 124, 81, 64, 100, 141, 187, 85, 156, 59, 205, 116, 200, 24, 108, 218, 145, 22, 7, 36, 45, 7, 156, 255, 170, 130,
- 165, 140, 99, 216, 120, 72, 171, 196, 27, 49, 138, 199, 137, 246, 214, 247, 121, 114, 215, 199, 240, 207, 237, 75, 226, 68, 133, 100, 42, 119, 89,
- 131, 79, 104, 158, 17, 172, 239, 4, 158, 201, 51, 62, 51, 248, 214, 27, 254, 221, 208, 181, 209 },
- // 婚纱企业版;
- { 109, 0, 94, 220, 40, 182, 30, 120, 56, 193, 78, 101, 1, 144, 68, 206, 192, 52, 67, 9, 243, 20, 9, 195, 153, 15, 22, 217, 243, 79, 177,
- 22, 24, 171, 185, 157, 172, 67, 117, 124, 153, 165, 3, 41, 218, 47, 149, 150, 48, 152, 75, 250, 204, 253, 92, 53, 121, 147, 242, 140, 80, 66,
- 34, 194, 16, 109, 237, 17, 222, 161, 96, 8, 11, 194, 58, 45, 86, 15, 207, 121, 247, 104, 78, 101, 1, 144, 68, 206, 192, 52, 67, 9, 243,
- 20, 9, 195, 153, 15, 22, 217, 243, 79, 177, 22, 24, 171, 122, 243, 190, 146, 77, 222, 208, 129 },
- // 儿童全能版;
- { 109, 0, 26, 222, 0, 239, 199, 199, 188, 225, 180, 168, 178, 208, 21, 79, 62, 90, 51, 31, 88, 128, 180, 105, 53, 137, 230, 254, 244, 50, 195,
- 49, 167, 143, 168, 125, 130, 125, 8, 73, 224, 120, 80, 95, 178, 49, 44, 158, 38, 38, 247, 169, 62, 187, 119, 192, 77, 194, 118, 246, 133, 241,
- 157, 62, 144, 24, 94, 173, 49, 192, 46, 250, 249, 239, 82, 78, 135, 3, 86, 154, 8, 135, 180, 168, 178, 208, 21, 79, 62, 90, 51, 31, 88,
- 128, 180, 105, 53, 137, 230, 254, 244, 50, 195, 49, 167, 143, 241, 214, 38, 180, 198, 3, 158, 165 },
- // 婚纱全能版;
- { 109, 0, 139, 145, 163, 176, 66, 18, 207, 79, 172, 200, 12, 124, 89, 151, 248, 238, 26, 85, 137, 146, 119, 58, 76, 194, 151, 239, 204, 104, 18,
- 166, 208, 54, 37, 85, 3, 174, 28, 74, 154, 156, 120, 194, 8, 112, 79, 42, 27, 89, 81, 95, 238, 74, 59, 199, 160, 101, 117, 179, 51, 138,
- 70, 176, 239, 182, 160, 212, 11, 33, 224, 74, 155, 143, 216, 10, 220, 71, 8, 168, 18, 175, 172, 200, 12, 124, 89, 151, 248, 238, 26, 85, 137,
- 146, 119, 58, 76, 194, 151, 239, 204, 104, 18, 166, 208, 54, 114, 118, 181, 24, 252, 41, 246, 88 },
- };
- // endof---------------加密表达式加密后的数组----------------------;
- //************************************//
- // 数据库地址;
- // 数据库端口;
- // 数据库管理员账号;
- // 数据库管理员密码;
- // 数据库名称;
- //
- // [函数]:GetIniInfo
- // [描述]:获取指定ini信息;
- // [参数]:
- // szPath:ini所在目录;
- // szIniName:ini名;
- // [返回]:void
- //
- //************************************//
- int GetIniInfo(const TCHAR *szPath,const TCHAR *szIniName)
- {
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_DIR] = { 0 };
- TCHAR szExt[_MAX_DIR] = { 0 };
- ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
- _stprintf_s(g_szModulePath, _T("%s"), g_szModuleFileName);
- _tsplitpath_s(g_szModulePath, szDrive, szDir, szFna, szExt);
- _tcscpy_s(g_szModulePath, szDrive);
- _tcscat_s(g_szModulePath, szDir);
- // -----------------------------------------------------//
- TCHAR szFile[MAX_PATH + 1] = _T("");
- if (szPath != NULL && szIniName != NULL)
- _stprintf_s(szFile, _T("%s\\%s"), szPath, szIniName);
- else
- _stprintf_s(szFile, _T("%s\\ServiceInfo.ini"), g_szModulePath);
- HANDLE hFile = CreateFile(szFile, 0/*GENERIC_READ*/, 0, NULL, OPEN_EXISTING, 0, NULL);
- if (ERROR_FILE_NOT_FOUND == GetLastError())
- {
- return -1;
- }
- // 获取数据库信息;
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbSource"), _T(""), g_szDBSource, MAX_PATH, szFile);
- g_dwDBServerPort = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbServerPort"), 0, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbAccount"), _T(""), g_szDBAccount, MAX_PATH, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbPassWord"), _T(""), g_szDBPassWord, MAX_PATH, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbName"), _T(""), g_szDBName, MAX_PATH, szFile);
- if (g_dwDBServerPort != 0)
- _stprintf_s(g_szConnectString, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
- g_szDBSource, g_dwDBServerPort, g_szDBName, g_szDBAccount, g_szDBPassWord);
- else
- _stprintf_s(g_szConnectString, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
- g_szDBSource, g_szDBName, g_szDBAccount, g_szDBPassWord);
- return 0;
- }
- int FindPortEx(int start, BYTE *InByte, int InLen, char *OutPath)
- {
- int n;
- int ret;
- int D[8];
- double F[8];
- char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
- CHAR KeyPath[MAX_PATH] = "";
- //查找系统上所有的锁;
- for (n = 0; n < 256; n++)
- {
- ZeroMemory(KeyPath, sizeof(KeyPath));
- ret = FindPort(n, KeyPath);
- if (ret != 0 && n == 0)return -1053;//表示系统上没有任何智能锁;
- if (ret != 0)return ret;
- #if 1
- sprintf_s(g_szKeyPath,"%s",KeyPath);
- #endif
- //使用该设备路径锁进行运算;
- ret = CalEx(InByte, InLen, &D[0], &D[1], &D[2], &D[3], &D[4], &D[5], &D[6], &D[7],
- &F[0], &F[1], &F[2], &F[3], &F[4], &F[5], &F[6], &F[7],
- s0, s1, s2, s3, s4, s5, s6, s7, KeyPath, 20000);
- //如果正确,则返回该设备路径供以后使用;
- if (ret == -63)return ret;
- if ((ret == 0) && (D[0] == 123))return 0;
- }
- return -53;
- }
- int GetSoftWareVersion()
- {
- int nRet = 0;
- CHAR szUSBKeyPath[MAX_PATH] = "";
- for (int i(0); i < 6; i++)
- {
- nRet = FindPortEx(0, g_byShotVersion[i], 10, szUSBKeyPath);
- if (nRet == 0)
- {
- g_nVersion = i;
- break;
- }
- else
- {
- //TCHAR szErrInfo[MAX_PATH] = _T("");
- //GetUSBKey32ErrInfo(nRet,szErrInfo,MAX_PATH);
- }
- }
- if (nRet == 0 )
- {
- // 再获取本机加密狗的s1位置字符串;
- INT nUnit[8] = {0};
- double fUnit[8] = {0.0};
- char cUnit[8][50] = {""};
- nRet = CalEx(g_byCalExVersion[g_nVersion],114,
- &nUnit[0],&nUnit[1],&nUnit[2],&nUnit[3],&nUnit[4],&nUnit[5],&nUnit[6],&nUnit[7],
- &fUnit[0],&fUnit[1],&fUnit[2],&fUnit[3],&fUnit[4],&fUnit[5],&fUnit[6],&fUnit[7],
- cUnit[0],cUnit[1],cUnit[2],cUnit[3],cUnit[4],cUnit[5],cUnit[6],cUnit[7],
- g_szKeyPath,200);
- if ( nRet == 0 || nRet == -43)
- {
- #if _DEBUG
- TRACE("加密狗S1:");
- TRACE(cUnit[1]);;
- TRACE("\n");
- #endif
- //LOG4C_NO_FILENUM((LOG_NOTICE,"本店域名:%s",cUnit[1]));
- USES_CONVERSION;
- _stprintf_s(g_szEncryS1,_T("%s"),A2W(cUnit[1]));
- }
- }
- return g_nVersion;
- }
|