YtDongle.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. #ifndef JEFF_ENCRYPTLOCK_HAEDER_20150708
  2. #define JEFF_ENCRYPTLOCK_HAEDER_20150708
  3. #include <string>
  4. #include <vector>
  5. #include "my32.h"
  6. #pragma comment (lib,"my32.lib")
  7. #pragma once
  8. namespace YtDongle
  9. {
  10. //////////////////////////////////////////////////////////////////////////
  11. // 宏定义;
  12. #define TIMELEN 10
  13. #define ENCRYPT_BLOCK_LEN 33 // 包含结束符'\0';
  14. #define ISCHILDVER(Ver) ( 5-Ver > 2 ) // 判断是否儿童版本;
  15. //////////////////////////////////////////////////////////////////////////
  16. // 枚举定义;
  17. enum EncryptType
  18. {
  19. EN_OCHILD = 0, // 儿童全能版;
  20. EN_LCHILD = 1, // 儿童座席版;
  21. EN_ECHILD = 2, // 儿童企业版;
  22. EN_OWDDING = 3, // 婚纱全能版;
  23. EN_LWDDING = 4, // 婚纱座席版;
  24. EN_EWDDING = 5, // 婚纱企业版;
  25. };
  26. enum Ver1ModifyType
  27. {
  28. VER1_ADDCCOUNT = 0,
  29. VER1_MINUSCCOUNT,
  30. VER1_HOSPITAL,
  31. VER1_ADDTIME,
  32. VER1_MINUSTIME,
  33. };
  34. //////////////////////////////////////////////////////////////////////////
  35. // 结构体定义;
  36. typedef struct _YT_ERROR_
  37. {
  38. INT nErrorCode;
  39. TCHAR* pErrorDescription;
  40. }YtError, *pYtError;
  41. typedef struct _ENCRYPT_LOCKINFO_
  42. {
  43. INT nSoftVer;
  44. INT nCCount;
  45. BOOL bHospital;
  46. BOOL bAdddate;
  47. CHAR szRunyears[TIMELEN];
  48. CHAR szRunmonths[TIMELEN];
  49. CHAR szRundays[TIMELEN];
  50. CHAR szRunhours[TIMELEN];
  51. CHAR szRunminutes[TIMELEN];
  52. _ENCRYPT_LOCKINFO_()
  53. {
  54. nSoftVer = -1;
  55. nCCount = 0;
  56. bHospital = FALSE;
  57. bAdddate = FALSE;
  58. memset(szRunyears, 0, TIMELEN);
  59. memset(szRunmonths, 0, TIMELEN);
  60. memset(szRundays, 0, TIMELEN);
  61. memset(szRunhours, 0, TIMELEN);
  62. memset(szRunminutes, 0, TIMELEN);
  63. }
  64. _ENCRYPT_LOCKINFO_(CONST INT& nsoftver, CONST INT& nccount, BOOL bhospital, BOOL badddate, CONST CHAR* szyears, CONST CHAR* szmonths, CONST CHAR* szday, CONST CHAR* szhours, CONST CHAR* szminutes)
  65. {
  66. nSoftVer = nsoftver;
  67. nCCount = nccount;
  68. bHospital = bhospital;
  69. bAdddate = badddate;
  70. if (szyears)
  71. {
  72. sprintf_s(szRunyears, "%s", szyears);
  73. }
  74. else
  75. {
  76. strcpy_s(szRunyears, "0");
  77. }
  78. if (szmonths)
  79. {
  80. sprintf_s(szRunmonths, "%s", szmonths);
  81. }
  82. else
  83. {
  84. strcpy_s(szRunmonths, "0");
  85. }
  86. if (szday)
  87. {
  88. sprintf_s(szRundays, "%s", szday);
  89. }
  90. else
  91. {
  92. strcpy_s(szRundays, "0");
  93. }
  94. if (szhours)
  95. {
  96. sprintf_s(szRunhours, "%s", szhours);
  97. }
  98. else
  99. {
  100. strcpy_s(szRunhours, "0");
  101. }
  102. if (szminutes)
  103. {
  104. sprintf_s(szRunminutes, "%s", szminutes);
  105. }
  106. else
  107. {
  108. strcpy_s(szRunminutes, "0");
  109. }
  110. }
  111. }EncryptlockInfo, *pEncryptlockInfo;
  112. typedef struct _YT_INFO_VER1_
  113. {
  114. INT nSoftVer;
  115. DWORD dwShortKey;
  116. CHAR szHospital[MAX_PATH];
  117. CHAR szCCount[MAX_PATH];
  118. CHAR szBranchId[MAX_PATH];
  119. // 已运行时间;
  120. CHAR szHasRunyears[TIMELEN];
  121. CHAR szHasRunmonths[TIMELEN];
  122. CHAR szHasRundays[TIMELEN];
  123. CHAR szHasRunhours[TIMELEN];
  124. CHAR szHasRunminutes[TIMELEN];
  125. CHAR szHasRunseconds[TIMELEN];
  126. // 可运行时间;
  127. CHAR szCanRunyears[TIMELEN];
  128. CHAR szCanRunmonths[TIMELEN];
  129. CHAR szCanRundays[TIMELEN];
  130. CHAR szCanRunhours[TIMELEN];
  131. CHAR szCanRunminutes[TIMELEN];
  132. _YT_INFO_VER1_()
  133. {
  134. nSoftVer = -1;
  135. dwShortKey = 0;
  136. memset(szHospital, 0, MAX_PATH*sizeof(CHAR));
  137. memset(szCCount, 0, MAX_PATH*sizeof(CHAR));
  138. memset(szBranchId, 0, MAX_PATH*sizeof(CHAR));
  139. memset(szHasRunyears, 0, TIMELEN*sizeof(CHAR));
  140. memset(szHasRunmonths, 0, TIMELEN*sizeof(CHAR));
  141. memset(szHasRundays, 0, TIMELEN*sizeof(CHAR));
  142. memset(szHasRunhours, 0, TIMELEN*sizeof(CHAR));
  143. memset(szHasRunminutes, 0, TIMELEN*sizeof(CHAR));
  144. memset(szHasRunseconds, 0, TIMELEN*sizeof(CHAR));
  145. memset(szCanRunyears, 0, TIMELEN*sizeof(CHAR));
  146. memset(szCanRunmonths, 0, TIMELEN*sizeof(CHAR));
  147. memset(szCanRundays, 0, TIMELEN*sizeof(CHAR));
  148. memset(szCanRunhours, 0, TIMELEN*sizeof(CHAR));
  149. memset(szCanRunminutes, 0, TIMELEN*sizeof(CHAR));
  150. }
  151. }YtInfoVer1, *pYtInfoVer1;
  152. typedef struct YTUSBINFO
  153. {
  154. int nUSBPort;
  155. CHAR szKeyPath[MAX_PATH];
  156. YtInfoVer1 verInfo;
  157. }YtUsbInfo, *pYtUsbInfo;
  158. //////////////////////////////////////////////////////////////////////////
  159. // 全局变量定义;
  160. extern CHAR *g_pHReadPassWord;
  161. extern CHAR *g_pLReadPassWord;
  162. extern CHAR *g_pHWritePassWord;
  163. extern CHAR *g_pLWritePassWord;
  164. extern BOOL g_bUSE_NEWPASSWORD;
  165. extern CHAR *g_szEncKey[][4];
  166. extern CHAR *g_szRom[];
  167. extern CHAR *g_szPassword[][2];
  168. extern CHAR *g_szUserKey;
  169. extern BYTE g_byShotVersion[][10];
  170. extern CONST BYTE g_byCalExVersion[][114];
  171. extern CHAR g_szKeyPath[MAX_PATH];
  172. extern CONST YtError g_YtError[];
  173. //////////////////////////////////////////////////////////////////////////
  174. // 全局函数定义;
  175. //
  176. // ASCII字符转UNICODE字符;
  177. WCHAR* ascii2unicode(IN const CHAR* pszascii);
  178. // 初始化密码;
  179. extern void ReSetPassWord(BOOL bClassicPsw = FALSE);
  180. // 返回错误码;
  181. extern CONST TCHAR* GetYtUSBKey32ErrInfo(IN const long lError);
  182. // 读取所有加密锁信息;
  183. extern void ReadAllClassicYtInfo(IN std::vector<YtUsbInfo*> &vtYtInfo);
  184. // 读取加密锁信息;
  185. extern BOOL ReadYtInfoVer1(IN CONST INT &nUSBStartPos, OUT YtInfoVer1 &Infover1, OUT INT &nUSBPort, OUT CHAR* pszKeyPath = NULL, IN CONST INT &nKeypath = 0);
  186. // 修改加密狗版本1信息;
  187. extern BOOL ModifyYtVer1Info(IN CHAR* pszKeypath, IN YtInfoVer1 &Infover1, IN CONST INT &nModifyType);
  188. // 修改连接数;
  189. extern BOOL ChangeConnectCount(IN CHAR* pszKeypath, IN CONST INT& nCCount);
  190. // 修改域名;
  191. extern BOOL ChangeBranchId(IN CHAR* pszKeypath, IN CONST CHAR* pszBranchId, IN CONST INT& dwShortKey);
  192. // 修改医院跟踪;
  193. extern BOOL ChangeHospital(IN CHAR* pszKeypath, IN BOOL bEnableHospital);
  194. // 修改运行时间;
  195. extern BOOL ChangeRunTime(IN CHAR* pszKeypath, IN CONST DWORD& dwShortKey, IN BOOL bAppend, IN CONST INT& nRunYears, IN CONST INT& nRunMonth, IN CONST INT& nRunDays, IN CONST INT& nRunHours, IN CONST INT& nRunMinutes);
  196. // 修改加密锁版本;
  197. extern BOOL ChangeVersion(IN CHAR* pszKeypath, IN CONST INT& nOldVersion, IN CONST INT& nNewVersion);
  198. // 获取经典版加密锁剩余运行时间;
  199. extern BOOL GetRemainderRunTime(IN CHAR* pszKeypath, IN DWORD dwShortKey, OUT DWORD& dwHasRunTime, OUT DWORD& dwCanRunTime);
  200. // 生成经典版加时授权码;
  201. extern BOOL GenerateRunTimeRegCode(IN CHAR* pszKeypath, IN INT nShortKey, IN CONST INT& nSoftVer, OUT LPTSTR lpRegCode, IN CONST INT& nBufLen);
  202. // 逆向获取加时授权码,获取可运行时间;
  203. extern BOOL GetRunTimeByRegCode(IN CHAR* pszKeypath, IN DWORD dwShortKey, IN CONST INT& nSoftVer, IN LPCTSTR lpRegCode, IN CString& strResult);
  204. // 初始加密锁(完全清除所有内容,空加密锁);
  205. extern BOOL InitEncryptlock(IN const int &nStartUSBPort = 0);
  206. // 清除加密锁信息;
  207. extern BOOL ClearEncryptlockInfo(IN const int &nStartUSBPort = 0);
  208. // 生成指定软件版本的加密锁;
  209. extern BOOL CreateEncryptlockInfo(IN CONST INT &nStartPort, IN EncryptlockInfo &linfo, OUT LPTSTR lpHasRundate, IN CONST size_t &sizeOfhasrundate, OUT LPTSTR lpCouldRundate, IN CONST size_t &sizeOfcouldrundate, IN BOOL bfixedId = FALSE, IN CHAR* pszBranchId = NULL);
  210. // 查找锁,并返回锁短ID,锁版本号,锁物理位置;
  211. extern BOOL FindYtUSB(OUT DWORD &dwShortKey, OUT INT &nVersion, OUT CHAR *pszKeyPath, IN CONST INT &nStartPort = 0);
  212. // 返回计算机上第一个找到的加密锁;
  213. extern BOOL GetFirstYtUSBSoftVer(IN INT &nSoftVer, IN CHAR *pBranchIdBuffer, IN size_t sizeOfBranchIdBuffer, IN CONST INT &nUSBStartPos);
  214. // 获取第一个找到的加密锁;
  215. template<size_t size>
  216. BOOL GetFirstYtUSBSoftVer(IN INT &nSoftVer, IN CHAR(&szBranchId)[size], IN CONST INT &nUSBStartPos)
  217. {
  218. INT nRetval = 0;
  219. INT nVal[8] = { 0 };
  220. DOUBLE fVal[8] = { 0.0 };
  221. CHAR s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  222. BOOL bFind = FALSE;
  223. CHAR szKeyPath[MAX_PATH] = "";
  224. for (INT nIndex = nUSBStartPos; nIndex < 256; nIndex++)
  225. {
  226. memset(szKeyPath, 0, sizeof(szKeyPath));
  227. nRetval = FindPort(nIndex, szKeyPath);
  228. if (nRetval != 0 && nIndex == 0) continue;
  229. if (nRetval != 0) continue;
  230. for (int i = 0; i < 6; i++)
  231. {
  232. // 使用该设备路径锁进行运算;
  233. nRetval = CalEx(g_byShotVersion[i], 10,
  234. &nVal[0], &nVal[1], &nVal[2], &nVal[3], &nVal[4], &nVal[5], &nVal[6], &nVal[7],
  235. &fVal[0], &fVal[1], &fVal[2], &fVal[3], &fVal[4], &fVal[5], &fVal[6], &fVal[7],
  236. s0, s1, s2, s3, s4, s5, s6, s7, szKeyPath, 20000);
  237. //如果正确,则返回该设备路径供以后使用;
  238. if (nRetval == -63) continue;
  239. if ((nRetval == 0) && (nVal[0] == 123))
  240. {
  241. bFind = TRUE;
  242. nSoftVer = i;
  243. if ((nRetval = YtReadString(szBranchId, 297, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  244. {
  245. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  246. }
  247. break;
  248. }
  249. }
  250. if (bFind) break;
  251. }
  252. return bFind;
  253. }
  254. template<size_t tlen>
  255. BOOL ReadClassicYtInfo(IN CONST INT &nUSBStartPos, OUT YtInfoVer1 &Infover1, OUT INT &nUSBPort, OUT CHAR(&pszKeyPath)[tlen])
  256. {
  257. INT nRetval = 0;
  258. INT nVal[8] = { 0 };
  259. DOUBLE fVal[8] = { 0.0 };
  260. CHAR s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  261. BOOL bFind = FALSE;
  262. CHAR szKeyPath[MAX_PATH] = "";
  263. for (INT nIndex = nUSBStartPos; nIndex < 256; nIndex++)
  264. {
  265. memset(szKeyPath, 0, sizeof(szKeyPath));
  266. nRetval = FindPort(nIndex, szKeyPath);
  267. if (nRetval != 0 && nIndex == 0) continue;
  268. if (nRetval != 0) continue;
  269. for (int i = 0; i < 6; i++)
  270. {
  271. // 使用该设备路径锁进行运算;
  272. nRetval = CalEx(g_byShotVersion[i], 10,
  273. &nVal[0], &nVal[1], &nVal[2], &nVal[3], &nVal[4], &nVal[5], &nVal[6], &nVal[7],
  274. &fVal[0], &fVal[1], &fVal[2], &fVal[3], &fVal[4], &fVal[5], &fVal[6], &fVal[7],
  275. s0, s1, s2, s3, s4, s5, s6, s7, szKeyPath, 20000);
  276. //如果正确,则返回该设备路径供以后使用;
  277. if (nRetval == -63) continue;
  278. if ((nRetval == 0) && (nVal[0] == 123))
  279. {
  280. nUSBPort = nIndex;
  281. if (pszKeyPath)
  282. sprintf_s(pszKeyPath, "%s", szKeyPath);
  283. bFind = TRUE;
  284. Infover1.nSoftVer = i;
  285. // 获取加密锁座席数量;
  286. if ((nRetval = YtReadString(Infover1.szCCount, 264, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  287. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  288. // 获取加密锁域名值;
  289. if ((nRetval = YtReadString(Infover1.szBranchId, 297, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  290. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  291. // 获取医院跟踪系统;
  292. if ((nRetval = YtReadString(Infover1.szHospital, 330, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  293. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  294. // 返回加密锁已运行时间;
  295. if ((nRetval = GetRunTimer(Infover1.szHasRunyears, Infover1.szHasRunmonths, Infover1.szHasRundays, Infover1.szHasRunhours, Infover1.szHasRunminutes, Infover1.szHasRunseconds, szKeyPath)) != 0)
  296. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  297. // 返回加密锁可运行时间;
  298. DWORD dwShortID = 0; // 锁短ID;
  299. CHAR szOutString[100] = { 0 };
  300. CHAR HKey[50] = { 0 }, LKey[50] = { 0 };
  301. // 30000以后的储存空间为公共区域;
  302. if ((nRetval = ReadTimeAuthFromEprom(HKey, LKey, szOutString, &dwShortID, 30128, "FFFFFFFF", "FFFFFFFF", szKeyPath)) != 0)
  303. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  304. std::string str = szOutString;
  305. int nStrPos = str.find("年");
  306. if (nStrPos != std::string::npos)
  307. {
  308. sprintf_s(Infover1.szCanRunyears, "%s", str.substr(0, nStrPos).c_str());
  309. str = str.substr(nStrPos + strlen("年"));
  310. nStrPos = str.find("月");
  311. sprintf_s(Infover1.szCanRunmonths, "%s", str.substr(0, nStrPos).c_str());
  312. str = str.substr(nStrPos + strlen("月"));
  313. nStrPos = str.find("日");
  314. sprintf_s(Infover1.szCanRundays, "%s", str.substr(0, nStrPos).c_str());
  315. str = str.substr(nStrPos + strlen("日"));
  316. nStrPos = str.find("小时");
  317. sprintf_s(Infover1.szCanRunhours, "%s", str.substr(0, nStrPos).c_str());
  318. str = str.substr(nStrPos + strlen("小时"));
  319. nStrPos = str.find("分钟");
  320. sprintf_s(Infover1.szCanRunminutes, "%s", str.substr(0, nStrPos).c_str());
  321. //str = str.substr(nStrPos + strlen("分钟"));
  322. }
  323. break;
  324. }
  325. }
  326. if (bFind) break;
  327. }
  328. return bFind;
  329. }
  330. // 生成指定软件版本的加密锁;
  331. template< size_t sizeOfhasrundate, size_t sizeofCouldrundate >
  332. BOOL CreateEncryptlockInfo(IN CONST INT &nStartPort, IN EncryptlockInfo &linfo, OUT TCHAR(&szHasRundate)[sizeOfhasrundate], OUT TCHAR(&szCouldRundate)[sizeofCouldrundate], IN BOOL bfixedId = FALSE, IN CHAR* pszBranchId = NULL);
  333. template< size_t sizeOfhasrundate, size_t sizeofCouldrundate >
  334. BOOL CreateEncryptlockInfo(IN CONST INT &nStartPort, IN EncryptlockInfo &linfo, OUT TCHAR(&szHasRundate)[sizeOfhasrundate], OUT TCHAR(&szCouldRundate)[sizeofCouldrundate], IN BOOL bfixedId /*= FALSE*/, IN CHAR* pszBranchId /*= NULL*/)
  335. {
  336. int nRet = -1;
  337. DWORD dwShortKey = 0;
  338. int nVersion = -1;
  339. CHAR szKeyPath[MAX_PATH] = { 0 };
  340. if (!FindYtUSB(dwShortKey, nVersion, szKeyPath, nStartPort))
  341. return FALSE;
  342. if (dwShortKey == -1)
  343. {
  344. // 不是域天智能锁;
  345. return FALSE;
  346. }
  347. nRet = SetReadPassword("FFFFFFFF", "FFFFFFFF", g_pHReadPassWord, g_pLReadPassWord, szKeyPath);
  348. if (nRet != 0) {
  349. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  350. }
  351. nRet = SetWritePassword("FFFFFFFF", "FFFFFFFF", g_pHWritePassWord, g_pLWritePassWord, szKeyPath);
  352. if (nRet != 0) {
  353. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  354. }
  355. // 从地址0~231+32,是所有加密锁共同内容;
  356. for (int i = 0; i < 8; i++)
  357. {
  358. if ((nRet = YtWriteString(g_szRom[i], i * 33, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  359. {
  360. // 写区域错误;
  361. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  362. }
  363. }
  364. // 264是座席数量;
  365. if (linfo.nCCount > 0)
  366. {
  367. CHAR szCCount[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  368. sprintf_s(szCCount, "%d", linfo.nCCount);
  369. if ((nRet = YtWriteString(szCCount, 264, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  370. {
  371. // 设置座席数失败;
  372. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  373. return FALSE;
  374. }
  375. }
  376. // 297是域名值;
  377. // 生成域名串 = 日期 + 短ID;
  378. CHAR szDomain[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  379. if (bfixedId && pszBranchId && pszBranchId[0] != '\0')
  380. {
  381. sprintf_s(szDomain, pszBranchId);
  382. }
  383. else
  384. {
  385. CTime tt = CTime::GetCurrentTime();
  386. sprintf_s(szDomain, "%04d%02d%02d%02d%02d%02d%d.ly.com", tt.GetYear(), tt.GetMonth(), tt.GetDay(), tt.GetHour(), tt.GetMinute(), tt.GetSecond(), dwShortKey);
  387. }
  388. if ((nRet = YtWriteString(szDomain, 297, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  389. {
  390. // 生成域名错误;
  391. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  392. return FALSE;
  393. }
  394. // 330是医院跟踪系统;
  395. if (linfo.bHospital)
  396. {
  397. CHAR szHospital[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  398. sprintf_s(szHospital, "%d", linfo.bHospital);
  399. if ((nRet = YtWriteString(szHospital, 330, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  400. {
  401. // 设置医院跟踪系统失败;
  402. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  403. return FALSE;
  404. }
  405. }
  406. // 生成指定软件版本加密解密密钥;
  407. switch (linfo.nSoftVer)
  408. {
  409. case EN_OCHILD:
  410. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_OCHILD][0], g_szEncKey[EN_OCHILD][1], g_szEncKey[EN_OCHILD][2], g_szEncKey[EN_OCHILD][3], szKeyPath);
  411. break;
  412. case EN_LCHILD:
  413. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_LCHILD][0], g_szEncKey[EN_LCHILD][1], g_szEncKey[EN_LCHILD][2], g_szEncKey[EN_LCHILD][3], szKeyPath);
  414. break;
  415. case EN_ECHILD:
  416. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_ECHILD][0], g_szEncKey[EN_ECHILD][1], g_szEncKey[EN_ECHILD][2], g_szEncKey[EN_ECHILD][3], szKeyPath);
  417. break;
  418. case EN_OWDDING:
  419. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_OWDDING][0], g_szEncKey[EN_OWDDING][1], g_szEncKey[EN_OWDDING][2], g_szEncKey[EN_OWDDING][3], szKeyPath);
  420. break;
  421. case EN_LWDDING:
  422. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_LWDDING][0], g_szEncKey[EN_LWDDING][1], g_szEncKey[EN_LWDDING][2], g_szEncKey[EN_LWDDING][3], szKeyPath);
  423. break;
  424. case EN_EWDDING:
  425. nRet = WriteEncKey("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", g_szEncKey[EN_EWDDING][0], g_szEncKey[EN_EWDDING][1], g_szEncKey[EN_EWDDING][2], g_szEncKey[EN_EWDDING][3], szKeyPath);
  426. break;
  427. }
  428. if (nRet != 0)
  429. {
  430. // 生成密钥失败;
  431. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  432. return FALSE;
  433. }
  434. //////////////////////////////////////////////////////////////////////////
  435. // 授权时间码;
  436. CHAR szyear[10] = { 0 }, szmonth[10] = { 0 }, szday[10] = { 0 }, szhour[10] = { 0 }, szminute[10] = { 0 }, szsecond[10] = { 0 };
  437. if ((nRet = GetRunTimer(szyear, szmonth, szday, szhour, szminute, szsecond, szKeyPath)) != 0)
  438. {
  439. // 获取运行时间失败;
  440. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  441. return FALSE;
  442. }
  443. _stprintf_s(szHasRundate, _T("已运行 %d年%d月%d天%d时%d分"), atoi(szyear), atoi(szmonth), atoi(szday), atoi(szhour), atoi(szminute));
  444. if (linfo.bAdddate) // 追加时间;
  445. {
  446. sprintf_s(szyear, "%d", atoi(linfo.szRunyears) + atoi(szyear));
  447. sprintf_s(szmonth, "%d", atoi(linfo.szRunmonths) + atoi(szmonth));
  448. sprintf_s(szday, "%d", atoi(linfo.szRundays) + atoi(szday));
  449. sprintf_s(szhour, "%d", atoi(linfo.szRunhours) + atoi(szhour));
  450. sprintf_s(szminute, "%d", atoi(linfo.szRunminutes) + atoi(szminute));
  451. }
  452. else
  453. {
  454. sprintf_s(szyear, "%s", linfo.szRunyears);
  455. sprintf_s(szmonth, "%s", linfo.szRunmonths);
  456. sprintf_s(szday, "%s", linfo.szRundays);
  457. sprintf_s(szhour, "%s", linfo.szRunhours);
  458. sprintf_s(szminute, "%s", linfo.szRunminutes);
  459. }
  460. // 生成时间授权码;
  461. CHAR szOutString[100] = { 0 }; // 返回的时间授权码;
  462. if ((nRet = MakeTimerAuth(g_szUserKey, dwShortKey, szyear, szmonth, szday, szhour, szminute, szOutString, szKeyPath)) != 0)
  463. {
  464. // 生成时间授权码失败;
  465. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  466. return FALSE;
  467. }
  468. CHAR HKey[9] = "FFFFFFFF", LKey[9] = "FFFFFFFF";
  469. CHAR WHKey[41] = "0", WLKey[41] = "0";
  470. memcpy(WHKey, szOutString, 40);
  471. memcpy(WLKey, &szOutString[40], 40);
  472. // 写授权时间到加密锁中;
  473. if ((nRet = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, dwShortKey, szyear, szmonth, szday, szhour, szminute, szKeyPath)) != 0)
  474. {
  475. // 写授权时间失败;
  476. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  477. return FALSE;
  478. }
  479. DWORD dwID;
  480. // 30000以后的储存空间为公共区域;
  481. if ((nRet = ReadTimeAuthFromEprom(WHKey, WLKey, szOutString, &dwID, 30128, "FFFFFFFF", "FFFFFFFF", szKeyPath)) == 0)
  482. {
  483. #ifdef UNICODE
  484. WCHAR *pOutString = ascii2unicode(szOutString);
  485. _stprintf_s(szCouldRundate, _T("%s"), pOutString);
  486. delete pOutString;
  487. pOutString = NULL;
  488. #else
  489. _stprintf_s(szCouldRundate, _T("%s"), szOutString);
  490. #endif
  491. }
  492. else
  493. {
  494. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  495. }
  496. return TRUE;
  497. }
  498. };
  499. #endif