[ Mr. Rejn @ 06.03.2006. 18:40 ] @
Hocu da zastitim deo koda pomocu sifrovanja asimetricnom enkripcijom, primerom iz ASProtect /examples direktorijuma-ideja je da se izvrsi sifrovanje koda koji se nalazi izmedju oznaka REG_CRYPT_BEGIN i REG_CRYPT_END kljucem koji je generisao ASProtect-kada to stavim u BCB6 projekat, to izgleda ovako: Code: #include <io.h> #include "asprotect.h" ... void __fastcall TForm1::Button1Click(TObject *Sender) { REG_CRYPT_BEGIN //Kod koji se sifruje: ShowMessage("Registracija programa je izvrsena!"); REG_CRYPT_END } ... gde je asprotect.h: Code: #ifndef ASPROTECT_H #define ASPROTECT_H #ifdef __BORLANDC__ #define REG_CRYPT_BEGIN __emit__ (0xEB,0x04,0xEB,0x05,0x89,0x01); #define REG_CRYPT_END __emit__ (0xEB,0x04,0xEB,0x05,0x99,0x01); #else #define REG_CRYPT_BEGIN \ __asm _emit 0xEB \ __asm _emit 0x04 \ __asm _emit 0xEB \ __asm _emit 0x05 \ __asm _emit 0x89 \ __asm _emit 0x01 #define REG_CRYPT_END \ __asm _emit 0xEB \ __asm _emit 0x04 \ __asm _emit 0xEB \ __asm _emit 0x05 \ __asm _emit 0x99 \ __asm _emit 0x01 #endif #define APIConst 0xFFFFFFFF #define capiDecrypt 4 #define capiGetRegInfo 5 #define capiGetTrialDays 8 #define capiGetTrialExecs 9 typedef DWORD (__stdcall *TapiDecrypt) (IN char *Key, IN DWORD KeySize); typedef char* (__stdcall *TapiGetRegInfo) (); typedef DWORD (__stdcall *TapiGetTrialDays) (); typedef DWORD (__stdcall *TapiGetTrialExecs) (); #endif ovo se kompajlira kako treba, zatim generisem kljuc u ASProtect (npr.key.bin), zatim se program obradi pomocu ASProtect.Onda se pokrene i kada se pritisne dugme-nista se ne dogadja, ne pojavljuje se Message "Registracija programa je izvrsena!" (tako treba i da bude), znaci kod izmedju oznaka je (valjda) sifrovan generisanim kljucem. E sad ide rutavi deo... Da bi se taj kod desifrovao, potrebno je spolja softverski ucitati fajl sa kljucem (npr. key.bin), ali kod koji je dat za primer je za VC++ i ne odgovara BCB-u, inache ovo stavljam u Unit1.cpp u Builder projektu posle include fajlova i onih #pragma delova, a ide ovako: Code: // // This example shows a way of using of external constant for fragment's decryption // #include <windows.h> #include <io.h> #include "asprotect.h" typedef void (__stdcall *TFunction) (); typedef void (__stdcall *TSetKeyProc) (IN char *Key, IN DWORD KeySize); void __stdcall Fake(); void __stdcall FakeSetKeyProc( char *Key, DWORD KeySize); TFunction DecryptProc = (void*) Fake, EncryptProc = (void*) Fake; TSetKeyProc SetKeyProc = (void*) FakeSetKeyProc; //---------------------------------------------------------------------- // Fake functions for debugging // void __stdcall Fake(){} void __stdcall FakeSetKeyProc( char *Key, DWORD KeySize){} //---------------------------------------------------------------------- // ASProtect will call these two functions for a setting // of pointers on functions for encryption and decryption of // fragments with REG_CRYPT_BEGIN and REG_CRYPT_END //---------------------------------------------------------------------- void __declspec(dllexport) __stdcall GetDecryptProc(void* DProc){ DecryptProc = DProc; } //---------------------------------------------------------------------- // // void __declspec(dllexport) __stdcall GetEncryptProc(void* DProc){ EncryptProc = DProc; } //---------------------------------------------------------------------- // This function gets pointer on function for setting of external key //---------------------------------------------------------------------- void __declspec(dllexport) __stdcall SetDecryptionKey(TSetKeyProc DProc){ SetKeyProc = DProc; } //---------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int f = -1; int fsize; unsigned char *fbuffer = NULL; char *message = "Neregistrovana verzija !"; if ((f = open("key.bin", 0)) != -1) { // Read a file with a constant for decryption fsize = filelength(f); fbuffer = malloc(fsize); read(f, fbuffer, fsize); // Set a constatnt to ASProtect SetKeyProc(fbuffer, fsize); // This is an example of dynamic decryption/encryption // of fragments // After a call of function DecryptProc all fragments will be decrypted DecryptProc(); REG_CRYPT_BEGIN MessageBeep(1); REG_CRYPT_END if (f != -1) close(f); REG_CRYPT_BEGIN //Kod koji se sifruje: ShowMessage("Registracija programa je izvrsena!"); REG_CRYPT_END // After a call of function EncryptProc all fragments will be encrypted again !!! EncryptProc(); if (fbuffer != NULL) free(fbuffer); } ShowMessage(message); } naravno bcc mi raspali ovo: Code: [C++ Error] Unit1.cpp(23): E2034 Cannot convert 'void *' to 'void (__stdcall *)()' [C++ Error] Unit1.cpp(24): E2034 Cannot convert 'void *' to 'void (__stdcall *)()' [C++ Error] Unit1.cpp(25): E2034 Cannot convert 'void *' to 'void (__stdcall *)(char *,unsigned long)' [C++ Error] Unit1.cpp(39): E2034 Cannot convert 'void *' to 'void (__stdcall *)()' [C++ Error] Unit1.cpp(46): E2034 Cannot convert 'void *' to 'void (__stdcall *)()' [C++ Error] Unit1.cpp(87): E2034 Cannot convert 'void *' to 'unsigned char *'//Ovo poslednje se odnosi na: fbuffer = malloc(fsize); Znaci ako neko ima pojma o cemu ovde pricam ili nekog iskustva u ovome bilo bi lepo da postuje nesto na ovo pitanje jer ovaj problem sigurno interesuje veci broj ljudi koji hoce da zastite program od crack-a. Poz. [Ovu poruku je menjao Mr. Rejn dana 07.03.2006. u 16:34 GMT+1] |