YtDongle.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. #include "StdAfx.h"
  2. #include "YtDongle.h"
  3. #include <strsafe.h>
  4. namespace YtDongle
  5. {
  6. CHAR *g_pHReadPassWord = NULL;
  7. CHAR *g_pLReadPassWord = NULL;
  8. CHAR *g_pHWritePassWord = NULL;
  9. CHAR *g_pLWritePassWord = NULL;
  10. BOOL g_bUSE_NEWPASSWORD = FALSE;
  11. // 加密解密密钥;
  12. CHAR *g_szEncKey[][4] = {
  13. { "5A11475E", "39F530AD", "DCE97937", "6BCDB275" }, // 儿童全能版;
  14. { "04BBE109", "E3AFEA47", "778414D1", "16785D1F" }, // 儿童座席版;
  15. { "4900364D", "28E42F9C", "CBD86826", "5ACCA264" }, // 儿童企业版;
  16. { "BA7DA71F", "A17DB814", "C411F1AE", "A34531FD" }, // 婚纱全能版;
  17. { "F3A690F8", "828AD936", "667E03C0", "05674C0E" }, // 婚纱座席版;
  18. { "EC9FC9E1", "773E7E16", "0612A764", "A907E0F2" } // 婚纱企业版;
  19. };
  20. CHAR *g_szRom[] = {
  21. "9E5B96F2223FCF8CC12308DABF669CB4", // 000
  22. "873A748B773F7E261623B775A907F0F3", // 033
  23. "7C2359705B1752BEEEFB9B4816785D2F", // 066
  24. "4EF5EF37D1D91881B0CD5D1F44B19659", // 099
  25. "CA7DA7CF9951A0493845DA97DC391325", // 132
  26. "1CD3CD15BFB7F66F9EAB3BFD118E6326", // 165
  27. "3EE5DF32D1991480607D5D0E4F614658", // 198
  28. "4FB2FC03EEAA2592819E2EDC1072676A" // 231
  29. // 264 是座席数使用的地址;
  30. // 297 是域名值使用的地址;
  31. // 330 是医院系统使用的地址;
  32. };
  33. CHAR *g_szPassword[][2] = {
  34. //////////////////////////////////////////////////////////////////////////
  35. // 旧密码;
  36. { "7528527A", "541C5CF4" }, // 读密码 高低;
  37. { "E4F08542", "87E5CED0" }, // 写密码 高低;
  38. //////////////////////////////////////////////////////////////////////////
  39. // 新密码;
  40. { "9201B009", "26B43D72" }, // 读密码 高低;
  41. { "AA679BD9", "302B1952" } // 写密码 高低;
  42. };
  43. // 用户自定义密钥;
  44. CHAR *g_szUserKey = { "20D30D15FFB7F6AF9EAB30FD229F797B" };
  45. //////////////////////////////////////////////////////////////////////////
  46. // 锁内存数据;
  47. BYTE g_byShotVersion[][10] =
  48. {
  49. { 0x06, 0x00, 0xC2, 0xC7, 0xD2, 0x43, 0xB9, 0x01, 0x8A, 0xC3 }, // 儿童全能版;
  50. { 0x06, 0x00, 0x94, 0x0B, 0xCD, 0x32, 0x04, 0xAB, 0x20, 0x27 }, // 儿童座席版;
  51. { 0x06, 0x00, 0x04, 0xBB, 0x67, 0x0A, 0x3B, 0xA9, 0xF0, 0xDC }, // 儿童企业版;
  52. { 0x06, 0x00, 0xBC, 0x91, 0x64, 0x2F, 0x9A, 0xB1, 0x22, 0xCD }, // 婚纱全能版;
  53. { 0x06, 0x00, 0x04, 0x1D, 0x18, 0xF7, 0xBD, 0x5F, 0x53, 0x4C }, // 婚纱座席版;
  54. { 0x06, 0x00, 0x89, 0xA0, 0xE6, 0xAD, 0xCA, 0x02, 0x75, 0x8E } // 婚纱企业版;
  55. };
  56. //////////////////////////////////////////////////////////////////////////
  57. // 用于计算经典版加密锁加时授权码;
  58. BYTE g_byTimeRegCode[][58] =
  59. {
  60. { 0x31, 0x00, 0xAF, 0xD1, 0x1C, 0x68, 0x93, 0xA7, 0x92, 0x7D, 0xCE, 0x5B, 0xB9, 0x0A, 0xD7, 0xA8, 0x7F, 0x4F, 0x58, 0x3F, 0x40, 0xC8, 0xBB, 0xEA, 0xE6, 0x42, 0x74, 0xFC, 0x67,
  61. 0xE8, 0x54, 0x89, 0x85, 0x15, 0x4F, 0xE2, 0x96, 0x78, 0x00, 0xB7, 0x75, 0x2D, 0xC4, 0x03, 0xFB, 0x13, 0x5C, 0xD0, 0x0C, 0x77, 0xFF, 0xCA, 0x8D, 0x4F, 0xDC, 0xAC, 0x6E, 0xED }, // 儿童全能版;
  62. { 0x31, 0x00, 0x75, 0xE7, 0xAF, 0x0E, 0xB8, 0x60, 0x75, 0xFD, 0xE1, 0x79, 0xE3, 0x7E, 0x1F, 0x9E, 0x85, 0xD0, 0xD5, 0xB0, 0xFD, 0x94, 0xE3, 0x10, 0xC8, 0x02, 0x0C, 0xC5, 0x6B,
  63. 0x4E, 0x6B, 0xE7, 0xBA, 0x9E, 0x18, 0xDD, 0xE8, 0x79, 0x04, 0xB9, 0x9E, 0x4D, 0xA2, 0x32, 0xE1, 0x60, 0x13, 0x22, 0xA1, 0xA4, 0xB7, 0x68, 0xB3, 0xD6, 0x75, 0xD9, 0xAE, 0x33 }, // 儿童座席版;
  64. { 0x31, 0x00, 0xDB, 0x65, 0x89, 0x92, 0x8A, 0xD1, 0xFE, 0x64, 0x86, 0x45, 0x1C, 0x50, 0x0F, 0xBD, 0x06, 0x93, 0x23, 0x56, 0xC2, 0x9F, 0x8A, 0xC8, 0xEE, 0x5F, 0x3C, 0x52, 0x57,
  65. 0x89, 0x3B, 0x03, 0x5A, 0x30, 0x43, 0xB5, 0xE4, 0x94, 0xBC, 0xE4, 0x0C, 0xB2, 0x92, 0xD5, 0x09, 0x89, 0xE9, 0x45, 0xD7, 0x4B, 0xF8, 0x30, 0xBA, 0xE6, 0x4A, 0x13, 0x9A, 0xCB }, // 儿童企业版;
  66. { 0x31, 0x00, 0x81, 0x42, 0x2A, 0x16, 0x26, 0x48, 0xEE, 0x90, 0xEA, 0xDD, 0xEC, 0xCA, 0x93, 0xFF, 0x3C, 0x12, 0x06, 0x76, 0xA9, 0xE5, 0xA9, 0xDE, 0xF9, 0x69, 0x9B, 0x19, 0xB8,
  67. 0x1D, 0xD5, 0x05, 0x33, 0x5A, 0x59, 0x20, 0x50, 0xC9, 0x3D, 0x12, 0x61, 0xFD, 0xF0, 0x9E, 0x85, 0xAE, 0x89, 0xF8, 0x49, 0x41, 0x02, 0xA6, 0x95, 0x82, 0x3A, 0xE7, 0xC6, 0x4E }, // 婚纱全能版;
  68. { 0x31, 0x00, 0xE6, 0xB3, 0x38, 0x6D, 0xB3, 0x13, 0xFD, 0xF1, 0x23, 0x5F, 0x4C, 0xEA, 0xA3, 0x1D, 0xB8, 0xA2, 0x47, 0xB4, 0xAC, 0x97, 0xB1, 0xF0, 0x29, 0x38, 0x6E, 0x87, 0x44,
  69. 0xCA, 0x91, 0x85, 0x02, 0x0F, 0xCC, 0x59, 0x94, 0x28, 0x08, 0x76, 0x40, 0x5E, 0xD1, 0xA1, 0x75, 0x5B, 0x6B, 0xCA, 0xEE, 0x7B, 0x90, 0xE0, 0xDD, 0xFF, 0x47, 0x4A, 0xA9, 0x86 }, // 婚纱座席版;
  70. { 0x31, 0x00, 0x0E, 0x64, 0x83, 0x39, 0xA6, 0x51, 0x31, 0xB6, 0xF3, 0x16, 0x16, 0xB9, 0xCE, 0x78, 0x4B, 0x43, 0x85, 0xBF, 0x97, 0x47, 0x98, 0x0E, 0x5D, 0x9E, 0x3D, 0x41, 0x18,
  71. 0x1B, 0xF8, 0xC6, 0xBE, 0xDC, 0xF9, 0xB8, 0x18, 0x8D, 0x0D, 0x90, 0x9F, 0xB2, 0x70, 0xBE, 0x49, 0xA1, 0xAF, 0x9B, 0x6B, 0x80, 0x8C, 0xDF, 0x8F, 0x5B, 0xEC, 0xBD, 0xBE, 0xF4 } // 婚纱企业版;
  72. };
  73. // 用于解密加时授权码regcode;
  74. BYTE g_byDecryptRegCode[58] = { 0x31, 0x00, 0x81, 0x42, 0x2A, 0x16, 0x26, 0x48, 0xEE, 0x90, 0xEA, 0xDD, 0xEC, 0xCA, 0x93, 0xFF, 0x3C, 0x12, 0x06, 0x76, 0xA9, 0xE5, 0xA9, 0xDE, 0xF9, 0x69, 0x9B, 0x19,
  75. 0xB8, 0x1D, 0xD5, 0x05, 0x33, 0x5A, 0x13, 0x18, 0xB0, 0xF0, 0x77, 0xEF, 0xE9, 0x9B, 0xEA, 0x9C, 0x2D, 0xBF, 0x59, 0x53, 0x5C, 0x7B, 0x02, 0xA6, 0x95, 0x82, 0x3A, 0xE7, 0xC6, 0x4E };
  76. // start---------------加密表达式加密后的数组----------------------;
  77. CONST BYTE g_byCalExVersion[][114] =
  78. {
  79. // 儿童全能版;
  80. { 0x6D, 0x00, 0x1A, 0xDE, 0x00, 0xEF, 0xC7, 0xC7, 0xBC, 0xE1, 0xB4, 0xA8, 0xB2, 0xD0, 0x15, 0x4F, 0x3E, 0x5A, 0x33, 0x1F, 0x58, 0x80, 0xB4, 0x69, 0x35, 0x89, 0xE6, 0xFE, 0xF4,
  81. 0x32, 0xC3, 0x31, 0xA7, 0x8F, 0xA8, 0x7D, 0x82, 0x7D, 0x08, 0x49, 0xE0, 0x78, 0x50, 0x5F, 0xB2, 0x31, 0x2C, 0x9E, 0x26, 0x26, 0xF7, 0xA9, 0x3E, 0xBB, 0x77, 0xC0, 0x4D, 0xC2,
  82. 0x76, 0xF6, 0x85, 0xF1, 0x9D, 0x3E, 0x90, 0x18, 0x5E, 0xAD, 0x31, 0xC0, 0x2E, 0xFA, 0xF9, 0xEF, 0x52, 0x4E, 0x87, 0x03, 0x56, 0x9A, 0x08, 0x87, 0xB4, 0xA8, 0xB2, 0xD0, 0x15,
  83. 0x4F, 0x3E, 0x5A, 0x33, 0x1F, 0x58, 0x80, 0xB4, 0x69, 0x35, 0x89, 0xE6, 0xFE, 0xF4, 0x32, 0xC3, 0x31, 0xA7, 0x8F, 0xF1, 0xD6, 0x26, 0xB4, 0xC6, 0x03, 0x9E, 0xA5 },
  84. // 儿童座席版;
  85. { 0x6D, 0x00, 0x5A, 0x0F, 0x6C, 0x8A, 0x25, 0xBE, 0x52, 0x08, 0x14, 0xFC, 0x20, 0xA2, 0x07, 0x08, 0xFE, 0xFF, 0x38, 0xF5, 0xC2, 0x04, 0x2E, 0x78, 0x31, 0x78, 0x9C, 0x1B, 0x11,
  86. 0xA4, 0xD9, 0x4F, 0xA7, 0x92, 0xC5, 0x45, 0x37, 0x75, 0xC5, 0x95, 0x2A, 0xD9, 0x97, 0xC3, 0xFE, 0x91, 0xBB, 0xC5, 0xE8, 0xBC, 0x72, 0xDF, 0x28, 0xE5, 0x97, 0xF5, 0x74, 0xB1,
  87. 0x8D, 0x5E, 0x86, 0x0E, 0x0D, 0xA9, 0xA5, 0x5E, 0x05, 0xD8, 0xEB, 0x3C, 0xB0, 0x26, 0xAE, 0x79, 0xBB, 0xAE, 0x10, 0x1E, 0x11, 0x14, 0xF6, 0x22, 0x14, 0xFC, 0x20, 0xA2, 0x07,
  88. 0x08, 0xFE, 0xFF, 0x38, 0xF5, 0xC2, 0x04, 0x2E, 0x78, 0x31, 0x78, 0x9C, 0x1B, 0x11, 0xA4, 0xD9, 0x4F, 0xA7, 0x92, 0x8F, 0x84, 0xDB, 0xAD, 0xD3, 0x02, 0x63, 0xB4 },
  89. // 儿童企业版;
  90. { 0x6D, 0x00, 0xE5, 0x24, 0xDF, 0xDE, 0xD5, 0x2E, 0x46, 0x37, 0xF0, 0xCF, 0xED, 0x4B, 0xE2, 0x44, 0x85, 0x64, 0x2A, 0x77, 0x59, 0x83, 0x4F, 0x68, 0x9E, 0x11, 0xAC, 0xEF, 0x04,
  91. 0x9E, 0xC9, 0x33, 0x3E, 0x33, 0x5E, 0xE8, 0x0E, 0x7C, 0x51, 0x40, 0x64, 0x8D, 0xBB, 0x55, 0x9C, 0x3B, 0xCD, 0x74, 0xC8, 0x18, 0x6C, 0xDA, 0x91, 0x16, 0x07, 0x24, 0x2D, 0x07,
  92. 0x9C, 0xFF, 0xAA, 0x82, 0xA5, 0x8C, 0x63, 0xD8, 0x78, 0x48, 0xAB, 0xC4, 0x1B, 0x31, 0x8A, 0xC7, 0x89, 0xF6, 0xD6, 0xF7, 0x79, 0x72, 0xD7, 0xC7, 0xF0, 0xCF, 0xED, 0x4B, 0xE2,
  93. 0x44, 0x85, 0x64, 0x2A, 0x77, 0x59, 0x83, 0x4F, 0x68, 0x9E, 0x11, 0xAC, 0xEF, 0x04, 0x9E, 0xC9, 0x33, 0x3E, 0x33, 0xF8, 0xD6, 0x1B, 0xFE, 0xDD, 0xD0, 0xB5, 0xD1 },
  94. // 婚纱全能版;
  95. { 0x6D, 0x00, 0x8B, 0x91, 0xA3, 0xB0, 0x42, 0x12, 0xCF, 0x4F, 0xAC, 0xC8, 0x0C, 0x7C, 0x59, 0x97, 0xF8, 0xEE, 0x1A, 0x55, 0x89, 0x92, 0x77, 0x3A, 0x4C, 0xC2, 0x97, 0xEF, 0xCC,
  96. 0x68, 0x12, 0xA6, 0xD0, 0x36, 0x25, 0x55, 0x03, 0xAE, 0x1C, 0x4A, 0x9A, 0x9C, 0x78, 0xC2, 0x08, 0x70, 0x4F, 0x2A, 0x1B, 0x59, 0x51, 0x5F, 0xEE, 0x4A, 0x3B, 0xC7, 0xA0, 0x65,
  97. 0x75, 0xB3, 0x33, 0x8A, 0x46, 0xB0, 0xEF, 0xB6, 0xA0, 0xD4, 0x0B, 0x21, 0xE0, 0x4A, 0x9B, 0x8F, 0xD8, 0x0A, 0xDC, 0x47, 0x08, 0xA8, 0x12, 0xAF, 0xAC, 0xC8, 0x0C, 0x7C, 0x59,
  98. 0x97, 0xF8, 0xEE, 0x1A, 0x55, 0x89, 0x92, 0x77, 0x3A, 0x4C, 0xC2, 0x97, 0xEF, 0xCC, 0x68, 0x12, 0xA6, 0xD0, 0x36, 0x72, 0x76, 0xB5, 0x18, 0xFC, 0x29, 0xF6, 0x58 },
  99. // 婚纱座席版;
  100. { 0x6D, 0x00, 0x80, 0x0D, 0xA4, 0x8F, 0xFC, 0x57, 0x1E, 0x30, 0x14, 0x15, 0x91, 0x72, 0xA0, 0x60, 0x31, 0x7F, 0xB5, 0x20, 0x90, 0xD5, 0x6D, 0x63, 0x8E, 0xDB, 0x47, 0x1A, 0x16,
  101. 0xDC, 0xB1, 0xB3, 0xBF, 0x52, 0x8A, 0x2D, 0xAD, 0xA0, 0x09, 0x53, 0xA2, 0x6A, 0xB6, 0xAF, 0x2F, 0x5C, 0xD6, 0x4E, 0x5D, 0x15, 0xCA, 0xA5, 0xA7, 0xC8, 0xC6, 0xAC, 0xDA, 0x4A,
  102. 0xEC, 0xC2, 0xC2, 0xE4, 0x28, 0x1B, 0x5F, 0x3C, 0xA0, 0xAD, 0x42, 0xB9, 0xB2, 0x07, 0x9F, 0xDC, 0x3A, 0x47, 0x8C, 0x13, 0x14, 0x25, 0x42, 0x54, 0x14, 0x15, 0x91, 0x72, 0xA0,
  103. 0x60, 0x31, 0x7F, 0xB5, 0x20, 0x90, 0xD5, 0x6D, 0x63, 0x8E, 0xDB, 0x47, 0x1A, 0x16, 0xDC, 0xB1, 0xB3, 0xBF, 0x52, 0xE8, 0xB6, 0x2D, 0x1B, 0x0D, 0xC3, 0xE1, 0xCC },
  104. // 婚纱企业版;
  105. { 0x6D, 0x00, 0x5E, 0xDC, 0x28, 0xB6, 0x1E, 0x78, 0x38, 0xC1, 0x4E, 0x65, 0x01, 0x90, 0x44, 0xCE, 0xC0, 0x34, 0x43, 0x09, 0xF3, 0x14, 0x09, 0xC3, 0x99, 0x0F, 0x16, 0xD9, 0xF3,
  106. 0x4F, 0xB1, 0x16, 0x18, 0xAB, 0xB9, 0x9D, 0xAC, 0x43, 0x75, 0x7C, 0x99, 0xA5, 0x03, 0x29, 0xDA, 0x2F, 0x95, 0x96, 0x30, 0x98, 0x4B, 0xFA, 0xCC, 0xFD, 0x5C, 0x35, 0x79, 0x93,
  107. 0xF2, 0x8C, 0x50, 0x42, 0x22, 0xC2, 0x10, 0x6D, 0xED, 0x11, 0xDE, 0xA1, 0x60, 0x08, 0x0B, 0xC2, 0x3A, 0x2D, 0x56, 0x0F, 0xCF, 0x79, 0xF7, 0x68, 0x4E, 0x65, 0x01, 0x90, 0x44,
  108. 0xCE, 0xC0, 0x34, 0x43, 0x09, 0xF3, 0x14, 0x09, 0xC3, 0x99, 0x0F, 0x16, 0xD9, 0xF3, 0x4F, 0xB1, 0x16, 0x18, 0xAB, 0x7A, 0xF3, 0xBE, 0x92, 0x4D, 0xDE, 0xD0, 0x81 }
  109. };
  110. // endof---------------加密表达式加密后的数组----------------------;
  111. CONST YtError g_YtError[] = {
  112. { -1, _T("未找到返回结果变量\n") },
  113. { -2, _T("未找到 = 符号\n") },
  114. { -3, _T("代表没有找到相应常数\n") },
  115. //{-4, _T("未找到返回结果变量\n")},
  116. { -5, _T("代表找不到字符串的第一个双引号\n") },
  117. { -6, _T("代表找不到字符串的第二个双引号\n") },
  118. { -7, _T("IF语句没有找到goto字符\n") },
  119. { -8, _T("IF语句没有找到第一个比较字符\n") },
  120. { -9, _T("IF语句没有找到比较符号\n") },
  121. { -10, _T("两边变量类型不相符\n") },
  122. { -11, _T("没有找到NOT符号\n") },
  123. { -12, _T("不是整形变量\n") },
  124. { -13, _T("代表没有找到相应整形常数\n") },
  125. { -14, _T("代表没有找到相应字符串常数\n") },
  126. { -15, _T("代表没有找到相应浮点常数\n") },
  127. { -16, _T("代表不支持这个运算\n") },
  128. { -17, _T("代表没有左边括号\n") },
  129. { -18, _T("代表没有变量\n") },
  130. { -19, _T("代表没“,”\n") },
  131. { -20, _T("代表没有右边括号\n") },
  132. { -21, _T("代表常数超过指这定的范围\n") },
  133. { -22, _T("代表储存器的地址超过指定的范围,整数不能超过EEPROM_LEN-4,浮点不能超过EEPROM_LEN-8\n") },
  134. { -23, _T("代表储存器的地址超过指定的范围,字符串不能超过EEPROM_LEN-LEN,其中LEN为字符串的长度\n") },
  135. { -24, _T("除法中,被除数不能为0\n") },
  136. { -25, _T("未知错误\n") },
  137. { -26, _T("第二个变量不在指定的位置\n") },
  138. { -27, _T("字符串常量超过指定的长度\n") },
  139. { -28, _T("不是字符串变量\n") },
  140. { -29, _T("没有第三个变量\n") },
  141. { -30, _T("GOTO的标识语句不能全为数字\n") },
  142. { -31, _T("不能打开ENC文件\n") },
  143. { -32, _T("不能读ENC文件\n") },
  144. { -33, _T("GOTO CALL不能找到指定的跳转位置\n") },
  145. { -34, _T("智能卡运算中,未知数据类型\n") },
  146. { -35, _T("智能卡运算中,未知代码类型\n") },
  147. { -36, _T("字符串长度超出50\n") },
  148. { -37, _T("操作时超长,负长\n") },
  149. { -38, _T("标识重复\n") },
  150. { -39, _T("程序堆栈溢出\n") },
  151. { -40, _T("堆栈溢出\n") },
  152. { -41, _T("不能建立编译文件,请查看文件是否有只读属性,或被其它文件打开\n") },
  153. { -42, _T("不能写文件,请查看文件是否有只读属性,或被其它文件打开\n") },
  154. { -43, _T("程序被中途使用END语句结束\n") },
  155. { -44, _T("程序跳转到外部的空间\n") },
  156. { -45, _T("传送数据失败\n") },
  157. { -46, _T("程序超出运算次数,可能是死循环\n") },
  158. { -47, _T("写密码不正确\n") },
  159. { -48, _T("读密码不正确\n") },
  160. { -49, _T("读写EEPROM时,地址溢出\n") },
  161. { -50, _T("USB操作失败,可能是没有找到相关的指令\n") },
  162. { -51, _T("打开USB文件句柄失败\n") },
  163. { -52, _T("使用加密锁加密自定义表达式,生成加密代码时生产错误\n") },
  164. { -53, _T("无法打开usb设备,可能驱动程序没有安装或没有插入加密锁\n") },
  165. //{-54, _T("未找到返回结果变量\n")},
  166. { -55, _T("要加密的数据少于8个字节\n") },
  167. { -56, _T("返回结果变量错误\n") },
  168. { -57, _T("初始化密钥错误\n") },
  169. { -58, _T("e密钥或n模不能为0\n") },
  170. { -59, _T("初始化MD5错误\n") },
  171. { -60, _T("MD5运算错误\n") },
  172. { -61, _T("计算MD5结果时错误\n") },
  173. { -62, _T("授权次数溢出,不能再进行授权\n") },
  174. { -63, _T("不能打开指定的文件\n") },
  175. { -64, _T("不能建立指定的文件\n") },
  176. { -65, _T("验证码错误,可能是输入解密密钥错误,或注册授权码错误\n") },
  177. { -66, _T("执行TIMEOUT函数时,输入的ID与锁ID不相符\n") },
  178. { -67, _T("执行TIMEOUT函数时,智能卡运行函数已到期\n") },
  179. { -68, _T("操作浮点运算时,输入的参数将会导致返回值是一个无穷值\n") },
  180. { -69, _T("代表没足够的变量参数\n") },
  181. { -70, _T("返回变量与函数不相符\n") },
  182. { -71, _T("浮点数转换字符串时,要转换的数据太大\n") },
  183. { -72, _T("初始化服务器错误\n") },
  184. { -73, _T("对缓冲区进行MD5运算时错误\n") },
  185. { -74, _T("MD5验证IPVAR错误\n") },
  186. { -75, _T("MD5验证IPCount错误\n") },
  187. { -76, _T("没有找到对应的SOCKET连接\n") },
  188. { -77, _T("没有找到要删除的对应的SOCKET连接\n") },
  189. { -78, _T("没有找到要删除的对应的功能模块号连接\n") },
  190. { -79, _T("没有找到要增加的对应的功能模块号连接\n") },
  191. { -80, _T("用户数已超过限制的授权数量\n") },
  192. { -81, _T("找不到对应的INI文件条目\n") },
  193. { -82, _T("没有进行初始化服务工作\n") },
  194. { -83, _T("ref不能应用于常数\n") },
  195. { -84, _T("代表使用scall,ccall等指令时,传递的参数太多\n") },
  196. { -85, _T("表示调用scall,ccall,sloadlib,cloadlib等指令时,不能返回运行代码\n") },
  197. { -86, _T("表示调用scall,ccall,sloadlib,cloadlib等指令时,不能将结果变量返回\n") },
  198. { -87, _T("表示调用外部DLL时,不能读取指定的DLL\n") },
  199. { -88, _T("表示调用外部DLL时,不能获取对应函数所在的地址\n") },
  200. //{-89, _T("未找到返回结果变量\n")},
  201. //////////////////////////////////////////////////////////////////////////
  202. { -252, _T("密码不正确\n") },
  203. { -253, _T("打开加密锁时PIN码错误\n") },
  204. { -254, _T("设置PIN码错误\n") },
  205. { -255, _T("操作加密锁时没有进行PIN操作\n") },
  206. //////////////////////////////////////////////////////////////////////////
  207. { -1052, _T("可能是输入的授权号不正确\n") },
  208. { -1053, _T("系统上没有任何智能锁\n") },
  209. { -1088, _T("发送数据错误\n") },
  210. { -1089, _T("获取数据错误\n") },
  211. { -1092, _T("找不到对应的服务端操作码\n") },
  212. { -1093, _T("表示连接服务时错误\n") },
  213. { -1095, _T("获取主机名称失败\n") },
  214. { -1097, _T("建立套字接错误\n") },
  215. { -1098, _T("绑定套字节端口错误\n") },
  216. { -1099, _T("表示无效连接,不能进行相关的操作\n") },
  217. { -2002, _T("表示监听时产生错误\n") },
  218. { -2003, _T("表示发送的数据长度与接收的数据长度不相符\n") },
  219. { -2005, _T("表示当前服务不存在任何连接\n") },
  220. { -2006, _T("表示当前查询节点超出集合范范围\n") },
  221. { -2009, _T("表示关闭连接错误\n") },
  222. //////////////////////////////////////////////////////////////////////////
  223. { -10000, _T("未知错误代码\n") }
  224. };
  225. CHAR g_szKeyPath[MAX_PATH] = { 0 };
  226. //////////////////////////////////////////////////////////////////////////
  227. /************************************************************************/
  228. /* 函数:[7/20/2017 IT];
  229. /* 描述:将ascii字符串转为unicode字符串;
  230. /* 参数:;
  231. /* [IN] pszascii ascii字符串:;
  232. /* [OUT] :;
  233. /* [IN/OUT] :;
  234. /* 返回:unicode字符串;
  235. /* 注意:返回的指针需要手动释放其所指的内存;
  236. /* 示例:;
  237. /*
  238. /* 修改:;
  239. /* 日期:;
  240. /* 内容:;
  241. /************************************************************************/
  242. WCHAR* ascii2unicode(IN const CHAR* pszascii)
  243. {
  244. INT wSize = MultiByteToWideChar(CP_ACP, 0, pszascii, -1, NULL, 0);
  245. if (wSize == ERROR_NO_UNICODE_TRANSLATION)
  246. {
  247. return NULL;
  248. }
  249. if (wSize == 0)
  250. {
  251. return NULL;
  252. }
  253. WCHAR *punicode = new WCHAR[wSize];
  254. int convresult = MultiByteToWideChar(CP_ACP, 0, pszascii, -1, punicode, wSize);
  255. if (convresult != wSize)
  256. {
  257. if (punicode) delete[]punicode;
  258. return NULL;
  259. }
  260. return punicode;
  261. }
  262. void ReSetPassWord(BOOL bClassicPsw /* = FALSE */)
  263. {
  264. g_bUSE_NEWPASSWORD = bClassicPsw;
  265. if (!g_bUSE_NEWPASSWORD)
  266. {
  267. g_pHReadPassWord = g_szPassword[0][0];
  268. g_pLReadPassWord = g_szPassword[0][1];
  269. g_pHWritePassWord = g_szPassword[1][0];
  270. g_pLWritePassWord = g_szPassword[1][1];
  271. }
  272. else
  273. {
  274. g_pHReadPassWord = g_szPassword[2][0];
  275. g_pLReadPassWord = g_szPassword[2][1];
  276. g_pHWritePassWord = g_szPassword[3][0];
  277. g_pLWritePassWord = g_szPassword[3][1];
  278. }
  279. }
  280. void ReadAllClassicYtInfo(IN std::vector<YtUsbInfo*> &vtYtInfo)
  281. {
  282. ReSetPassWord(FALSE);
  283. INT nRetval = 0;
  284. INT nVal[8] = { 0 };
  285. DOUBLE fVal[8] = { 0.0 };
  286. CHAR s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  287. BOOL bFind = FALSE;
  288. CHAR szKeyPath[MAX_PATH] = "";
  289. for (INT nIndex = 0; nIndex < 256; nIndex++)
  290. {
  291. memset(szKeyPath, 0, sizeof(szKeyPath));
  292. nRetval = FindPort(nIndex, szKeyPath);
  293. if (nRetval != 0 && nIndex == 0) continue;
  294. if (nRetval != 0) continue;
  295. for (int i = 0; i < 6; i++)
  296. {
  297. // 使用该设备路径锁进行运算;
  298. nRetval = CalEx(g_byShotVersion[i], 10,
  299. &nVal[0], &nVal[1], &nVal[2], &nVal[3], &nVal[4], &nVal[5], &nVal[6], &nVal[7],
  300. &fVal[0], &fVal[1], &fVal[2], &fVal[3], &fVal[4], &fVal[5], &fVal[6], &fVal[7],
  301. s0, s1, s2, s3, s4, s5, s6, s7, szKeyPath, 20000);
  302. //如果正确,则返回该设备路径供以后使用;
  303. if (nRetval == -63) continue;
  304. if ((nRetval == 0) && (nVal[0] == 123))
  305. {
  306. YtUsbInfo *pYtInfo = new YtUsbInfo;
  307. pYtInfo->nUSBPort = nIndex;
  308. sprintf_s(pYtInfo->szKeyPath, MAX_PATH, "%s", szKeyPath);
  309. // 返回锁的短ID及版本号;
  310. INT nVersion = 0;
  311. if ((nRetval = GetIDVersion(&pYtInfo->verInfo.dwShortKey, &nVersion, szKeyPath)) != 0)
  312. {
  313. // 返回非0表示失败;
  314. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  315. if (pYtInfo)
  316. delete pYtInfo;
  317. continue;
  318. }
  319. if (pYtInfo->verInfo.dwShortKey == -1)
  320. {
  321. // 不是域天智能锁;
  322. if (pYtInfo)
  323. delete pYtInfo;
  324. continue;
  325. }
  326. bFind = TRUE;
  327. pYtInfo->verInfo.nSoftVer = i;
  328. // 获取加密锁座席数量;
  329. if ((nRetval = YtReadString(pYtInfo->verInfo.szCCount, 264, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  330. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  331. // 获取加密锁域名值;
  332. if ((nRetval = YtReadString(pYtInfo->verInfo.szBranchId, 297, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  333. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  334. // 获取医院跟踪系统;
  335. if ((nRetval = YtReadString(pYtInfo->verInfo.szHospital, 330, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  336. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  337. // 返回加密锁已运行时间;
  338. if ((nRetval = GetRunTimer(pYtInfo->verInfo.szHasRunyears, pYtInfo->verInfo.szHasRunmonths, pYtInfo->verInfo.szHasRundays, pYtInfo->verInfo.szHasRunhours, pYtInfo->verInfo.szHasRunminutes, pYtInfo->verInfo.szHasRunseconds, szKeyPath)) != 0)
  339. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  340. // 返回加密锁可运行时间;
  341. DWORD dwShortID = 0; // 锁短ID;
  342. CHAR szOutString[100] = { 0 };
  343. CHAR HKey[50] = { 0 }, LKey[50] = { 0 };
  344. // 30000以后的储存空间为公共区域;
  345. if ((nRetval = ReadTimeAuthFromEprom(HKey, LKey, szOutString, &dwShortID, 30128, "FFFFFFFF", "FFFFFFFF", szKeyPath)) != 0)
  346. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  347. std::string str = szOutString;
  348. int nStrPos = str.find("年");
  349. if (nStrPos != std::string::npos)
  350. {
  351. sprintf_s(pYtInfo->verInfo.szCanRunyears, "%s", str.substr(0, nStrPos).c_str());
  352. str = str.substr(nStrPos + strlen("年"));
  353. nStrPos = str.find("月");
  354. sprintf_s(pYtInfo->verInfo.szCanRunmonths, "%s", str.substr(0, nStrPos).c_str());
  355. str = str.substr(nStrPos + strlen("月"));
  356. nStrPos = str.find("日");
  357. sprintf_s(pYtInfo->verInfo.szCanRundays, "%s", str.substr(0, nStrPos).c_str());
  358. str = str.substr(nStrPos + strlen("日"));
  359. nStrPos = str.find("小时");
  360. sprintf_s(pYtInfo->verInfo.szCanRunhours, "%s", str.substr(0, nStrPos).c_str());
  361. str = str.substr(nStrPos + strlen("小时"));
  362. nStrPos = str.find("分钟");
  363. sprintf_s(pYtInfo->verInfo.szCanRunminutes, "%s", str.substr(0, nStrPos).c_str());
  364. //str = str.substr(nStrPos + strlen("分钟"));
  365. }
  366. vtYtInfo.push_back(pYtInfo);
  367. }
  368. }
  369. }
  370. }
  371. BOOL ReadYtInfoVer1(IN CONST INT &nUSBStartPos, OUT YtInfoVer1 &Infover1, OUT INT &nUSBPort, OUT CHAR* pszKeyPath, IN CONST INT &nKeypath)
  372. {
  373. INT nRetval = 0;
  374. INT nVal[8] = { 0 };
  375. DOUBLE fVal[8] = { 0.0 };
  376. CHAR s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  377. BOOL bFind = FALSE;
  378. CHAR szKeyPath[MAX_PATH] = "";
  379. for (INT nIndex = nUSBStartPos; nIndex < 256; nIndex++)
  380. {
  381. memset(szKeyPath, 0, sizeof(szKeyPath));
  382. nRetval = FindPort(nIndex, szKeyPath);
  383. if (nRetval != 0 && nIndex == 0) continue;
  384. if (nRetval != 0) continue;
  385. for (int i = 0; i < 6; i++)
  386. {
  387. // 使用该设备路径锁进行运算;
  388. nRetval = CalEx(g_byShotVersion[i], 10,
  389. &nVal[0], &nVal[1], &nVal[2], &nVal[3], &nVal[4], &nVal[5], &nVal[6], &nVal[7],
  390. &fVal[0], &fVal[1], &fVal[2], &fVal[3], &fVal[4], &fVal[5], &fVal[6], &fVal[7],
  391. s0, s1, s2, s3, s4, s5, s6, s7, szKeyPath, 20000);
  392. //如果正确,则返回该设备路径供以后使用;
  393. if (nRetval == -63) continue;
  394. if ((nRetval == 0) && (nVal[0] == 123))
  395. {
  396. nUSBPort = nIndex;
  397. if (pszKeyPath)
  398. sprintf_s(pszKeyPath, nKeypath, "%s", szKeyPath);
  399. // 返回锁的短ID及版本号;
  400. INT nVersion = 0;
  401. if ((nRetval = GetIDVersion(&Infover1.dwShortKey, &nVersion, szKeyPath)) != 0)
  402. {
  403. // 返回非0表示失败;
  404. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  405. return FALSE;
  406. }
  407. if (Infover1.dwShortKey == -1)
  408. {
  409. // 不是域天智能锁;
  410. return FALSE;
  411. }
  412. bFind = TRUE;
  413. Infover1.nSoftVer = i;
  414. // 获取加密锁座席数量;
  415. if ((nRetval = YtReadString(Infover1.szCCount, 264, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  416. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  417. // 获取加密锁域名值;
  418. if ((nRetval = YtReadString(Infover1.szBranchId, 297, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  419. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  420. // 获取医院跟踪系统;
  421. if ((nRetval = YtReadString(Infover1.szHospital, 330, ENCRYPT_BLOCK_LEN, g_pHReadPassWord, g_pLReadPassWord, szKeyPath)) != 0)
  422. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  423. // 返回加密锁已运行时间;
  424. if ((nRetval = GetRunTimer(Infover1.szHasRunyears, Infover1.szHasRunmonths, Infover1.szHasRundays, Infover1.szHasRunhours, Infover1.szHasRunminutes, Infover1.szHasRunseconds, szKeyPath)) != 0)
  425. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  426. // 返回加密锁可运行时间;
  427. DWORD dwShortID = 0; // 锁短ID;
  428. CHAR szOutString[100] = { 0 };
  429. CHAR HKey[50] = { 0 }, LKey[50] = { 0 };
  430. // 30000以后的储存空间为公共区域;
  431. if ((nRetval = ReadTimeAuthFromEprom(HKey, LKey, szOutString, &dwShortID, 30128, "FFFFFFFF", "FFFFFFFF", szKeyPath)) != 0)
  432. AfxMessageBox(GetYtUSBKey32ErrInfo(nRetval));
  433. std::string str = szOutString;
  434. int nStrPos = str.find("年");
  435. if (nStrPos != std::string::npos)
  436. {
  437. sprintf_s(Infover1.szCanRunyears, "%s", str.substr(0, nStrPos).c_str());
  438. str = str.substr(nStrPos + strlen("年"));
  439. nStrPos = str.find("月");
  440. sprintf_s(Infover1.szCanRunmonths, "%s", str.substr(0, nStrPos).c_str());
  441. str = str.substr(nStrPos + strlen("月"));
  442. nStrPos = str.find("日");
  443. sprintf_s(Infover1.szCanRundays, "%s", str.substr(0, nStrPos).c_str());
  444. str = str.substr(nStrPos + strlen("日"));
  445. nStrPos = str.find("小时");
  446. sprintf_s(Infover1.szCanRunhours, "%s", str.substr(0, nStrPos).c_str());
  447. str = str.substr(nStrPos + strlen("小时"));
  448. nStrPos = str.find("分钟");
  449. sprintf_s(Infover1.szCanRunminutes, "%s", str.substr(0, nStrPos).c_str());
  450. }
  451. break;
  452. }
  453. }
  454. if (bFind) break;
  455. }
  456. return bFind;
  457. }
  458. BOOL ModifyYtVer1Info(IN CHAR* pszKeypath, IN YtInfoVer1 &Infover1, IN CONST INT &nModifyType)
  459. {
  460. // 修改类型有:加减运行时间、加减座席数量、开通或关闭医院功能。
  461. switch (nModifyType)
  462. {
  463. case VER1_ADDCCOUNT:
  464. break;
  465. case VER1_MINUSCCOUNT:
  466. break;
  467. case VER1_HOSPITAL:
  468. break;
  469. case VER1_ADDTIME:
  470. break;
  471. case VER1_MINUSTIME:
  472. break;
  473. default:
  474. break;
  475. }
  476. return TRUE;
  477. }
  478. BOOL ChangeConnectCount(IN CHAR* pszKeypath, IN CONST INT& nCCount)
  479. {
  480. if (pszKeypath == NULL)
  481. {
  482. OutputDebugString(_T("usb路径无效!\n"));
  483. return FALSE;
  484. }
  485. // 264是座席数量;
  486. if (nCCount >= 0)
  487. {
  488. CHAR szCCount[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  489. sprintf_s(szCCount, "%d", nCCount);
  490. INT nRet = YtWriteString(szCCount, 264, g_pHWritePassWord, g_pLWritePassWord, pszKeypath);
  491. if (nRet <= 0)
  492. {
  493. // 设置座席数失败;
  494. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  495. return FALSE;
  496. }
  497. }
  498. return TRUE;
  499. }
  500. BOOL ChangeBranchId(IN CHAR* pszKeypath, IN CONST CHAR* pszBranchId, IN CONST INT& dwShortKey)
  501. {
  502. if (pszKeypath == NULL)
  503. {
  504. OutputDebugString(_T("usb路径无效!\n"));
  505. return FALSE;
  506. }
  507. // 297是域名值;
  508. // 生成域名串 = 日期 + 短ID;
  509. CHAR szDomain[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  510. sprintf_s(szDomain, "%s%d.ly.com", pszBranchId, dwShortKey);
  511. INT nRet = YtWriteString(szDomain, 297, g_pHWritePassWord, g_pLWritePassWord, pszKeypath);
  512. if (nRet <= 0)
  513. {
  514. // 生成域名错误;
  515. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  516. return FALSE;
  517. }
  518. return TRUE;
  519. }
  520. BOOL ChangeHospital(IN CHAR* pszKeypath, IN BOOL bEnableHospital)
  521. {
  522. if (pszKeypath == NULL)
  523. {
  524. OutputDebugString(_T("usb路径无效!\n"));
  525. return FALSE;
  526. }
  527. // 330是医院跟踪系统;
  528. CHAR szHospital[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  529. sprintf_s(szHospital, "%d", bEnableHospital);
  530. INT nRet = YtWriteString(szHospital, 330, g_pHWritePassWord, g_pLWritePassWord, pszKeypath);
  531. if (nRet <= 0)
  532. {
  533. // 设置医院跟踪系统失败;
  534. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  535. return FALSE;
  536. }
  537. return TRUE;
  538. }
  539. 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)
  540. {
  541. if (pszKeypath == NULL)
  542. {
  543. OutputDebugString(_T("usb路径无效!\n"));
  544. return FALSE;
  545. }
  546. //////////////////////////////////////////////////////////////////////////
  547. // 获取加密锁已运行时间GetRunTimer;
  548. CHAR szHasRunyears[TIMELEN] = { 0 };
  549. CHAR szHasRunmonths[TIMELEN] = { 0 };
  550. CHAR szHasRundays[TIMELEN] = { 0 };
  551. CHAR szHasRunhours[TIMELEN] = { 0 };
  552. CHAR szHasRunminutes[TIMELEN] = { 0 };
  553. CHAR szHasRunseconds[TIMELEN] = { 0 };
  554. INT nRet = GetRunTimer(szHasRunyears, szHasRunmonths, szHasRundays, szHasRunhours, szHasRunminutes, szHasRunseconds, pszKeypath);
  555. if (nRet != 0)
  556. {
  557. // 获取运行时间失败;
  558. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  559. return FALSE;
  560. }
  561. //////////////////////////////////////////////////////////////////////////
  562. CHAR szCanRunyears[TIMELEN] = { 0 };
  563. CHAR szCanRunmonths[TIMELEN] = { 0 };
  564. CHAR szCanRundays[TIMELEN] = { 0 };
  565. CHAR szCanRunhours[TIMELEN] = { 0 };
  566. CHAR szCanRunminutes[TIMELEN] = { 0 };
  567. if (bAppend) // 追加时间;
  568. {
  569. // 获取加密锁可运行时间ReadTimeAuthFromEprom;
  570. CHAR szOutString[100] = { 0 };// 返回的时间授权码;
  571. CHAR HKey[50] = { 0 }, LKey[50] = { 0 };
  572. // 30000以后的储存空间为公共区域;
  573. DWORD dwShortID = dwShortKey;
  574. if ((nRet = ReadTimeAuthFromEprom(HKey, LKey, szOutString, &dwShortID, 30128, "FFFFFFFF", "FFFFFFFF", pszKeypath)) != 0)
  575. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  576. std::string str = szOutString;
  577. int nStrPos = str.find("年");
  578. if (nStrPos != std::string::npos)
  579. {
  580. sprintf_s(szCanRunyears, "%s", str.substr(0, nStrPos).c_str());
  581. str = str.substr(nStrPos + strlen("年"));
  582. nStrPos = str.find("月");
  583. sprintf_s(szCanRunmonths, "%s", str.substr(0, nStrPos).c_str());
  584. str = str.substr(nStrPos + strlen("月"));
  585. nStrPos = str.find("日");
  586. sprintf_s(szCanRundays, "%s", str.substr(0, nStrPos).c_str());
  587. str = str.substr(nStrPos + strlen("日"));
  588. nStrPos = str.find("小时");
  589. sprintf_s(szCanRunhours, "%s", str.substr(0, nStrPos).c_str());
  590. str = str.substr(nStrPos + strlen("小时"));
  591. nStrPos = str.find("分钟");
  592. sprintf_s(szCanRunminutes, "%s", str.substr(0, nStrPos).c_str());
  593. }
  594. sprintf_s(szCanRunyears, "%d", nRunYears + atoi(szCanRunyears));
  595. sprintf_s(szCanRunmonths, "%d", nRunMonth + atoi(szCanRunmonths));
  596. sprintf_s(szCanRundays, "%d", nRunDays + atoi(szCanRundays));
  597. sprintf_s(szCanRunhours, "%d", nRunHours + atoi(szCanRunhours));
  598. sprintf_s(szCanRunminutes, "%d", nRunMinutes + atoi(szCanRunminutes));
  599. }
  600. else
  601. {
  602. sprintf_s(szCanRunyears, "%d", nRunYears);
  603. sprintf_s(szCanRunmonths, "%d", nRunMonth);
  604. sprintf_s(szCanRundays, "%d", nRunDays);
  605. sprintf_s(szCanRunhours, "%d", nRunHours);
  606. sprintf_s(szCanRunminutes, "%d", nRunMinutes);
  607. }
  608. // 生成时间授权码;
  609. CHAR szOutString[100] = { 0 };// 返回的时间授权码;
  610. if ((nRet = MakeTimerAuth(g_szUserKey, dwShortKey, szCanRunyears, szCanRunmonths, szCanRundays, szCanRunhours, szCanRunminutes, szOutString, pszKeypath)) != 0)
  611. {
  612. // 生成时间授权码失败;
  613. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  614. return FALSE;
  615. }
  616. CHAR wHKey[9] = "FFFFFFFF", wLKey[9] = "FFFFFFFF";
  617. CHAR Key1[41] = "0", Key2[41] = "0";
  618. memcpy(Key1, szOutString, 40);
  619. memcpy(Key2, &szOutString[40], 40);
  620. // 写授权时间到加密锁中;
  621. if ((nRet = WriteTimeAuthToEprom(30128, wHKey, wLKey, Key1, Key2, dwShortKey, szCanRunyears, szCanRunmonths, szCanRundays, szCanRunhours, szCanRunminutes, pszKeypath)) != 0)
  622. {
  623. // 写授权时间失败;
  624. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  625. return FALSE;
  626. }
  627. return TRUE;
  628. }
  629. BOOL ChangeVersion(IN CHAR* pszKeypath, IN CONST INT& nOldVersion, IN CONST INT& nNewVersion)
  630. {
  631. if (pszKeypath == NULL)
  632. {
  633. OutputDebugString(_T("usb路径无效!\n"));
  634. return FALSE;
  635. }
  636. // 清空所有版本锁的加密解密的密钥;
  637. INT nRet = WriteEncKey(g_szEncKey[nOldVersion][0], g_szEncKey[nOldVersion][1], g_szEncKey[nOldVersion][2], g_szEncKey[nOldVersion][3],
  638. g_szEncKey[nNewVersion][0], g_szEncKey[nNewVersion][1], g_szEncKey[nNewVersion][2], g_szEncKey[nNewVersion][3], pszKeypath);
  639. if (nRet != 0)
  640. {
  641. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  642. return FALSE;
  643. }
  644. // 从地址0~231+32,是所有加密锁共同内容;
  645. for (int i = 0; i < 8; i++)
  646. {
  647. if ((nRet = YtWriteString(g_szRom[i], i * 33, g_pHWritePassWord, g_pLWritePassWord, pszKeypath)) <= 0)
  648. {
  649. // 写区域错误;
  650. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  651. }
  652. }
  653. // 判断新版是否属于座席版,如果不是,清除坐席数;
  654. if (nNewVersion != 1 && nNewVersion != 4)
  655. {
  656. ChangeConnectCount(pszKeypath, 0);
  657. }
  658. return TRUE;
  659. }
  660. /************************************************************************/
  661. /*
  662. 函数:GetRemainderRunTime
  663. 描述:获取经典版加密锁剩余的可运行时间;
  664. 参数:
  665. [IN] pszKeypath 加密锁物理位置;
  666. [OUT] dwRemainderRunTime 返回剩余可运行时间;
  667. 返回:
  668. */
  669. /************************************************************************/
  670. BOOL GetRemainderRunTime(IN CHAR* pszKeypath, IN DWORD dwShortKey, OUT DWORD& dwHasRunTime, OUT DWORD& dwCanRunTime)
  671. {
  672. if (pszKeypath == NULL)
  673. {
  674. OutputDebugString(_T("usb路径无效!\n"));
  675. return FALSE;
  676. }
  677. //////////////////////////////////////////////////////////////////////////
  678. // 获取加密锁已运行时间GetRunTimer;
  679. CHAR szHasRunyears[TIMELEN] = { 0 };
  680. CHAR szHasRunmonths[TIMELEN] = { 0 };
  681. CHAR szHasRundays[TIMELEN] = { 0 };
  682. CHAR szHasRunhours[TIMELEN] = { 0 };
  683. CHAR szHasRunminutes[TIMELEN] = { 0 };
  684. CHAR szHasRunseconds[TIMELEN] = { 0 };
  685. INT nRet = GetRunTimer(szHasRunyears, szHasRunmonths, szHasRundays, szHasRunhours, szHasRunminutes, szHasRunseconds, pszKeypath);
  686. if (nRet != 0)
  687. {
  688. // 获取运行时间失败;
  689. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  690. return FALSE;
  691. }
  692. //////////////////////////////////////////////////////////////////////////
  693. // 获取加密锁可运行时间;
  694. CHAR szCanRunyears[TIMELEN] = { 0 };
  695. CHAR szCanRunmonths[TIMELEN] = { 0 };
  696. CHAR szCanRundays[TIMELEN] = { 0 };
  697. CHAR szCanRunhours[TIMELEN] = { 0 };
  698. CHAR szCanRunminutes[TIMELEN] = { 0 };
  699. // 获取加密锁可运行时间ReadTimeAuthFromEprom;
  700. CHAR szOutString[100] = { 0 };// 返回的时间授权码;
  701. CHAR HKey[50] = { 0 }, LKey[50] = { 0 };
  702. // 30000以后的储存空间为公共区域;
  703. if ((nRet = ReadTimeAuthFromEprom(HKey, LKey, szOutString, &dwShortKey, 30128, "FFFFFFFF", "FFFFFFFF", pszKeypath)) != 0)
  704. {
  705. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  706. return FALSE;
  707. }
  708. std::string str = szOutString;
  709. int nStrPos = str.find("年");
  710. if (nStrPos != std::string::npos)
  711. {
  712. sprintf_s(szCanRunyears, "%s", str.substr(0, nStrPos).c_str());
  713. str = str.substr(nStrPos + strlen("年"));
  714. nStrPos = str.find("月");
  715. if (nStrPos != std::string::npos)
  716. {
  717. sprintf_s(szCanRunmonths, "%s", str.substr(0, nStrPos).c_str());
  718. str = str.substr(nStrPos + strlen("月"));
  719. }
  720. nStrPos = str.find("日");
  721. if (nStrPos != std::string::npos)
  722. {
  723. sprintf_s(szCanRundays, "%s", str.substr(0, nStrPos).c_str());
  724. str = str.substr(nStrPos + strlen("日"));
  725. }
  726. nStrPos = str.find("小时");
  727. if (nStrPos != std::string::npos)
  728. {
  729. sprintf_s(szCanRunhours, "%s", str.substr(0, nStrPos).c_str());
  730. str = str.substr(nStrPos + strlen("小时"));
  731. }
  732. nStrPos = str.find("分钟");
  733. if (nStrPos != std::string::npos)
  734. {
  735. sprintf_s(szCanRunminutes, "%s", str.substr(0, nStrPos).c_str());
  736. }
  737. }
  738. // 转化为整数秒;
  739. CHAR szSecondes[10] = "0";
  740. dwHasRunTime = ConvertStringToTimerReal(szHasRunyears, szHasRunmonths, szHasRundays, szHasRunhours, szHasRunminutes, szSecondes);
  741. dwCanRunTime = ConvertStringToTimerReal(szCanRunyears, szCanRunmonths, szCanRundays, szCanRunhours, szCanRunminutes, szSecondes);
  742. return TRUE;
  743. }
  744. /************************************************************************/
  745. /* 函数:GenerateRunTimeRegCode[4/17/2016 IT];
  746. /* 描述:生成加时授权码,一般先判断加密锁是否过时,如果过时进行运算,获取加时授权码;
  747. /* 参数:;
  748. /* [IN] pszKeypath:;
  749. /* [IN] nShortKey:;
  750. /* [IN] nSoftVer:;
  751. /* [OUT] lpRegCode:返回加时授权码;
  752. /* [IN] nBufLen:lpRegCode缓冲区大小;
  753. /* 返回:void;
  754. /* 注意:;
  755. /* 示例:;
  756. /*
  757. /* 修改:;
  758. /* 日期:;
  759. /* 内容:;
  760. /************************************************************************/
  761. BOOL GenerateRunTimeRegCode(IN CHAR* pszKeypath, IN INT nShortKey, IN CONST INT& nSoftVer, OUT LPTSTR lpRegCode, IN CONST INT& nBufLen)
  762. {
  763. if (pszKeypath == NULL)
  764. {
  765. OutputDebugString(_T("usb路径无效!\n"));
  766. return FALSE;
  767. }
  768. INT nHasRunTime = 0, nCanRunTime = 0;
  769. INT nVal[4] = { 0 };
  770. CHAR szVal[8][50] = { 0 };
  771. double flVal[8] = { 0.0 };
  772. INT nRet = 0, nKeyCode = 123456;
  773. if (GetRemainderRunTime(pszKeypath, nShortKey, (DWORD&)nHasRunTime, (DWORD&)nCanRunTime))
  774. {
  775. nRet = CalEx(g_byTimeRegCode[nSoftVer], 58, &nShortKey, &nKeyCode, &nHasRunTime, &nCanRunTime, &nVal[0], &nVal[1], &nVal[2], &nVal[3],
  776. &flVal[0], &flVal[1], &flVal[2], &flVal[3], &flVal[4], &flVal[5], &flVal[6], &flVal[7],
  777. szVal[0], szVal[1], szVal[2], szVal[3], szVal[4], szVal[5], szVal[6], szVal[7], pszKeypath, 20000);
  778. if (nRet != 0 && nRet != -43)
  779. {
  780. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  781. return FALSE;
  782. }
  783. }
  784. CString strTimeRegCode = _T("");
  785. CString temp, temp2;
  786. /////////////////////////////////////////
  787. temp.Format(_T("%d"), abs(nShortKey));
  788. int leng = temp.GetLength();
  789. if (nShortKey < 0)
  790. temp2 = _T("1");
  791. else
  792. temp2 = _T("0");
  793. temp = temp2 + temp;
  794. temp2.Format(_T("%02d"), leng);
  795. temp = temp2 + temp;
  796. strTimeRegCode += temp;
  797. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  798. temp.Format(_T("%d"), abs(nHasRunTime));
  799. leng = temp.GetLength();
  800. if (nHasRunTime < 0)
  801. temp2 = _T("1");
  802. else
  803. temp2 = _T("0");
  804. temp = temp2 + temp;
  805. temp2.Format(_T("%02d"), leng);
  806. temp = temp2 + temp;
  807. strTimeRegCode += temp;
  808. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  809. temp.Format(_T("%d"), abs(nCanRunTime));
  810. leng = temp.GetLength();
  811. if (nCanRunTime < 0)
  812. temp2 = _T("1");
  813. else
  814. temp2 = _T("0");
  815. temp = temp2 + temp;
  816. temp2.Format(_T("%02d"), leng);
  817. temp = temp2 + temp;
  818. strTimeRegCode += temp;
  819. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  820. temp.Format(_T("%d"), abs(nKeyCode));
  821. leng = temp.GetLength();
  822. if (nKeyCode < 0)
  823. temp2 = _T("1");
  824. else
  825. temp2 = _T("0");
  826. temp = temp2 + temp;
  827. temp2.Format(_T("%02d"), leng);
  828. temp = temp2 + temp;
  829. strTimeRegCode += temp;
  830. StringCchPrintf(lpRegCode, nBufLen, _T("%s"), strTimeRegCode.GetString());
  831. return TRUE;
  832. }
  833. /************************************************************************/
  834. /* 函数:GetRunTimeByRegCode[3/4/2016 IT];
  835. /* 描述:获取指定加时授权码的加密锁的运行时间;
  836. /* 参数:;
  837. /* [IN] pszKeypath:加密锁物理位置;
  838. /* [IN] dwShortKey:加密锁短id;
  839. /* [IN] nSoftVer:加密锁版本;
  840. /* [IN] lpRegCode:加时授权码;
  841. /* [OUT] :;
  842. /* [IN/OUT] :;
  843. /* 返回:成功返回TRUE;
  844. /* 注意:运算的加密锁必须是婚纱全能版,否则是计算不出授权码里的内容;
  845. /* 示例:;
  846. /*
  847. /* 修改:;
  848. /* 日期:;
  849. /* 内容:;
  850. /************************************************************************/
  851. BOOL GetRunTimeByRegCode(IN CHAR* pszKeypath, IN DWORD dwShortKey, IN CONST INT& nSoftVer, IN LPCTSTR lpRegCode, IN CString& strResult)
  852. {
  853. if (pszKeypath == NULL)
  854. {
  855. OutputDebugString(_T("usb路径无效!\n"));
  856. return FALSE;
  857. }
  858. if (nSoftVer != EN_OWDDING)
  859. return FALSE;
  860. CString requestcode = lpRegCode;
  861. requestcode.TrimLeft();
  862. requestcode.TrimRight();
  863. requestcode.Replace(_T("\n"), _T(""));
  864. requestcode.Replace(_T("\r"), _T(""));
  865. if (requestcode.IsEmpty())
  866. {
  867. return FALSE;
  868. }
  869. CString str, temp, temp2;
  870. INT id, time1, time2, idtemp;
  871. int leng;
  872. str = requestcode;
  873. temp = str.Left(3);
  874. str = str.Right(str.GetLength() - 3);
  875. leng = _tstoi(temp.Left(2).GetString());
  876. temp2 = str.Left(leng);
  877. str = str.Right(str.GetLength() - leng);
  878. id = _tstoi(temp2);
  879. if (temp.Right(1) == _T("1"))id = -id;
  880. //////////////////////////////////////////////////
  881. temp = str.Left(3);
  882. str = str.Right(str.GetLength() - 3);
  883. leng = _tstoi(temp.Left(2));
  884. temp2 = str.Left(leng);
  885. str = str.Right(str.GetLength() - leng);
  886. time1 = _tstoi(temp2);
  887. if (temp.Right(1) == _T("1"))time1 = -time1;
  888. //////////////////////////////////////////////////
  889. temp = str.Left(3);
  890. str = str.Right(str.GetLength() - 3);
  891. leng = _tstoi(temp.Left(2));
  892. temp2 = str.Left(leng);
  893. str = str.Right(str.GetLength() - leng);
  894. time2 = _tstoi(temp2);
  895. if (temp.Right(1) == _T("1"))time2 = -time2;
  896. //////////////////////////////////////////////////////
  897. temp = str.Left(3);
  898. str = str.Right(str.GetLength() - 3);
  899. leng = _tstoi(temp.Left(2));
  900. temp2 = str.Left(leng);
  901. str = str.Right(str.GetLength() - leng);
  902. idtemp = _tstoi(temp2);
  903. if (temp.Right(1) == _T("1"))idtemp = -idtemp;
  904. //////////////////////////////////////////////////////
  905. INT d[8]; double f[8];
  906. char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  907. // 运行自定义函数;
  908. INT nRet = CalEx(g_byDecryptRegCode, 58, &id, &idtemp, &time1, &time2, &d[4], &d[5], &d[6], &d[7],
  909. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7, pszKeypath, 2000);
  910. if (nRet != 0 && nRet != -43)
  911. {
  912. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  913. return FALSE;
  914. }
  915. CHAR year[10], month[10], day[10], hour[10], minute[10], second[10];
  916. ConvertTimerToStringReal(time2, year, month, day, hour, minute, second);
  917. temp.Format(_T("%d 已运行:%02d年%02d月%02d日%02d时%02d分%02d秒 "), id, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute), atoi(second));
  918. strResult += temp;
  919. if (time1 > 0)
  920. ConvertTimerToStringReal(time1, year, month, day, hour, minute, second);
  921. else
  922. {
  923. StringCchPrintfA(year, 10, "%s", "0");
  924. StringCchPrintfA(month, 10, "%s", "0");
  925. StringCchPrintfA(day, 10, "%s", "0");
  926. StringCchPrintfA(hour, 10, "%s", "0");
  927. StringCchPrintfA(minute, 10, "%s", "0");
  928. }
  929. temp.Format(_T("能运行:%02d年%02d月%02d日%02d时%02d分%02d秒---%d"), atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute), atoi(second), time2);
  930. strResult += temp;
  931. return FALSE;
  932. }
  933. /************************************************************************/
  934. /* 函数:InitEncryptlock[3/4/2016 IT];
  935. /* 描述:初始化加密锁,完全清空;
  936. /* 参数:;
  937. /* [IN] nStartUSBPort:加密狗起始USB搜索位置;
  938. /* 返回:清除成功返回TRUE;
  939. /* 注意:;
  940. /* 示例:;
  941. /*
  942. /* 修改:;
  943. /* 日期:;
  944. /* 内容:;
  945. /************************************************************************/
  946. BOOL InitEncryptlock(IN const int &nStartUSBPort)
  947. {
  948. int nRet = 0;
  949. int nVersion = -1; // 锁版本;
  950. DWORD dwShortKey = 0; // 锁短ID;
  951. CHAR szKeyPath[MAX_PATH] = { 0 }; // USB锁物理位置;
  952. // 从nStartUSBPort的USB的位置开始查找加密锁;
  953. if ((nRet = FindPort(nStartUSBPort, szKeyPath)) != 0)
  954. {
  955. // 返回非0表示失败;
  956. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  957. return FALSE;
  958. }
  959. // 返回锁的短ID及版本号;
  960. if ((nRet = GetIDVersion(&dwShortKey, &nVersion, szKeyPath)) != 0)
  961. {
  962. // 返回非0表示失败;
  963. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  964. return FALSE;
  965. }
  966. if (dwShortKey == -1)
  967. {
  968. // 不是域天智能锁;
  969. return FALSE;
  970. }
  971. if ((nRet = ReSet(szKeyPath)) != 0)
  972. {
  973. // 返回非0表示失败;
  974. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  975. return FALSE;
  976. }
  977. return TRUE;
  978. }
  979. /************************************************************************/
  980. /* 函数:ClearEncryptlockInfo[3/4/2016 IT];
  981. /* 描述:清空加密所有加密信息;
  982. /* 参数:;
  983. /* [IN] nStartUSBPort:加密狗起始USB搜索位置;
  984. /* 返回:清除成功返回TRUE;
  985. /* 注意:;
  986. /* 示例:;
  987. /*
  988. /* 修改:;
  989. /* 日期:;
  990. /* 内容:;
  991. /************************************************************************/
  992. BOOL ClearEncryptlockInfo(IN const int &nStartUSBPort)
  993. {
  994. int nRet = 0;
  995. int nVersion = -1; // 锁版本;
  996. DWORD dwShortKey = 0; // 锁短ID;
  997. CHAR szKeyPath[MAX_PATH] = { 0 }; // USB锁物理位置;
  998. // 从nStartUSBPort的USB的位置开始查找加密锁;
  999. if ((nRet = FindPort(nStartUSBPort, szKeyPath)) != 0)
  1000. {
  1001. // 返回非0表示失败;
  1002. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1003. return FALSE;
  1004. }
  1005. // 返回锁的短ID及版本号;
  1006. if ((nRet = GetIDVersion(&dwShortKey, &nVersion, szKeyPath)) != 0)
  1007. {
  1008. // 返回非0表示失败;
  1009. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1010. return FALSE;
  1011. }
  1012. if (dwShortKey == -1)
  1013. {
  1014. // 不是域天智能锁;
  1015. return FALSE;
  1016. }
  1017. // 清空所有版本锁的rom空间地内容;
  1018. CHAR szRom[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  1019. for (int i = 0; i < 11; i++)
  1020. {
  1021. nRet = YtWriteString(szRom, i * 33, g_pHWritePassWord, g_pLWritePassWord, szKeyPath);
  1022. if (nRet <= 0)
  1023. {
  1024. // 执行失败;
  1025. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1026. GetYtUSBKey32ErrInfo(nRet);
  1027. }
  1028. }
  1029. // 清除写密码;
  1030. nRet = SetWritePassword(g_pHWritePassWord, g_pLWritePassWord, "FFFFFFFF", "FFFFFFFF", szKeyPath);
  1031. if (nRet != 0)
  1032. {
  1033. // 执行失败;
  1034. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1035. //return FALSE;
  1036. }
  1037. // 清除读密码;//设置读密码,必须用写密码;
  1038. if ((nRet = SetReadPassword("FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", szKeyPath)) != 0)
  1039. {
  1040. // 执行失败;
  1041. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1042. //return FALSE;
  1043. }
  1044. // 清空所有版本锁的加密解密的密钥;
  1045. BOOL bErased = FALSE;
  1046. for (int i = 0; i < 6; i++)
  1047. {
  1048. if (0 == (nRet = WriteEncKey(g_szEncKey[i][0], g_szEncKey[i][1], g_szEncKey[i][2], g_szEncKey[i][3], "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", "FFFFFFFF", szKeyPath)))
  1049. {
  1050. bErased = TRUE;
  1051. break;
  1052. }
  1053. else
  1054. {
  1055. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1056. }
  1057. }
  1058. if (!bErased)
  1059. {
  1060. AfxMessageBox(_T("清除加密锁失败,该锁可能已经清除过~"));
  1061. }
  1062. return TRUE;
  1063. }
  1064. BOOL FindYtUSB(OUT DWORD &dwShortKey, OUT INT &nVersion, OUT CHAR *pszKeyPath, IN CONST INT &nStartPort)
  1065. {
  1066. INT nResult = 0;
  1067. // 从nStartPort的USB的位置开始查找加密锁;
  1068. if ((nResult = FindPort(nStartPort, pszKeyPath)) != 0)
  1069. {
  1070. AfxMessageBox(GetYtUSBKey32ErrInfo(nResult));
  1071. return FALSE;
  1072. }
  1073. // 返回锁的短ID及版本号;
  1074. if ((nResult = GetIDVersion(&dwShortKey, &nVersion, pszKeyPath)) != 0)
  1075. {
  1076. AfxMessageBox(GetYtUSBKey32ErrInfo(nResult));
  1077. return FALSE;
  1078. }
  1079. return TRUE;
  1080. }
  1081. /************************************************************************/
  1082. /* 函数:CreateEncryptlockInfo[3/4/2016 IT];
  1083. /* 描述:生成指定版本的加密锁;
  1084. /* 参数:;
  1085. /* [IN] nStartPort:起始USB搜索位置;
  1086. /* [IN] nSoftVer:指定生成的加密狗版本信息;
  1087. /* [IN] nCCount:座席版连接数量;
  1088. /* [IN] bHospital:是否注册医院跟踪系统功能;
  1089. /* [IN] bAdddate:授权时间是否追加生成;
  1090. /* [IN] szRunyears:;
  1091. /* [IN] szRunmonths:;
  1092. /* [IN] szRundays:;
  1093. /* [IN] szRunhours:;
  1094. /* [IN] szRunminutes:;
  1095. /* [OUT] lpHasRundate:返回锁已运行时间;
  1096. /* [OUT] lpCouldRundate:返回锁授权时间;
  1097. /* 返回:成功返回TRUE;
  1098. /* 注意:;
  1099. /* 示例:;
  1100. /*
  1101. /* 修改:;
  1102. /* 日期:;
  1103. /* 内容:;
  1104. /************************************************************************/
  1105. 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*/)
  1106. {
  1107. int nRet = -1;
  1108. DWORD dwShortKey = 0;
  1109. int nVersion = -1;
  1110. CHAR szKeyPath[MAX_PATH] = { 0 };
  1111. if (!FindYtUSB(dwShortKey, nVersion, szKeyPath, nStartPort))
  1112. return FALSE;
  1113. if (dwShortKey == -1)
  1114. {
  1115. // 不是域天智能锁;
  1116. return FALSE;
  1117. }
  1118. nRet = SetReadPassword("FFFFFFFF", "FFFFFFFF", g_pHReadPassWord, g_pLReadPassWord, szKeyPath);
  1119. if (nRet != 0) {
  1120. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1121. }
  1122. nRet = SetWritePassword("FFFFFFFF", "FFFFFFFF", g_pHWritePassWord, g_pLWritePassWord, szKeyPath);
  1123. if (nRet != 0) {
  1124. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1125. }
  1126. // 从地址0~231+32,是所有加密锁共同内容;
  1127. for (int i = 0; i < 8; i++)
  1128. {
  1129. if ((nRet = YtWriteString(g_szRom[i], i * 33, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  1130. {
  1131. // 写区域错误;
  1132. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1133. }
  1134. }
  1135. // 264是座席数量;
  1136. if (linfo.nCCount > 0)
  1137. {
  1138. CHAR szCCount[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  1139. sprintf_s(szCCount, "%d", linfo.nCCount);
  1140. if ((nRet = YtWriteString(szCCount, 264, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  1141. {
  1142. // 设置座席数失败;
  1143. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1144. return FALSE;
  1145. }
  1146. }
  1147. // 297是域名值;
  1148. // 生成域名串 = 日期 + 短ID;
  1149. CHAR szDomain[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  1150. if (bfixedId && pszBranchId && pszBranchId[0] != '\0')
  1151. {
  1152. //sprintf_s(szDomain, "20151208000000%d.ly.com", dwShortKey);
  1153. sprintf_s(szDomain, pszBranchId);
  1154. }
  1155. else
  1156. {
  1157. CTime tt = CTime::GetCurrentTime();
  1158. 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);
  1159. }
  1160. if ((nRet = YtWriteString(szDomain, 297, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  1161. {
  1162. // 生成域名错误;
  1163. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1164. return FALSE;
  1165. }
  1166. // 330是医院跟踪系统;
  1167. if (linfo.bHospital)
  1168. {
  1169. CHAR szHospital[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  1170. sprintf_s(szHospital, "%d", linfo.bHospital);
  1171. if ((nRet = YtWriteString(szHospital, 330, g_pHWritePassWord, g_pLWritePassWord, szKeyPath)) <= 0)
  1172. {
  1173. // 设置医院跟踪系统失败;
  1174. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1175. return FALSE;
  1176. }
  1177. }
  1178. // 生成指定软件版本加密解密密钥;
  1179. switch (linfo.nSoftVer)
  1180. {
  1181. case EN_OCHILD:
  1182. 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);
  1183. break;
  1184. case EN_LCHILD:
  1185. 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);
  1186. break;
  1187. case EN_ECHILD:
  1188. 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);
  1189. break;
  1190. case EN_OWDDING:
  1191. 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);
  1192. break;
  1193. case EN_LWDDING:
  1194. 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);
  1195. break;
  1196. case EN_EWDDING:
  1197. 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);
  1198. break;
  1199. }
  1200. if (nRet != 0)
  1201. {
  1202. // 生成密钥失败;
  1203. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1204. return FALSE;
  1205. }
  1206. //////////////////////////////////////////////////////////////////////////
  1207. // 授权时间码;
  1208. CHAR szyear[10] = { 0 }, szmonth[10] = { 0 }, szday[10] = { 0 }, szhour[10] = { 0 }, szminute[10] = { 0 }, szsecond[10] = { 0 };
  1209. if ((nRet = GetRunTimer(szyear, szmonth, szday, szhour, szminute, szsecond, szKeyPath)) != 0)
  1210. {
  1211. // 获取运行时间失败;
  1212. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1213. return FALSE;
  1214. }
  1215. _stprintf_s(lpHasRundate, sizeOfhasrundate, _T("已运行 %s年%s月%s天%s时%s分"), szyear, szmonth, szday, szhour, szminute);
  1216. if (linfo.bAdddate) // 追加时间;
  1217. {
  1218. sprintf_s(szyear, "%d", atoi(linfo.szRunyears) + atoi(szyear));
  1219. sprintf_s(szmonth, "%d", atoi(linfo.szRunmonths) + atoi(szmonth));
  1220. sprintf_s(szday, "%d", atoi(linfo.szRundays) + atoi(szday));
  1221. sprintf_s(szhour, "%d", atoi(linfo.szRunhours) + atoi(szday));
  1222. sprintf_s(szminute, "%d", atoi(linfo.szRunminutes) + atoi(szminute));
  1223. }
  1224. else
  1225. {
  1226. sprintf_s(szyear, "%s", linfo.szRunyears);
  1227. sprintf_s(szmonth, "%s", linfo.szRunmonths);
  1228. sprintf_s(szday, "%s", linfo.szRundays);
  1229. sprintf_s(szhour, "%s", linfo.szRunhours);
  1230. sprintf_s(szminute, "%s", linfo.szRunminutes);
  1231. }
  1232. // 生成时间授权码;
  1233. CHAR szOutString[100] = { 0 }; // 返回的时间授权码;
  1234. if ((nRet = MakeTimerAuth(g_szUserKey, dwShortKey, szyear, szmonth, szday, szhour, szminute, szOutString, szKeyPath)) != 0)
  1235. {
  1236. // 生成时间授权码失败;
  1237. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1238. return FALSE;
  1239. }
  1240. CHAR HKey[9] = "FFFFFFFF", LKey[9] = "FFFFFFFF";
  1241. CHAR WHKey[41] = "0", WLKey[41] = "0";
  1242. memcpy(WHKey, szOutString, 40);
  1243. memcpy(WLKey, &szOutString[40], 40);
  1244. // 写授权时间到加密锁中;
  1245. if ((nRet = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, dwShortKey, szyear, szmonth, szday, szhour, szminute, szKeyPath)) != 0)
  1246. {
  1247. // 写授权时间失败;
  1248. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1249. return FALSE;
  1250. }
  1251. DWORD dwID;
  1252. // 30000以后的储存空间为公共区域;
  1253. if ((nRet = ReadTimeAuthFromEprom(WHKey, WLKey, szOutString, &dwID, 30128, "FFFFFFFF", "FFFFFFFF", szKeyPath)) == 0)
  1254. {
  1255. #ifdef UNICODE
  1256. WCHAR *pOutString = ascii2unicode(szOutString);
  1257. _stprintf_s(lpCouldRundate, sizeOfcouldrundate, _T("%s"), pOutString);
  1258. delete pOutString;
  1259. pOutString = NULL;
  1260. #else
  1261. _stprintf_s(lpCouldRundate, sizeOfcouldrundate, _T("%s"), szOutString);
  1262. #endif
  1263. }
  1264. else
  1265. {
  1266. AfxMessageBox(GetYtUSBKey32ErrInfo(nRet));
  1267. }
  1268. return TRUE;
  1269. }
  1270. //////////////////////////////////////////////////////////////////////////
  1271. // 应用接口;
  1272. BOOL GetFirstYtUSBSoftVer(IN INT &nSoftVer, IN CHAR *pBranchIdBuffer, IN size_t sizeOfBranchIdBuffer, IN CONST INT &nUSBStartPos /* = 0 */)
  1273. {
  1274. INT nRetval = 0;
  1275. INT nVal[8] = { 0 };
  1276. DOUBLE fVal[8] = { 0.0 };
  1277. CHAR s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  1278. BOOL bFind = FALSE;
  1279. CHAR szKeyPath[MAX_PATH] = "";
  1280. for (INT nIndex = nUSBStartPos; nIndex < 256; nIndex++)
  1281. {
  1282. memset(szKeyPath, 0, sizeof(szKeyPath));
  1283. nRetval = FindPort(nIndex, szKeyPath);
  1284. if (nRetval != 0 && nIndex == 0) continue;
  1285. if (nRetval != 0) continue;
  1286. for (int i = 0; i < 6; i++)
  1287. {
  1288. // 使用该设备路径锁进行运算;
  1289. nRetval = CalEx(g_byShotVersion[i], 10,
  1290. &nVal[0], &nVal[1], &nVal[2], &nVal[3], &nVal[4], &nVal[5], &nVal[6], &nVal[7],
  1291. &fVal[0], &fVal[1], &fVal[2], &fVal[3], &fVal[4], &fVal[5], &fVal[6], &fVal[7],
  1292. s0, s1, s2, s3, s4, s5, s6, s7, szKeyPath, 20000);
  1293. //如果正确,则返回该设备路径供以后使用;
  1294. if (nRetval == -63) continue;
  1295. if ((nRetval == 0) && (nVal[0] == 123))
  1296. {
  1297. bFind = TRUE;
  1298. nSoftVer = i;
  1299. sprintf_s(pBranchIdBuffer, sizeOfBranchIdBuffer, "%s", s0);
  1300. break;
  1301. }
  1302. }
  1303. if (bFind) break;
  1304. }
  1305. return bFind;
  1306. }
  1307. CONST TCHAR* GetYtUSBKey32ErrInfo(IN const long lError)
  1308. {
  1309. INT nIndex = -1;
  1310. TCHAR *pErrorDescription = NULL;
  1311. while (g_YtError[++nIndex].nErrorCode != -10000)
  1312. {
  1313. if (lError == g_YtError[nIndex].nErrorCode)
  1314. {
  1315. pErrorDescription = g_YtError[nIndex].pErrorDescription;
  1316. break;
  1317. }
  1318. }
  1319. if (pErrorDescription == NULL)
  1320. pErrorDescription = _T("未知错误!\n");
  1321. OutputDebugString(pErrorDescription);
  1322. return pErrorDescription;
  1323. }
  1324. };