//--------------------------------------------------------------------------- #include #include #include #include #include #include #pragma hdrstop #include "ProtectCard.h" #include "Define.h" #include "Des.h" #include "Pcilib.h" #ifndef LOCK_CRYPKEY #include "Common.h" #endif #ifdef HASPSRM #include "seedx.h" #include "HaspCheckThread.h" #endif //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- #define IDS_HASPKEYNOTFOUND StringTable[128] //--------------------------------------------------------------------------- #define CPORT 0xE0 // Æ÷Æ® ½ÃÀÛ ÁÖ¼Ò //--------------------------------------------------------------------------- //v10 = ÃÖÃÊÀÇ PCI¹öÀü //TexTricot Ãß°¡ //v11 = ¹öÀüÁ¤º¸ÀÇ »óÀ§4 bits¸¦ »©¿È //Tex3D, TexStylist Ãß°¡ #define MaxIFCVersion 11 //--------------------------------------------------------------------------- TProtectCard *ProtectCard; //--------------------------------------------------------------------------- int __fastcall toJulian() { SYSTEMTIME st; int jyear, jmonth, jul, greg, curDay, ja; GetLocalTime(&st); jyear = st.wYear; jmonth = st.wMonth; if (st.wYear < 0) jyear++; if (st.wMonth > 2) jmonth++; else { jyear--; jmonth += 13; } jul = 365.25*jyear + 30.6001*jmonth + st.wDay + 1720995.0; greg = 15 + 31*(10+12*1582); curDay = st.wDay + 31*(st.wMonth +12*st.wYear); if (curDay >= greg) { ja = 0.01*jyear; jul += 2-ja+(0.25*ja); } return jul; } //--------------------------------------------------------------------------- static bool __fastcall checkTime() { unsigned char blk[8], k[8] = {'^', '*', 'F', 'S', '0', '>', '?', '['}; int nowJul, pastJul, due, sumDay; TRegIniFile *RegIniFile; AnsiString pw; int timePass[4]; RegIniFile = new TRegIniFile(RegFilename); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey(RegFilename + "\\",true); // yw if (RegIniFile) { pw = RegIniFile->ReadString("Common", "Product No.", ""); if (pw == "") goto fail; sscanf(pw.c_str(), "%d-%d-%d-%d", &timePass[0], &timePass[1], &timePass[2], &timePass[3]); delete RegIniFile; } else return false; blk[0] = timePass[0] & 0xFF; blk[1] = (timePass[0] >> 8) & 0xFF; blk[2] = timePass[1] & 0xFF; blk[3] = (timePass[1] >> 8) & 0xFF; blk[4] = timePass[2] & 0xFF; blk[5] = (timePass[2] >> 8) & 0xFF; blk[6] = timePass[3] & 0xFF; blk[7] = (timePass[3] >> 8) & 0xFF; decrypt(k, blk); sumDay = blk[0]; sumDay |= blk[1] << 8; sumDay |= blk[2] << 16; sumDay |= blk[3] << 24; pastJul = sumDay; sumDay = blk[4]; sumDay |= blk[5] << 8; sumDay |= blk[6] << 16; sumDay |= blk[7] << 24; due = sumDay; nowJul = toJulian(); if (nowJul >= pastJul) { if (nowJul < (pastJul + due)) return true; else return false; } else return false; fail : delete RegIniFile; return true; } //--------------------------------------------------------------------------- //#ifndef LOCK_CRYPKEY #ifdef LOCK_IFC //--------------------------------------------------------------------------- static Byte __stdcall InportByte(Word port) { if(GetDeviceOK()){ Byte cc; AtWriteB(iatpci.cs[ATPCI_CS3]+0,port); // port´Â CPORTºÎÅÍ ½ÃÀÛÇÑ´Ù //(Byte)portÇØµµ µÈ´Ù AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x10); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x14); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x1D); cc = AtReadB(iatpci.cs[ATPCI_CS3]+8); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x00); return cc; } else { asm { mov dx, port xor ax, ax in al, dx } } } //--------------------------------------------------------------------------- static Word __stdcall InportWord(Word port) { asm { mov dx, port in ax, dx } } //--------------------------------------------------------------------------- static void __stdcall OutportByte(Word port, Byte data) { if(GetDeviceOK()){ AtWriteB(iatpci.cs[ATPCI_CS3]+0,port); // port´Â CPORTºÎÅÍ ½ÃÀÛÇÑ´Ù //(Byte)portÇØµµ µÈ´Ù AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x10); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x14); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x16); AtWriteB(iatpci.cs[ATPCI_CS3]+0,data); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x10); AtWriteB(iatpci.cs[ATPCI_CS3]+4,0x00); } else { asm { mov dx, port mov al, data out dx, al } } } //--------------------------------------------------------------------------- static void __stdcall OutportWord(Word port, Word data) { asm { mov dx, port mov ax, data out dx, ax } } //--------------------------------------------------------------------------- #ifdef ACADEMY //--------------------------------------------------------------------------- #define OK 0x4F4B static Word CPort = 0xFEE0; //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- bool __fastcall TProtectCard::status_chk(Byte d) { int i, lp = 10000; for (i=0; i>= 2; if (status_chk(1)==false) goto fail; for (j=0; j>= 2; if (status_chk(1)==false) goto fail; } OutportByte(CPort, ((dt&3)|0x4)<<4); OutportByte(CPort, (((dt&3)|9)&0xb)<<4); if (status_chk(2)==false) goto fail; OutportByte(CPort, 0xf0); return true; fail: OutportByte(CPort, 0xf0); return false; } //--------------------------------------------------------------------------- int __fastcall TProtectCard::receive() { int i, j, d, dt, lp = 10000; for (i=j=dt=0; i=0) { pw = d; return true; } } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::GetData(Word &pw) { if (send(4, 0x64)) { int d = receive(); if (d>=0) { pw = d; return true; } } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::PutData(Word d) { return send(12, 0x440000+d) && receive()==OK; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::rand16(Byte lp, Word &seed) { int i, j, k; if (password(0, seed)) { for (k=0; k>9)^seed)>>3; j = ((seed>>1)^seed)>>14; seed <<= 1; seed |= ((i^j)&1); } return true; } return false; } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Init() { if (!checkTime()) return false; int j = (CPort>>2)&0xfc; if (send(12, 0x410000+(j<<8)+j) && receive()==OK) { return WritePassword(); } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::SerialNO(Cardinal &no) { if (send(4, 0x4E)) { int d = receive(); if (d>=0) { no = d; return true; } } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Information(Word &infor) { if (send(4, 0x4D)) { int d = receive(); if (d>=0) { infor = d; return true; } } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::ReadPassword() { Word lp, pw1, pw2; if (GetData(lp)) { if (rand16(lp, pw2)) { if (password(lp, pw1)) { if (pw1==pw2) return true; } } } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::WritePassword() { Word seed = rand(); if (PutData(seed&0x0F)) { return send(12, 0x530000+seed) && receive()==OK; } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::CheckPassword() { if (ReadPassword()) { if (WritePassword()) return true; } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::SetTimer(Byte msec) { return send(8, 0x5700+msec) && receive()==OK; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::GetTimer(Byte &msec) { if (send(4, 0x52)) { int d = receive(); if (d>=0) { msec = d; return true; } } return false; } //--------------------------------------------------------------------------- #else // ACADEMY //--------------------------------------------------------------------------- static Word CPort; static Word CPassL, CPassH; static Byte vBoard; static Byte buf; //--------------------------------------------------------------------------- __fastcall TProtectCard::TProtectCard() { AppStart(); } //--------------------------------------------------------------------------- __fastcall TProtectCard::~TProtectCard() { AppEnd(); } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Check(int id) { int t; clock_t c; OutportByte(CPort, id); c = clock(); t = 25; SetTimer(t); while (1) { if (GetTimer()==t) t = t-1; if (t==0) break; if (clock()-c>=5) break; } return t<24; } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- int __fastcall TProtectCard::Init(AnsiString rfn) { Byte vb; if(GetDeviceOK()){ if (!checkTime()) return 0; CPort = CPORT; vb = InportByte(CPort+0x0F); vBoard = vb & 0x0F;//ÇÏÀ§ 4ºñÆ®´Â ¹öÀü Á¤º¸//»óÀ§ 4ºñÆ®´Â ¾ÆÀÌÅÛ Á¤º¸ if (vBoard<10 || vBoard>MaxIFCVersion) { // 10Àº PCI ¹öÀüÀÇ ÃÖ¼Ò°ª return 0; } else { OutportByte(CPort, 0);// 0 == id // CPassL = CPort+0x110; // CPassH = CPort+0x111; CPassL = CPort+0x10; CPassH = CPort+0x11; WritePassword(); return ( (vb & 0xF0) << 8 ) + (InportByte(CPort+0x0A) & 0xFF); } } else { try { TRegIniFile *RegIniFile; int id; if (!checkTime()) return 0; CPort = 0xFDE0; RegIniFile = new TRegIniFile(rfn); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey(RegFilename + "\\",true); // yw if (RegIniFile) { id = RegIniFile->ReadInteger("Device", "IFCid", 0); delete RegIniFile; } else id = 0; if (id>1) { switch (id) { case 1: CPort = 0xFEE0; break; case 2: CPort = 0xFE00; break; } if (Check(id)==false) { CPort = 0xFDE0; id = 0; if (Check(id)==false) { return 0; } } } vb = InportByte(CPort+0x0F); vBoard = vb & 0x0F;//ÇÏÀ§ 4ºñÆ®´Â ¹öÀü Á¤º¸//»óÀ§ 4ºñÆ®´Â ¾ÆÀÌÅÛ Á¤º¸ if (vBoard<8 || vBoard>MaxIFCVersion) return 0; else { RegIniFile = new TRegIniFile(rfn); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey(RegFilename + "\\",true); // yw if (RegIniFile) { id = RegIniFile->ReadInteger("Device", "IFCid", 0); delete RegIniFile; } else id = 0; if (id>2) id = 0; switch (id) { case 1: CPort = 0xFEE0; break; case 2: CPort = 0xFE00; break; } OutportByte(CPort, id); if (CPort==0xFDE0) { CPassL = CPort+0x110; CPassH = CPort+0x111; } else { CPassL = CPort+0x10; CPassH = CPort+0x11; } WritePassword(); return InportByte(CPort+0x0A) & 0x7F; //return ( (vb & 0xF0) << 8 ) + (InportByte(CPort+0x0A) & 0xFF);// ISA ¹öÀü¿¡´Â 0x7F ÀÌ»óÀÇ ¾ÆÀÌÅÛÀº ¾ø´Ù } } catch(...) { return 0; } } } //--------------------------------------------------------------------------- int __fastcall TProtectCard::Version() { return vBoard; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::ReadPassword() { Word Rand; int i, c1, c2; buf = InportByte(CPassL); Rand = 0x4500+buf; if (vBoard<4) { OutportByte(CPassL, 0); buf = InportByte(CPassH); return buf==0x55; } else { while (1) { buf = InportByte(CPassH); if ((buf & 0x80)==0) break; } for (i=0; i<=15; i++) { c1 = ((Rand >> 3) & 1) ^ ((Rand >> 12) & 1); c2 = ((Rand >> 14) & 1) ^ ((Rand >> 15) & 1); Rand = Rand << 1; Rand = Rand+(c1 ^ c2); } buf = InportByte(CPassH); return buf==(Rand & 0x7F); } } //--------------------------------------------------------------------------- void __fastcall TProtectCard::WritePassword() { Byte pass; if (vBoard<4) { OutportByte(CPassL, 0x55); OutportByte(CPassH, 0x55); } else { pass = 0; while (pass==0) { pass = rand()&0xFF; } OutportByte(CPassL, pass); OutportByte(CPassH, 0x80); } } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::CheckPassword() { if (ReadPassword()) { WritePassword(); return true; } return false; } //--------------------------------------------------------------------------- void __fastcall TProtectCard::SetTimer(Byte msec) { OutportByte(CPort+1, msec); } //--------------------------------------------------------------------------- Byte __fastcall TProtectCard::GetTimer() { return InportByte(CPort+1); } //--------------------------------------------------------------------------- #endif // ACADEMY //--------------------------------------------------------------------------- #else // LOCK_IFC //¿©±â±îÁö IFC //--------------------------------------------------------------------------- #ifdef NETHASP #define IS_HASP 1 #define GET_HASP_CODE 41 #define READ_MEMO 44 #define WRITE_MEMO 45 #define GET_HASP_STATUS 5 #define GET_ID_NUM 46 #define READ_MEMO_BLOCK 52 #define WRITE_MEMO_BLOCK 53 #else #define IS_HASP 1 #define GET_HASP_CODE 2 #define READ_MEMO 3 #define WRITE_MEMO 4 #define GET_HASP_STATUS 5 #define GET_ID_NUM 6 #define READ_MEMO_BLOCK 50 #define WRITE_MEMO_BLOCK 51 #endif //--------------------------------------------------------------------------- static Byte DesKey[14][13] = { " ", "eUvJ-nvh?aq9", "EmTxOX'60af#", "i'/[E15)'FU9", "5sv1Bt<_M,c!", "KF/ZPw7> 8) & 0xFF; blk[2] = pw[1] & 0xFF; blk[3] = (pw[1] >> 8) & 0xFF; blk[4] = pw[2] & 0xFF; blk[5] = (pw[2] >> 8) & 0xFF; blk[6] = pw[3] & 0xFF; blk[7] = (pw[3] >> 8)&0xFF; decrypt(k, blk); SeedCode = (blk[1] << 8) | blk[0]; Pass[0] = (blk[3] << 8) | blk[2]; Pass[1] = (blk[5] << 8) | blk[4]; Pass[2] = (blk[7] << 8) | blk[6]; #ifndef NETHASP hasp(IS_HASP, 0, 0, Pass1, Pass2, &p1, &p2, &p3, &p4); if (p1==0) return -2; #endif #ifdef NETHASP hasp(GET_HASP_CODE, SeedCode, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); #else hasp(GET_HASP_CODE, SeedCode, 0, Pass1, Pass2, &p1, &p2, &p3, &p4); #endif if (Pass[0]!=p1 || Pass[1]!=p2 || Pass[2]!=p3) return -3; p1 = 0; /* Address */ p2 = 0; #ifdef NETHASP hasp(READ_MEMO, 0, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); #else hasp(READ_MEMO, 0, 0, Pass1, Pass2, &p1, &p2, &p3, &p4); #endif if (p3!=0) return -4; item = p2; p1 = 1; /* Address */ p2 = 0; #ifdef NETHASP hasp(READ_MEMO, 0, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); #else hasp(READ_MEMO, 0, 0, Pass1, Pass2, &p1, &p2, &p3, &p4); #endif if (p3!=0) return -5; if (p2 == 0xFFFF) p2 = 0; return (p2<<14) | item; } //--------------------------------------------------------------------------- void __fastcall TProtectCard::Read() { int p1, p2, p3, p4; if (hasp && pwIndex==0) { pwIndex = 1+rand()%13; p1 = pwIndex*4; p2 = 4; p4 = int(pwData+pwIndex*8); #ifdef NETHASP hasp(READ_MEMO_BLOCK, SeedCode, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); #else hasp(READ_MEMO_BLOCK, SeedCode, 0, Pass1, Pass2, &p1, &p2, &p3, &p4); #endif } } //--------------------------------------------------------------------------- void __fastcall TProtectCard::Check() { Byte *pw, blk[8]; if (hasp && pwIndex) { pw = (Byte *)malloc(112); if (pw) { memcpy(pw, pwData, 112); memcpy(blk, pw+pwIndex*8, 8); strcpy(DesKey[0], DesKey[pwIndex]); decrypt(DesKey[0], blk); isHacking = (SeedCode==((blk[1]<<8)|blk[0])) && (Pass[0]==((blk[3]<<8)|blk[2])) && (Pass[1]==((blk[5]<<8)|blk[4])) && (Pass[2]==((blk[7]<<8)|blk[6])) ? false : true; pwIndex = 0; free(pw); } } } //--------------------------------------------------------------------------- void __fastcall TProtectCard::Lock_Check() { #ifndef LOCK_CRYPKEY //ConfigurationÀÌ CrypKey·Î Compile µÇ±â ¶§¹®¿¡... #ifdef TEXWORK // TPException ec = EC_NONE; int Items; //============================================================================== unsigned char blk[8], k[8] = { 'T', 'e', 'x', 'p', 'i', 'a', 0, 0 }; unsigned char blk2[8], k2[8] = { 'T', 'e', 'x', 'p', 'i', 'a', 0, 0 }; int p1, p2, p3, p4; Byte *pw; Byte blk_check[8], k_check[8] = { 'T', 'e', 'x', 'p', 'i', 'a', 0, 0 }; int SeedCode2, Pass_2[3], Password_hasp[4]; TRegIniFile *RegIniFile; AnsiString pw1; RegIniFile = new TRegIniFile(RegFilename); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey(RegFilename + "\\",true); // yw if (RegIniFile) { pw1 = RegIniFile->ReadString("Common", "Serial", ""); sscanf(pw1.c_str(), "%d-%d-%d-%d", &Password[0], &Password[1], &Password[2], &Password[3]); } blk_check[0] = Password[0] & 0xFF; blk_check[1] = (Password[0] >> 8) & 0xFF; blk_check[2] = Password[1] & 0xFF; blk_check[3] = (Password[1] >> 8) & 0xFF; blk_check[4] = Password[2] & 0xFF; blk_check[5] = (Password[2] >> 8) & 0xFF; blk_check[6] = Password[3] & 0xFF; blk_check[7] = (Password[3] >> 8)&0xFF; decrypt(k_check, blk_check); SeedCode = (blk_check[1] << 8) | blk_check[0]; hasp(GET_HASP_CODE, SeedCode, 2, Pass1, Pass2, &Pass[0], &Pass[1], &Pass[2], &p4); blk[0] = SeedCode & 0xFF; blk[1] = (SeedCode >> 8) & 0xFF; blk[2] = Pass[0] & 0xFF; blk[3] = (Pass[0] >> 8) & 0xFF; blk[4] = Pass[1] & 0xFF; blk[5] = (Pass[1] >> 8) & 0xFF; blk[6] = Pass[2] & 0xFF; blk[7] = (Pass[2] >> 8) & 0xFF; encrypt(k, blk); Password_hasp[0] = (blk[1]<<8)|blk[0]; Password_hasp[1] = (blk[3]<<8)|blk[2]; Password_hasp[2] = (blk[5]<<8)|blk[4]; Password_hasp[3] = (blk[7]<<8)|blk[6]; blk2[0] = Password_hasp[0] & 0xFF; blk2[1] = (Password_hasp[0] >> 8) & 0xFF; blk2[2] = Password_hasp[1] & 0xFF; blk2[3] = (Password_hasp[1] >> 8) & 0xFF; blk2[4] = Password_hasp[2] & 0xFF; blk2[5] = (Password_hasp[2] >> 8) & 0xFF; blk2[6] = Password_hasp[3] & 0xFF; blk2[7] = (Password_hasp[3] >> 8)&0xFF; decrypt(k2, blk2); SeedCode2 = (blk2[1] << 8) | blk2[0]; Pass_2[0] = (blk2[3] << 8) | blk2[2]; Pass_2[1] = (blk2[5] << 8) | blk2[4]; Pass_2[2] = (blk2[7] << 8) | blk2[6]; hasp(GET_HASP_CODE, SeedCode2, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); if (Pass_2[0] == p1 && Pass_2[1] == p2 && Pass_2[2] == p3) { if (hasp) { pwIndex = 1; p1 = pwIndex*4; p2 = 4; p4 = int(pwData+pwIndex*8); hasp(READ_MEMO_BLOCK, SeedCode, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); } if (hasp) { pw = (Byte *)malloc(112); if (pw) { memcpy(pw, pwData, 112); memcpy(blk2, pw+pwIndex*8, 8); strcpy(DesKey[0], DesKey[pwIndex]); decrypt(DesKey[0], blk2); isHacking = (SeedCode2==((blk2[1]<<8)|blk2[0])) ? false : true; free(pw); } } if(isHacking) { // ec = EC_HASPKEYNOTFOUND; goto fail; } } //============================================================================== p1 = 0; /* Address */ p2 = 0; hasp(READ_MEMO, 0, 2, Pass1, Pass2, &p1, &p2, &p3, &p4); Items = p2; if (Items<1 || (Items&PCN_TEXWORK)!=PCN_TEXWORK) { // ec = EC_HASPKEYNOTFOUND; goto fail; } return; fail: ShowMessage(IDS_HASPKEYNOTFOUND); Application->Terminate(); #endif #endif } //--------------------------------------------------------------------------- //¿©±âºÎÅÍ HASPSRM #else //--------------------------------------------------------------------------- ///YOUNGW01.hvc ///HASP Master key°¡ º¯°æµÇ¸é ÀÌ ºÎºÐÀ» º¯°æÇØ¾ß ÇÑ´Ù. unsigned char vendor_code[] = "XiwC3NVFGFJcvdfsb7yFLg69msXGBYsGYFOj3bekzaTcAwLfp+9C2zLo8Ln3lYLaLjpNKNuyprVMJjz+" "nXXhlhuvVhGqymnPZW6jQTksBYqRhjXZAR1Kh9a2Ib+xjDMHYsDtv/y2MRqgaKOA8rd1sIxwbpEa9b3z" "QXBAOSb1EvlOhSO3B+NPadR1vzYaJdQUJAjPFKHoSgANDx94TlIzEm87AMMtsDaWSuORp93nJPLJy9wE" "SSIb45JptVruJ2TgsTIWdvKkvT+YD6QdhNRHfdRiMkU41yOBHXOCZH6BHNTp4kAB0GBvizlXpjh9IIgG" "RDBrpJIYlz+zX2eV8lakDhi9DyI4v4e/DM2J5XLl84D7j/Hv3gHfYFzyMAfnZvA78sKPEuiwdzAjmMI9" "PpHr+vKIHF0V4lPizlOj209D55yRmA0ip9egxgbqnf3sotHaGAtnl4wbHwNcaaWmLMzk/GH2LSbBYchU" "uGd3VFMEuOtjHLObrMFPNt9vewIoNDhjGgCYU4VysHjVf30Z2PidJh+J8CLgwUX1wZCRLH1J1Vr1W2TU" "XSugjijNpeAhlJaepzhaJwAQYE1pva3BAtrgdD06G94/ygEZeuOZ6fNOi2etBMNRu5kq70cg0d7ylnbZ" "k9bSWJL9cCkW1Y3AQU1gAHFBxxVwKbzOx5UhI1T4mf3244jqhQThOsd5NqheDlsJpv9EyLP92+eLYxb4" "wnoOQ4hTrleujIOUy1LcoX9VdtkNvjiW5EeIsI+ASiZwZrlv8XDo5vMhnei4L31Km4BHlI4UnWkXVvV9" "XxSVNN9xDAPiOeGNLqRR1oOaouP8Bza1UH2u5KNNroaH25vzjYzLya96ECpbobZutl7OcsdYQbrWQdVG" "JDbmljUYFVOGaF7Tzi2kknZAQaDnJoGVNstWsu4RukbHOmdX1GimMtOH0pc="; //--------------------------------------------------------------------------- __fastcall TProtectCard::TProtectCard() { hLibrary = LoadLibrary(String("hasp_windows.dll").c_str()); handle = HASP_INVALID_HANDLE_VALUE; isHacking = false; featureId = HASP_DEFAULT_FID; bLockIsHacked = false; } //--------------------------------------------------------------------------- __fastcall TProtectCard::~TProtectCard() { Logout(); if (hLibrary) FreeLibrary(hLibrary); hLibrary = NULL; } //--------------------------------------------------------------------------- void __fastcall TProtectCard::GetFeatureId() { if ((int)ProgramIndex <= (int)hsNetKnit ) { switch(ProgramIndex) { case hsTextile: case hsWeave: case hsKnit: featureId = 1; break; case hsNetWeave: featureId = 2; break; case hsNetKnit: featureId = 3; break; } } else { featureId = (int)ProgramIndex - 4; //Tex3D Feature ID = 4; } } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Init(EHaspProgramIndex index, String programVersion) { unsigned char data[112] = {0}; unsigned char pbData[112] = {0}; int stNo = 0; if (!hLibrary) { Application->MessageBox("HASP DLL NOT FOUND", "Warning", MB_OK); goto fail; } _hasp_login = (THASP_LOGIN)GetProcAddress(hLibrary, "hasp_login"); _hasp_logout = (THASP_LOGOUT)GetProcAddress(hLibrary, "hasp_logout"); _hasp_get_info = (THASP_GET_INFO)GetProcAddress(hLibrary, "hasp_get_info"); _hasp_get_sessioninfo = (THASP_GET_SESSIONINFO)GetProcAddress(hLibrary, "hasp_get_sessioninfo"); _hasp_free = (THASP_FREE)GetProcAddress(hLibrary, "hasp_free"); _hasp_read = (THASP_READ)GetProcAddress(hLibrary, "hasp_read"); ProgramIndex = index; ProgramVersion = programVersion; #ifdef NETHASP GetFeatureId(); #endif if (!Login(featureId)) goto fail; if (!GetHaspID()) goto fail; if (!Hasp_Read(data)) goto fail; if (!DecryptData(data, pbData)) goto fail; stNo = pbData[0]; info = pbData[0+stNo]; temp = pbData[1+stNo]; memset(program, 0, sizeof(unsigned char)*6); memset(version, 0, sizeof(unsigned char)*30); memcpy(program, &pbData[2+stNo], 5); memcpy(version, &pbData[7+stNo], 29); //Get8Bytes_ForSerial(pbData); if (!Get8Bytes_ForSerialOld(pbData)) goto fail; return true; fail: return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Login(int featureId) { hasp_status_t status; if (handle != HASP_INVALID_HANDLE_VALUE) { Logout(); handle = HASP_INVALID_HANDLE_VALUE; } if (_hasp_login == NULL) return false; status = _hasp_login(featureId, vendor_code, &handle); String msg; /* check if operation was successful */ if (status != HASP_STATUS_OK) { switch (status) { case HASP_FEATURE_NOT_FOUND: msg = "HASP_FEATURE_NOT_FOUND"; break; case HASP_HASP_NOT_FOUND: msg = "HASP_NOT_FOUND"; break; case HASP_OLD_DRIVER: msg = "HASP_OLD_DRIVER"; break; case HASP_NO_DRIVER: msg = "HASP_NO_DRIVER"; break; case HASP_INV_VCODE: msg = "HASP_INV_VCODE"; break; case HASP_FEATURE_TYPE_NOT_IMPL: msg = "HASP_FEATURE_TYPE_NOT_IMPL"; break; case HASP_TMOF: msg = "HASP_TMOF"; break; case HASP_TS_DETECTED: msg = "HASP_TS_DETECTED"; break; case HASP_TOO_MANY_USERS: msg = "HASP_TOO_MANY_USERS"; break; default: msg = "ERROR Code(Status): " + IntToStr((int)status); break; } Application->MessageBox(msg.c_str(), "LOGIN ERROR", MB_OK); return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Logout() { hasp_status_t status; if (handle == HASP_INVALID_HANDLE_VALUE) return true; if (_hasp_logout == NULL) return false; status = _hasp_logout(handle); handle = HASP_INVALID_HANDLE_VALUE; String msg; /* check if operation was successful */ if (status != HASP_STATUS_OK) { switch (status) { case HASP_INV_HND: msg = "HASP_INV_HND"; break; default: msg = "ERROR Code(Status): " + IntToStr((int)status); break; } Application->MessageBox(msg.c_str(), "LOGOUT ERROR", MB_OK); return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::GetHaspID() { hasp_status_t status; char *info = 0; const char* scope = "" ""; const char* format = "" "" " " " " " " " " " " " " " " ""; if (_hasp_get_info == NULL) return false; status = _hasp_get_info(scope, format, vendor_code, &info); /* check if operation was successful */ String msg; if (status != HASP_STATUS_OK) { switch (status) { case HASP_INV_FORMAT: msg = "HASP GET INFO ERROR\nHASP_INV_FORMAT"; break; default: msg = "HASP GET INFO ERROR"; break; } Application->MessageBox(msg.c_str(), "Warning", MB_OK); _hasp_free(info); return false; } String infoAnsi = info; int hasp_id_pos = 0; int length = 0; int st = 0, ed = 0; if (infoAnsi.IsEmpty()) goto fail; hasp_id_pos = infoAnsi.Pos("hasp id"); length = infoAnsi.Length() - hasp_id_pos - 1; for (int i = hasp_id_pos; i < length; i++) { if (infoAnsi.c_str()[i] == '\"' && st == 0) st = i; else if (infoAnsi.c_str()[i] == '\"' && st != 0) { ed = i; break; } } HaspID = infoAnsi.SubString(st+2, ed-st-1); if (HaspID.IsEmpty()) goto fail; /* use the information, free it afterwards */ _hasp_free(info); return true; fail: return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::Hasp_Read(unsigned char *data) { hasp_size_t offset = 0; hasp_size_t len = 112; String msg; hasp_status_t status; if (_hasp_read == NULL) return false; if (handle == HASP_INVALID_HANDLE_VALUE) { if (!Login(featureId)) return false; } status = _hasp_read(handle, HASP_FILEID_RW, offset, len, data); /* check if operation was successful */ if (status != HASP_STATUS_OK) { switch (status) { case HASP_FEATURE_NOT_FOUND: msg = "HASP_FEATURE_NOT_FOUND"; break; case HASP_INV_HND: msg = "HASP_INV_HND"; break; case HASP_INV_FILEID: msg = "HASP_INV_FILEID"; break; case HASP_MEM_RANGE: msg = "HASP_MEM_RANGE"; break; case HASP_BROKEN_SESSION: msg = "HASP_BROKEN_SESSION"; break; default: msg = "ERROR Code(Status): " + IntToStr((int)status); break; } Application->MessageBox(msg.c_str(), "HASP_READ ERROR", MB_OK); return false; } return true; } // --------------------------------------------------------------------------- bool __fastcall TProtectCard::DecryptData(unsigned char *data, unsigned char* pbData) { BYTE btType; BYTE btTemp; BYTE t_pbData[17] = {0}; BYTE pbUserKey[16] = {'T', 'e', 'x', 'p', 'i', 'a', 'Y', 'W', '2', '0', '1', '1', 'p', 's', 'h', 0}; DWORD pdwRoundKey[32] = {0}; //¾Ïȣȭ Ű »ý¼º... SeedEncRoundKey(pdwRoundKey, pbUserKey); //Encryption Key //16bytes ÀÌÇϸ¦ ¾Ïȣȭ Çϸé 16bytes·Î ¾Ïȣȭ µÇ¾î Ãâ·ÂµÈ´Ù. //16bytes ³ª´²¼­ ¾Ïȣȭ¸¦ ÇØ¾ß¸¸ ÇÑ´Ù. //16 * 7 = 112 for (int i = 0; i < 7; i++) { memset(t_pbData, 0, sizeof(BYTE)*17); memcpy(t_pbData, &data[16*i], sizeof(BYTE)*16); SeedDecrypt(t_pbData, pdwRoundKey);// Encryption memcpy(&pbData[16*i], t_pbData, sizeof(unsigned char)*16); } return true; } // --------------------------------------------------------------------------- bool __fastcall TProtectCard::Get8Bytes_ForSerial(unsigned char* pbData) { //29¹øÂ° byte¿¡ Serial ¹øÈ£°¡ µé¾î°¥ ½ÃÀÛ ÁÖ¼Ò°¡ ÀÖ´Ù. int stNum = pbData[56]; unsigned char blk[8] = {0}, rValue[8] = {0}; unsigned char k[8] = { 'T', 'E', 'X', 'p', 'i', 'a', 0, 0 }; int length = HaspID.Length(); int quotient = length/3; int remainder = length%3; int pw[4] = {0}, pwById[4] = {0}; //HASP ID°¡ 15ÀÚ¸®¸¦ ³ÑÁö ¾Ê´Â °ÍÀ¸·Î È®ÀÎÇß´Ù. //¿Ö 15ÀÚ¸®¸¦ üũÇ߳ĸé 15¸¦ 3À¸·Î ³ª´©¸é 5ÀÚ¸®°¡ ³ª¿Â´Ù. //½Ã¸®¾ó¹øÈ£¸¦ ¸¸µå´Â Å©±â´Â 2byteÀ̰í 0xFFFF = 65535ÀÌ´Ù. //3À¸·Î ³ª´« ¸òÀ¸·Î IDÀÇ ÀÚ¸®¸¦ ³ª´«´Ù. //±×·¡¼­ ¾Æ·¡¿Í °°ÀÌ pw¿¡ ³Ö¾ú´Ù. //4°³ÀÇ 2bytes·Î ½Ã¸®¾óÀ» ¸¸µé±â À§Çؼ­ÀÌ´Ù. String temp; for (int i = 0, st = 0, ed = 0; i < 3; i++) { pwById[1+i] = 0; ed += quotient; temp = ""; if (i == 2) ed += remainder; for (int j = st; j < ed && ed <= length; j++) { temp += HaspID.c_str()[j]; } if (!temp.IsEmpty()) { pwById[1+i] = temp.ToInt(); } st = ed; } //int¸¦ 2 bytes¿¡ ³ª´²¼­ Áý¾î ³Ö±â ¶§¹®¿¡ 3°³ÀÇ int°¡ 0xFFFFº¸´Ù Å©¸é ¹®Á¦°¡ //¹ß»ýÇÑ´Ù. µû¶ó¼­ ¾Æ·¡ if¹®¿¡¼­ Ȥ½Ã³ª Å« idÀÏ °æ¿ì¸¦ À§ÇØ Ã¼Å©¸¦ ÇÑ´Ù. if (quotient >= 5) { for (int i = 0; i < 3; i++) { if (pwById[i] > 0xFFFF) pwById[i] = 0xFFFF; } } memcpy(rValue, &pbData[stNum], sizeof(unsigned char)*8); blk[1] = rValue[0]; blk[0] = rValue[1]; blk[3] = rValue[2]; blk[2] = rValue[3]; blk[5] = rValue[4]; blk[4] = rValue[5]; blk[7] = rValue[6]; blk[6] = rValue[7]; decrypt(k, blk); pw[0] = (blk[1] << 8) | blk[0]; pw[1] = (blk[3] << 8) | blk[2]; pw[2] = (blk[5] << 8) | blk[4]; pw[3] = (blk[7] << 8) | blk[6]; //ŰÀÇ id·Î ¸¸µé¾î ³õÀº pwById¿Í Ű¿¡ ½á³õÀº pw¿Í ÀÏÄ¡ÇÏÁö ¾ÊÀ¸¸é //۸¦ Á¤»óÀûÀ¸·Î ¸¸µç °ÍÀÌ ¾Æ´Ï¶ó º¹»çÇÑ °ÍÀ¸·Î ÆÇ´ÜÇÑ´Ù. // if (pw[1] != pwById[1] || pw[2] != pwById[2] || pw[3] != pwById[3]) { // Application->MessageBox("Key is hacked!", "Warning", MB_OK); // return false; // } serial[0] = (rValue[0]<<8)|rValue[1]; serial[1] = (rValue[2]<<8)|rValue[3]; serial[2] = (rValue[4]<<8)|rValue[5]; serial[3] = (rValue[6]<<8)|rValue[7]; seedcode = pw[0]; return true; } // --------------------------------------------------------------------------- ///±âÁ¸ HASP4 ¹æ½ÄÀ¸·Î SerialÀ» ¸¸µé¾î¼­ »ç¿ëÇÒ °æ¿ì ÀÌ¿ë ///HASP ¸Þ¸ð¸®¿¡ ÀúÀåµÈ Äڵ尪(Serial)°ú HASP4·Î °Ë»öÇÑ return °ªÀÌ °°ÀºÁö È®ÀÎ bool __fastcall TProtectCard::Get8Bytes_ForSerialOld(unsigned char* pbData) { //29¹øÂ° byte¿¡ Serial ¹øÈ£°¡ µé¾î°¥ ½ÃÀÛ ÁÖ¼Ò°¡ ÀÖ´Ù. int stNum = pbData[56]; unsigned char blk[8] = {0}, rValue[8] = {0}; unsigned char k[8] = { 'T', 'e', 'x', 'p', 'i', 'a', 0, 0 }; int Pass1 = 7221, Pass2 = 17162, p4; int Pass[3] = {0}, pw[4] = {0}; HINSTANCE oldLibrary = NULL; memcpy(rValue, &pbData[stNum], sizeof(unsigned char)*8); blk[1] = rValue[0]; blk[0] = rValue[1]; blk[3] = rValue[2]; blk[2] = rValue[3]; blk[5] = rValue[4]; blk[4] = rValue[5]; blk[7] = rValue[6]; blk[6] = rValue[7]; decrypt(k, blk); pw[0] = (blk[1] << 8) | blk[0]; pw[1] = (blk[3] << 8) | blk[2]; pw[2] = (blk[5] << 8) | blk[4]; pw[3] = (blk[7] << 8) | blk[6]; seedcode = pw[0]; THASP hasp = NULL; oldLibrary = LoadLibrary(String("haspms32.dll").c_str()); if (oldLibrary) hasp = (THASP)GetProcAddress(oldLibrary, "hasp"); else goto fail; /* Get HASP code */ hasp(GET_HASP_CODE, seedcode, 0, Pass1, Pass2, &Pass[0], &Pass[1], &Pass[2], &p4); if (pw[1] != Pass[0] || pw[2] != Pass[1] || pw[3] != Pass[2]) { #ifndef NETHASP Application->MessageBox("Key is hacked!", "Warning", MB_OK); #endif goto fail; } if (oldLibrary) FreeLibrary(oldLibrary); oldLibrary = NULL; serial[0] = (rValue[0]<<8)|rValue[1]; serial[1] = (rValue[2]<<8)|rValue[3]; serial[2] = (rValue[4]<<8)|rValue[5]; serial[3] = (rValue[6]<<8)|rValue[7]; return true; fail: if (oldLibrary) FreeLibrary(oldLibrary); oldLibrary = NULL; return false; } //--------------------------------------------------------------------------- /** »õ·Î¿î ÇÁ·Î±×·¥ÀÌ Ãß°¡ µÇ¸é À̰÷¿¡ index¸¦ ó¸®ÇÏ´Â ºÎºÐÀ» Ãß°¡ÇÑ´Ù. */ bool __fastcall TProtectCard::isProgram(EHaspProgramIndex index) { if (index < 8) { if (program[0] & 0x80 && index == hsTextile) return true; else if (program[0] & 0x40 && index == hsWeave) return true; else if (program[0] & 0x20 && index == hsKnit) return true; else if (program[0] & 0x10 && index == hsN3D) return true; else if (program[0] & 0x8 && index == hsNetWeave) return true; else if (program[0] & 0x4 && index == hsNetKnit) return true; } else if (index < 16) { if (program[1] & 0x80 && index == hsTex3D) return true; else if (program[1] & 0x40 && index == hs3DVeiwer) return true; else if (program[1] & 0x20 && index == hsWebTex3D) return true; else if (program[1] & 0x10 && index == hsWebTex3DSim) return true; else if (program[1] & 0x8 && index == hsTexWork) return true; else if (program[1] & 0x4 && index == hsTexStylist) return true; else if (program[1] & 0x2 && index == hsTexWeave) return true; else if (program[1] & 0x1 && index == hsTexTricot) return true; } else if (index < 32) { if (program[2] & 0x80 && index == hsTexPrint) return true; else if (program[2] & 0x40 && index == hsTexKnit) return true; else if (program[2] & 0x20 && index == hsTexCoordi) return true; else if (program[2] & 0x10 && index == hsImageUpload) return true; } return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::isNetHasp() { if (info & 0x80) return true; else return false; } //--------------------------------------------------------------------------- bool __fastcall TProtectCard::isHacked(bool bThread) { if (bThread) { HaspCheckThread = new THaspCheckThread(ProgramIndex, ProgramVersion); return false; } else { TRegIniFile *RegIniFile = NULL; AnsiString pw; //unsigned char blk[8] = {0}; //unsigned char k[8] = { 'T', 'E', 'X', 'p', 'i', 'a', 0, 0 }; int pw_bySerial[4] = {0}, stNo = 0; unsigned char data[112] = {0}; unsigned char pbData[112] = {0}; isHacking = false; //if (!Login(featureId)) goto fail; //if (!GetHaspID()) goto fail; if (!Hasp_Read(data)) goto fail; if (!DecryptData(data, pbData)) goto fail; //if (!Get8Bytes_ForSerial(pbData)) goto fail; if (!Get8Bytes_ForSerialOld(pbData)) goto fail; stNo = pbData[0]; memset(program, 0, sizeof(unsigned char)*6); memset(version, 0, sizeof(unsigned char)*30); memcpy(program, &pbData[2+stNo], 5); memcpy(version, &pbData[7+stNo], 29); if (!isProgram(ProgramIndex)) goto fail; if (getVersion() != ProgramVersion) goto fail; RegIniFile = new TRegIniFile(RegFilename); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey(RegFilename + "\\",true); if (RegIniFile) { pw = RegIniFile->ReadString("Common", "Serial", ""); sscanf(pw.c_str(), "%d-%d-%d-%d", &Password[0], &Password[1], &Password[2], &Password[3]); delete RegIniFile; RegIniFile = NULL; } if (Password[0] != serial[0] || Password[1] != serial[1] || Password[2] != serial[2] || Password[3] != serial[3]) { Application->MessageBox("Serial No. is invalid!", "Warning", MB_OK); isHacking = true; //ÇØÅ· } #ifdef NETHASP if (!ProtectCard->isNetHasp()) isHacking = true; #else if (ProtectCard->isNetHasp()) isHacking = true; #endif return isHacking; //Á¤»ó fail: if (RegIniFile) delete RegIniFile; RegIniFile = NULL; isHacking = true; return isHacking; } } //--------------------------------------------------------------------------- String __fastcall TProtectCard::getVersion() { String sVertion; if (ProgramIndex == hsTextile || ProgramIndex == hsWeave || ProgramIndex == hsKnit || ProgramIndex == hsN3D || ProgramIndex == hsNetWeave || ProgramIndex == hsNetKnit) { sVertion = IntToStr((int)version[0]); } else if (ProgramIndex >= hsTex3D && ProgramIndex <= hsWebTex3DSim) { sVertion = IntToStr((int)version[1]); } else { sVertion = IntToStr((int)version[((int)ProgramIndex - (int)hsTexWork)+2]); } sVertion = sVertion.Insert(".", sVertion.Length()); return sVertion; } //--------------------------------------------------------------------------- int __fastcall TProtectCard::getType() { int rtValue; if (info & 0x8) rtValue = 0;//"Professional"; else if (info & 0x4) rtValue = 1;//"Education"; else if (info & 0x2) rtValue = 2;//"Demo"; else rtValue = 3;//"Academy"; return rtValue; } //--------------------------------------------------------------------------- int __fastcall TProtectCard::getCountry() { int rtValue; if (info & 0x40) rtValue = 1; else rtValue = 0; return rtValue; } //--------------------------------------------------------------------------- #endif //¿©±â±îÁö HASPSRM //--------------------------------------------------------------------------- #endif // LOCK_IFC //#endif // defined not crypkey.....