Global.cpp 8.9 KB

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