From 1fc8e65dd319abf0bac6ce753bb87ecbabd8b177 Mon Sep 17 00:00:00 2001 From: Mataes Date: Wed, 16 May 2018 21:12:31 +0300 Subject: Flags, CrashDumper, CryptoPP, CSList, Db_autobackups, DbEditorPP: cmplugin adaptation --- plugins/CryptoPP/src/GPGw/gpg_main.cpp | 162 ++++++++++++++++----------------- plugins/CryptoPP/src/GPGw/gpgw.h | 1 - plugins/CryptoPP/src/commonheaders.h | 29 +++--- plugins/CryptoPP/src/cpp_gpgw.cpp | 10 +- plugins/CryptoPP/src/cpp_pgpw.cpp | 38 ++++---- plugins/CryptoPP/src/cryptopp.h | 63 +++++++------ plugins/CryptoPP/src/main.cpp | 16 +--- 7 files changed, 158 insertions(+), 161 deletions(-) (limited to 'plugins/CryptoPP/src') diff --git a/plugins/CryptoPP/src/GPGw/gpg_main.cpp b/plugins/CryptoPP/src/GPGw/gpg_main.cpp index 311d7daa7c..f0b96bcf47 100644 --- a/plugins/CryptoPP/src/GPGw/gpg_main.cpp +++ b/plugins/CryptoPP/src/GPGw/gpg_main.cpp @@ -10,8 +10,8 @@ char logfile[fullfilenamesize]; char *txtbeginpgppublickeyblock="-----BEGIN PGP PUBLIC KEY BLOCK-----"; char *txtendpgppublickeyblock="-----END PGP PUBLIC KEY BLOCK-----"; */ -char *txtbeginpgpmessage="-----BEGIN PGP MESSAGE-----"; -char *txtendpgpmessage="-----END PGP MESSAGE-----"; +char *txtbeginpgpmessage = "-----BEGIN PGP MESSAGE-----"; +char *txtendpgpmessage = "-----END PGP MESSAGE-----"; void __cdecl ErrorMessage(const char *alevel, const char *atext, const char *ahint) { @@ -28,10 +28,10 @@ void __cdecl LogMessage(const char *astart, const char *atext, const char *aend) { FILE *log; - if(logfile[0]=='\0') return; + if (logfile[0] == '\0') return; - log=fopen(logfile, "a"); - if(log!=NULL) + log = fopen(logfile, "a"); + if (log != NULL) { fputs(astart, log); fputs(atext, log); @@ -42,8 +42,8 @@ void __cdecl LogMessage(const char *astart, const char *atext, const char *aend) int __cdecl _gpg_init() { - GetTempPath(sizeof(temporarydirectory),temporarydirectory); - logfile[0]='\0'; + GetTempPath(sizeof(temporarydirectory), temporarydirectory); + logfile[0] = '\0'; initPassphrases(); initKeyUserIDs(publickeyuserid); initKeyUserIDs(secretkeyuserid); @@ -62,13 +62,13 @@ int __cdecl _gpg_done() int __cdecl _gpg_open_keyrings(LPSTR ExecPath, LPSTR HomePath) { - if ( !ExecPath || (!*ExecPath && !ShowSelectExecDlg(ExecPath)) ) { + if (!ExecPath || (!*ExecPath && !ShowSelectExecDlg(ExecPath))) { return 0; } - if ( !HomePath || (!*HomePath && !ShowSelectHomeDlg(HomePath)) ) { + if (!HomePath || (!*HomePath && !ShowSelectHomeDlg(HomePath))) { return 0; } - if ( !existsFile(ExecPath) ) { + if (!existsFile(ExecPath)) { // ErrorMessage(txtwarning, txtinvalidexecutable, txtverifyoptions); return 0; } @@ -94,15 +94,15 @@ LPSTR __cdecl _gpg_get_error() void __cdecl _gpg_set_log(LPCSTR LogPath) { - if(LogPath) strncpy(logfile,LogPath,sizeof(logfile)); - else logfile[0]='\0'; + if (LogPath) strncpy(logfile, LogPath, sizeof(logfile)); + else logfile[0] = '\0'; } void __cdecl _gpg_set_tmp(LPCSTR TmpPath) { - if(TmpPath) strncpy(temporarydirectory,TmpPath,sizeof(temporarydirectory)); - else GetTempPath(sizeof(temporarydirectory),temporarydirectory); + if (TmpPath) strncpy(temporarydirectory, TmpPath, sizeof(temporarydirectory)); + else GetTempPath(sizeof(temporarydirectory), temporarydirectory); } @@ -110,21 +110,21 @@ LPSTR __cdecl _gpg_get_passphrases() { size_t i; char *b, x; - b = (char *) LocalAlloc(LPTR,(keyuseridsize+passphrasesize)*passphrasecount+1); *b = '\0'; + b = (char *)LocalAlloc(LPTR, (keyuseridsize + passphrasesize)*passphrasecount + 1); *b = '\0'; - for(i=0; i<(size_t)passphrasecount; i++) { - strcat(b,passphrases[i].keyuserid); strcat(b,"\x01"); - strcat(b,passphrases[i].passphrase); strcat(b,"\x02"); + for (i = 0; i < (size_t)passphrasecount; i++) { + strcat(b, passphrases[i].keyuserid); strcat(b, "\x01"); + strcat(b, passphrases[i].passphrase); strcat(b, "\x02"); } // encrypt - for(i=0; i2 ) { - x = b[i] ^ ( (i&0x7f) ^ 13); - if ( x>2 ) b[i]=x; + for (i = 0; i < strlen(b); i++) + if (b[i] > 2) { + x = b[i] ^ ((i & 0x7f) ^ 13); + if (x > 2) b[i] = x; } - return b; + return b; } @@ -132,25 +132,25 @@ void __cdecl _gpg_set_passphrases(LPCSTR buffer) { size_t i, l = strlen(buffer); char *t, *p, *b, x; - if ( !l ) return; + if (!l) return; - b = (char *) LocalAlloc(LPTR,l+1); + b = (char *)LocalAlloc(LPTR, l + 1); strcpy(b, buffer); // decrypt - for(i=0; i2 ) { - x = b[i] ^ ( (i&0x7f) ^ 13); - if ( x>2 ) b[i]=x; + for (i = 0; i < strlen(b); i++) + if (b[i] > 2) { + x = b[i] ^ ((i & 0x7f) ^ 13); + if (x > 2) b[i] = x; } - while(*b) { + while (*b) { t = strchr(b, '\x02'); - if(t) { + if (t) { *t = '\0'; p = strchr(b, '\x01'); *p = '\0'; - addPassphrase(b, p+1); + addPassphrase(b, p + 1); t++; } b = t; @@ -165,16 +165,16 @@ LPSTR __cdecl _gpg_encrypt(LPCSTR message, LPCSTR keyid) char *encmessage = 0; gpgResult gpgresult; - if(strlen(keyid)) + if (strlen(keyid)) { memset(buffer, 0, sizeof(buffer)); - gpgresult=gpgEncrypt(buffer, keyid, message); + gpgresult = gpgEncrypt(buffer, keyid, message); - if(gpgresult!=gpgSuccess) + if (gpgresult != gpgSuccess) return 0; - size_t encmessagelen = strlen(buffer)+1; - encmessage = (char *) LocalAlloc(LPTR,encmessagelen); + size_t encmessagelen = strlen(buffer) + 1; + encmessage = (char *)LocalAlloc(LPTR, encmessagelen); memcpy(encmessage, buffer, encmessagelen); } @@ -196,64 +196,64 @@ LPSTR __cdecl _gpg_decrypt(LPCSTR message) const char *begin = strstr(message, txtbeginpgpmessage); const char *end = strstr(message, txtendpgpmessage); - if ((begin!=NULL)&&(end!=NULL)) + if ((begin != NULL) && (end != NULL)) { strcpy(buffer, ""); - strncat(buffer, begin, end-begin+strlen(txtendpgpmessage)); + strncat(buffer, begin, end - begin + strlen(txtendpgpmessage)); replace(buffer, "\r", ""); replace(buffer, "\n", txtcrlf); memset(keyuserid, 0, sizeof(keyuserid)); - gpgresult=gpgDetectUserID(keyuserid, buffer); - storedpassphrase=NULL; + gpgresult = gpgDetectUserID(keyuserid, buffer); + storedpassphrase = NULL; - if(gpgresult!=gpgSuccess) + if (gpgresult != gpgSuccess) { // ErrorMessage(txtwarning, txtdetectuseridfailed, txtverifyoptions); strcpy(keyuserid, txtunknownuserid); - useridvalid=FALSE; + useridvalid = FALSE; } else { - storedpassphrase=getPassphrase(keyuserid); - useridvalid=TRUE; + storedpassphrase = getPassphrase(keyuserid); + useridvalid = TRUE; } - if(storedpassphrase!=NULL) + if (storedpassphrase != NULL) { strcpy(passphrase, storedpassphrase); memset(plaintext, 0, sizeof(plaintext)); - gpgresult=gpgDecrypt(plaintext, buffer, passphrase); + gpgresult = gpgDecrypt(plaintext, buffer, passphrase); } - else gpgresult=gpgUnknownError; + else gpgresult = gpgUnknownError; - dlgresult=IDOK; - while((gpgresult!=gpgSuccess)&&(dlgresult!=IDCANCEL)) + dlgresult = IDOK; + while ((gpgresult != gpgSuccess) && (dlgresult != IDCANCEL)) { - dlgresult=DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_PASSPHRASE), NULL, PassphraseDialogProcedure, (LPARAM)keyuserid); + dlgresult = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), NULL, PassphraseDialogProcedure, (LPARAM)keyuserid); - if(dlgresult==IDOK) + if (dlgresult == IDOK) { strcpy(passphrase, dlgpassphrase); memset(dlgpassphrase, 0, passphrasesize); strcat(passphrase, txtcrlf); memset(plaintext, 0, sizeof(plaintext)); - gpgresult=gpgDecrypt(plaintext, buffer, passphrase); + gpgresult = gpgDecrypt(plaintext, buffer, passphrase); } } - if(gpgresult==gpgSuccess) + if (gpgresult == gpgSuccess) { strcpy(buffer, plaintext); } - if ( gpgresult==gpgSuccess && useridvalid==TRUE) + if (gpgresult == gpgSuccess && useridvalid == TRUE) addPassphrase(keyuserid, passphrase); SecureZeroMemory(passphrase, sizeof(passphrase)); - size_t decmessagelen = strlen(buffer)+1; - decmessage = (char *) LocalAlloc(LPTR,decmessagelen); + size_t decmessagelen = strlen(buffer) + 1; + decmessage = (char *)LocalAlloc(LPTR, decmessagelen); memcpy(decmessage, buffer, decmessagelen); } @@ -272,32 +272,32 @@ int __cdecl _gpg_select_keyid(HWND hdlg, LPSTR keyid) int dlgresult; memset(keyid, 0, keyidsize); - dlgresult=DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_SELECTKEY), hdlg, UserIdDialogProcedure, (LPARAM)keyid); + dlgresult = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SELECTKEY), hdlg, UserIdDialogProcedure, (LPARAM)keyid); - if(dlgresult!=IDOK) + if (dlgresult != IDOK) memset(keyid, 0, keyidsize); - return (dlgresult==IDOK); + return (dlgresult == IDOK); } void noBackslash(LPSTR path) { LPSTR ptr = path + strlen(path) - 1; - if ( *ptr=='\\' ) *ptr = '\0'; + if (*ptr == '\\') *ptr = '\0'; } static char buf[MAX_PATH]; -LPSTR GetRegValue(HKEY hKey , LPCSTR szPath, LPCSTR szName) +LPSTR GetRegValue(HKEY hKey, LPCSTR szPath, LPCSTR szName) { - DWORD len=MAX_PATH,type; - LPSTR ret=0; + DWORD len = MAX_PATH, type; + LPSTR ret = 0; - RegOpenKey(hKey,szPath,&hKey); - if ( RegQueryValueEx(hKey,szName,NULL,&type,(LPBYTE)&buf,&len)==ERROR_SUCCESS ) { + RegOpenKey(hKey, szPath, &hKey); + if (RegQueryValueEx(hKey, szName, NULL, &type, (LPBYTE)&buf, &len) == ERROR_SUCCESS) { noBackslash((LPSTR)&buf); ret = (LPSTR)&buf; } @@ -309,9 +309,9 @@ LPSTR GetRegValue(HKEY hKey , LPCSTR szPath, LPCSTR szName) LPSTR GetEnvValue(LPCSTR szName) { - LPSTR ret=0; + LPSTR ret = 0; - if ( GetEnvironmentVariable(szName, buf, MAX_PATH) > 0 ) { + if (GetEnvironmentVariable(szName, buf, MAX_PATH) > 0) { noBackslash((LPSTR)&buf); ret = (LPSTR)&buf; } @@ -325,15 +325,15 @@ BOOL ShowSelectExecDlg(LPSTR path) OPENFILENAME ofn; memset(&ofn, 0, sizeof(ofn)); - ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","gpgProgram"); - if ( ofn.lpstrFile && existsFile(ofn.lpstrFile) ) { + ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", "gpgProgram"); + if (ofn.lpstrFile && existsFile(ofn.lpstrFile)) { strcpy(path, ofn.lpstrFile); return TRUE; } - ofn.lpstrFile = GetRegValue(HKEY_LOCAL_MACHINE,"Software\\GNU\\GnuPG","Install Directory"); - if ( ofn.lpstrFile ) { - strcat(ofn.lpstrFile,"\\gpg.exe"); - if ( existsFile(ofn.lpstrFile) ) { + ofn.lpstrFile = GetRegValue(HKEY_LOCAL_MACHINE, "Software\\GNU\\GnuPG", "Install Directory"); + if (ofn.lpstrFile) { + strcat(ofn.lpstrFile, "\\gpg.exe"); + if (existsFile(ofn.lpstrFile)) { strcpy(path, ofn.lpstrFile); return TRUE; } @@ -357,19 +357,19 @@ BOOL ShowSelectHomeDlg(LPSTR path) OPENFILENAME ofn; ofn.lpstrFile = GetEnvValue("GNUPGHOME"); - if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) { + if (ofn.lpstrFile && existsPath(ofn.lpstrFile)) { strcpy(path, ofn.lpstrFile); return TRUE; } - ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","HomeDir"); - if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) { + ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", "HomeDir"); + if (ofn.lpstrFile && existsPath(ofn.lpstrFile)) { strcpy(path, ofn.lpstrFile); return TRUE; } ofn.lpstrFile = GetEnvValue("APPDATA"); - if ( ofn.lpstrFile ) { - strcat(ofn.lpstrFile,"\\gnupg"); - if ( existsPath(ofn.lpstrFile) ) { + if (ofn.lpstrFile) { + strcat(ofn.lpstrFile, "\\gnupg"); + if (existsPath(ofn.lpstrFile)) { strcpy(path, ofn.lpstrFile); return TRUE; } @@ -385,7 +385,7 @@ BOOL ShowSelectHomeDlg(LPSTR path) if (!GetOpenFileName(&ofn)) return FALSE; int i; - for(i = (int)strlen(path);i && path[i]!='\\';i--); + for (i = (int)strlen(path); i && path[i] != '\\'; i--); path[i] = 0; return TRUE; diff --git a/plugins/CryptoPP/src/GPGw/gpgw.h b/plugins/CryptoPP/src/GPGw/gpgw.h index 041c79abc5..aefa913d04 100644 --- a/plugins/CryptoPP/src/GPGw/gpgw.h +++ b/plugins/CryptoPP/src/GPGw/gpgw.h @@ -39,7 +39,6 @@ extern char *txtendpgpmessage; extern LPCSTR szModuleName; extern LPCSTR szVersionStr; -extern HINSTANCE g_hInst; #define DLLEXPORT __declspec(dllexport) diff --git a/plugins/CryptoPP/src/commonheaders.h b/plugins/CryptoPP/src/commonheaders.h index e959912d38..0925c0881f 100644 --- a/plugins/CryptoPP/src/commonheaders.h +++ b/plugins/CryptoPP/src/commonheaders.h @@ -5,13 +5,13 @@ #define CRYPTOPP_DEFAULT_NO_DLL #ifdef _MSC_VER - #pragma once - #define _CRT_SECURE_NO_WARNINGS - #define _SCL_SECURE_NO_WARNINGS - #define NOMINMAX - #ifndef _WIN64 - #define _USE_32BIT_TIME_T - #endif +#pragma once +#define _CRT_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_WARNINGS +#define NOMINMAX +#ifndef _WIN64 +#define _USE_32BIT_TIME_T +#endif #endif #include @@ -32,7 +32,6 @@ #define M_API_H__ // Miranda API -#define __NO_CMPLUGIN_NEEDED #include #include #include @@ -55,11 +54,17 @@ #define MODULENAME "Crypto++" +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(MODULENAME) + {} +}; + extern LPCSTR szModuleName; extern LPCSTR szVersionStr; // shared vars -extern HINSTANCE g_hInst; extern PLUGININFOEX pluginInfoEx; extern HANDLE hPGPPRIV; @@ -67,7 +72,7 @@ extern HANDLE hRSA4096; extern mir_cs localQueueMutex; -void ExtractFile(char*,int,int); +void ExtractFile(char*, int, int); size_t rtrim(LPCSTR); std::string base64encode(const std::string&); @@ -78,14 +83,14 @@ std::string base64decode(const char *); extern HNETLIBUSER hNetlibUser; void InitNetlib(); void DeinitNetlib(); -int Sent_NetLog(const char *,...); +int Sent_NetLog(const char *, ...); #endif #define DLLEXPORT __declspec(dllexport) PBYTE cpp_alloc_pdata(pCNTX); -extern "C" +extern "C" { DLLEXPORT HANDLE __cdecl cpp_create_context(int); // create crypt-context DLLEXPORT void __cdecl cpp_delete_context(HANDLE); // delete crypt-context diff --git a/plugins/CryptoPP/src/cpp_gpgw.cpp b/plugins/CryptoPP/src/cpp_gpgw.cpp index bda82d6e6f..6141ee8796 100644 --- a/plugins/CryptoPP/src/cpp_gpgw.cpp +++ b/plugins/CryptoPP/src/cpp_gpgw.cpp @@ -7,21 +7,21 @@ PBYTE pRS_gpg; int __cdecl _gpg_init(void); int __cdecl _gpg_done(void); -int __cdecl _gpg_open_keyrings(LPSTR,LPSTR); +int __cdecl _gpg_open_keyrings(LPSTR, LPSTR); int __cdecl _gpg_close_keyrings(void); void __cdecl _gpg_set_log(LPCSTR); void __cdecl _gpg_set_tmp(LPCSTR); LPSTR __cdecl _gpg_get_error(void); int __cdecl _gpg_size_keyid(void); -int __cdecl _gpg_select_keyid(HWND,LPSTR); -LPSTR __cdecl _gpg_encrypt(LPCSTR,LPCSTR); +int __cdecl _gpg_select_keyid(HWND, LPSTR); +LPSTR __cdecl _gpg_encrypt(LPCSTR, LPCSTR); LPSTR __cdecl _gpg_decrypt(LPCSTR); LPSTR __cdecl _gpg_get_passphrases(); void __cdecl _gpg_set_passphrases(LPCSTR); int __cdecl gpg_init() { - hgpg = g_hInst; + hgpg = g_plugin.getInst(); return _gpg_init(); } @@ -71,7 +71,7 @@ LPSTR __cdecl gpg_encrypt(pCNTX ptr, LPCSTR szPlainMsg) return ptr->tmp = nullptr; } else { - ptr->tmp = mir_strdup(szEncMsg); + ptr->tmp = mir_strdup(szEncMsg); LocalFree((LPVOID)szEncMsg); return ptr->tmp; } diff --git a/plugins/CryptoPP/src/cpp_pgpw.cpp b/plugins/CryptoPP/src/cpp_pgpw.cpp index d574c2f236..4c148cffec 100644 --- a/plugins/CryptoPP/src/cpp_pgpw.cpp +++ b/plugins/CryptoPP/src/cpp_pgpw.cpp @@ -8,31 +8,31 @@ PBYTE pRS_pgp; int __cdecl _pgp_init(void); int __cdecl _pgp_done(void); -int __cdecl _pgp_open_keyrings(LPSTR,LPSTR); +int __cdecl _pgp_open_keyrings(LPSTR, LPSTR); int __cdecl _pgp_close_keyrings(void); int __cdecl _pgp_get_version(void); LPSTR __cdecl _pgp_get_error(void); int __cdecl _pgp_size_keyid(void); -PVOID __cdecl _pgp_select_keyid(HWND,LPSTR); -LPSTR __cdecl _pgp_encrypt_keydb(LPCSTR,PVOID); +PVOID __cdecl _pgp_select_keyid(HWND, LPSTR); +LPSTR __cdecl _pgp_encrypt_keydb(LPCSTR, PVOID); LPSTR __cdecl _pgp_decrypt_keydb(LPCSTR); //int __cdecl _pgp_check_key(LPCSTR); -LPSTR __cdecl _pgp_encrypt_key(LPCSTR,LPCSTR); -LPSTR __cdecl _pgp_decrypt_key(LPCSTR,LPCSTR); - -int (__cdecl *p_pgp_init)(void); -int (__cdecl *p_pgp_done)(void); -int (__cdecl *p_pgp_open_keyrings)(LPSTR,LPSTR); -int (__cdecl *p_pgp_close_keyrings)(void); -int (__cdecl *p_pgp_get_version)(void); -LPSTR (__cdecl *p_pgp_get_error)(void); -int (__cdecl *p_pgp_size_keyid)(void); -PVOID (__cdecl *p_pgp_select_keyid)(HWND,LPSTR); -LPSTR (__cdecl *p_pgp_encrypt_keydb)(LPCSTR,PVOID); -LPSTR (__cdecl *p_pgp_decrypt_keydb)(LPCSTR); +LPSTR __cdecl _pgp_encrypt_key(LPCSTR, LPCSTR); +LPSTR __cdecl _pgp_decrypt_key(LPCSTR, LPCSTR); + +int(__cdecl *p_pgp_init)(void); +int(__cdecl *p_pgp_done)(void); +int(__cdecl *p_pgp_open_keyrings)(LPSTR, LPSTR); +int(__cdecl *p_pgp_close_keyrings)(void); +int(__cdecl *p_pgp_get_version)(void); +LPSTR(__cdecl *p_pgp_get_error)(void); +int(__cdecl *p_pgp_size_keyid)(void); +PVOID(__cdecl *p_pgp_select_keyid)(HWND, LPSTR); +LPSTR(__cdecl *p_pgp_encrypt_keydb)(LPCSTR, PVOID); +LPSTR(__cdecl *p_pgp_decrypt_keydb)(LPCSTR); //int (__cdecl *p_pgp_check_key)(LPCSTR); -LPSTR (__cdecl *p_pgp_encrypt_key)(LPCSTR,LPCSTR); -LPSTR (__cdecl *p_pgp_decrypt_key)(LPCSTR,LPCSTR); +LPSTR(__cdecl *p_pgp_encrypt_key)(LPCSTR, LPCSTR); +LPSTR(__cdecl *p_pgp_decrypt_key)(LPCSTR, LPCSTR); #define GPA(x) \ { \ @@ -97,7 +97,7 @@ int __cdecl pgp_init() memset(tmp->pdata, 0, sizeof(PGPDATA)); } - hpgpsdk = g_hInst; + hpgpsdk = g_plugin.getInst(); return 0; } diff --git a/plugins/CryptoPP/src/cryptopp.h b/plugins/CryptoPP/src/cryptopp.h index a13337f20e..a98b6204f5 100644 --- a/plugins/CryptoPP/src/cryptopp.h +++ b/plugins/CryptoPP/src/cryptopp.h @@ -107,7 +107,7 @@ typedef RSAPRIV* pRSAPRIV; typedef deque > STRINGDEQUE; -typedef queue STRINGQUEUE; +typedef queue STRINGQUEUE; typedef struct __RSADATA { @@ -120,7 +120,7 @@ typedef struct __RSADATA { string aes_v; // aes iv HANDLE thread; // thread handle BOOL thread_exit; - HANDLE event; // thread event + HANDLE event; // thread event STRINGQUEUE *queue; // thread queue } RSADATA; typedef RSADATA* pRSADATA; @@ -151,48 +151,47 @@ typedef RSADATA* pRSADATA; extern LPCSTR szModuleName; extern LPCSTR szVersionStr; -extern HINSTANCE g_hInst; pCNTX get_context_on_id(int); pCNTX get_context_on_id(HANDLE); void cpp_free_keys(pCNTX); -BYTE *cpp_gzip(BYTE*,size_t,size_t&); -BYTE *cpp_gunzip(BYTE*,size_t,size_t&); +BYTE *cpp_gzip(BYTE*, size_t, size_t&); +BYTE *cpp_gunzip(BYTE*, size_t, size_t&); string cpp_zlibc(string&); string cpp_zlibd(string&); typedef struct { - int (__cdecl *rsa_gen_keypair)(short); // генерит RSA-ключи для указанной длины (либо тока 2048, либо 2048 и 4096) - int (__cdecl *rsa_get_keypair)(short,PBYTE,int*,PBYTE,int*); // возвращает пару ключей для указанной длины - int (__cdecl *rsa_get_keyhash)(short,PBYTE,int*,PBYTE,int*); // возвращает hash пары ключей для указанной длины - int (__cdecl *rsa_set_keypair)(short,PBYTE,int); // устанавливает ключи, указанной длины - int (__cdecl *rsa_get_pubkey)(HANDLE,PBYTE,int*); // возвращает паблик ключ из указанного контекста - int (__cdecl *rsa_set_pubkey)(HANDLE,PBYTE,int); // загружает паблик ключ для указанного контекста - void (__cdecl *rsa_set_timeout)(int); // установить таймаут для установки секюрного соединения - int (__cdecl *rsa_get_state)(HANDLE); // получить статус указанного контекста - int (__cdecl *rsa_get_hash)(PBYTE,int,PBYTE,int*); // вычисляет SHA1(key) - int (__cdecl *rsa_connect)(HANDLE); // запускает процесс установки содинения с указанным контекстом - int (__cdecl *rsa_disconnect)(HANDLE); // разрывает соединение с указанным контекстом - int (__cdecl *rsa_disabled)(HANDLE); // разрывает соединение по причине "disabled" - LPSTR (__cdecl *rsa_recv)(HANDLE,LPCSTR); // необходимо передавать сюда все входящие протокольные сообщения - int (__cdecl *rsa_send)(HANDLE,LPCSTR); // вызываем для отправки сообщения клиенту - int (__cdecl *rsa_encrypt_file)(HANDLE,LPCSTR,LPCSTR); - int (__cdecl *rsa_decrypt_file)(HANDLE,LPCSTR,LPCSTR); - LPSTR (__cdecl *utf8encode)(LPCWSTR); - LPWSTR (__cdecl *utf8decode)(LPCSTR); - int (__cdecl *is_7bit_string)(LPCSTR); - int (__cdecl *is_utf8_string)(LPCSTR); - int (__cdecl *rsa_export_keypair)(short,LPSTR,LPSTR,LPSTR); // export private key - int (__cdecl *rsa_import_keypair)(short,LPSTR,LPSTR); // import & activate private key - int (__cdecl *rsa_export_pubkey)(HANDLE,LPSTR); // export public key from context - int (__cdecl *rsa_import_pubkey)(HANDLE,LPSTR); // import public key into context + int(__cdecl *rsa_gen_keypair)(short); // генерит RSA-ключи для указанной длины (либо тока 2048, либо 2048 и 4096) + int(__cdecl *rsa_get_keypair)(short, PBYTE, int*, PBYTE, int*); // возвращает пару ключей для указанной длины + int(__cdecl *rsa_get_keyhash)(short, PBYTE, int*, PBYTE, int*); // возвращает hash пары ключей для указанной длины + int(__cdecl *rsa_set_keypair)(short, PBYTE, int); // устанавливает ключи, указанной длины + int(__cdecl *rsa_get_pubkey)(HANDLE, PBYTE, int*); // возвращает паблик ключ из указанного контекста + int(__cdecl *rsa_set_pubkey)(HANDLE, PBYTE, int); // загружает паблик ключ для указанного контекста + void(__cdecl *rsa_set_timeout)(int); // установить таймаут для установки секюрного соединения + int(__cdecl *rsa_get_state)(HANDLE); // получить статус указанного контекста + int(__cdecl *rsa_get_hash)(PBYTE, int, PBYTE, int*); // вычисляет SHA1(key) + int(__cdecl *rsa_connect)(HANDLE); // запускает процесс установки содинения с указанным контекстом + int(__cdecl *rsa_disconnect)(HANDLE); // разрывает соединение с указанным контекстом + int(__cdecl *rsa_disabled)(HANDLE); // разрывает соединение по причине "disabled" + LPSTR(__cdecl *rsa_recv)(HANDLE, LPCSTR); // необходимо передавать сюда все входящие протокольные сообщения + int(__cdecl *rsa_send)(HANDLE, LPCSTR); // вызываем для отправки сообщения клиенту + int(__cdecl *rsa_encrypt_file)(HANDLE, LPCSTR, LPCSTR); + int(__cdecl *rsa_decrypt_file)(HANDLE, LPCSTR, LPCSTR); + LPSTR(__cdecl *utf8encode)(LPCWSTR); + LPWSTR(__cdecl *utf8decode)(LPCSTR); + int(__cdecl *is_7bit_string)(LPCSTR); + int(__cdecl *is_utf8_string)(LPCSTR); + int(__cdecl *rsa_export_keypair)(short, LPSTR, LPSTR, LPSTR); // export private key + int(__cdecl *rsa_import_keypair)(short, LPSTR, LPSTR); // import & activate private key + int(__cdecl *rsa_export_pubkey)(HANDLE, LPSTR); // export public key from context + int(__cdecl *rsa_import_pubkey)(HANDLE, LPSTR); // import public key into context } RSA_EXPORT; typedef RSA_EXPORT* pRSA_EXPORT; typedef struct { - int (__cdecl *rsa_inject)(HANDLE,LPCSTR); // вставляет сообщение в очередь на отправку - int (__cdecl *rsa_check_pub)(HANDLE,PBYTE,int,PBYTE,int); // проверяет интерактивно SHA и сохраняет ключ, если все нормально - void (__cdecl *rsa_notify)(HANDLE,int); // нотификация о смене состояния + int(__cdecl *rsa_inject)(HANDLE, LPCSTR); // вставляет сообщение в очередь на отправку + int(__cdecl *rsa_check_pub)(HANDLE, PBYTE, int, PBYTE, int); // проверяет интерактивно SHA и сохраняет ключ, если все нормально + void(__cdecl *rsa_notify)(HANDLE, int); // нотификация о смене состояния } RSA_IMPORT; typedef RSA_IMPORT* pRSA_IMPORT; diff --git a/plugins/CryptoPP/src/main.cpp b/plugins/CryptoPP/src/main.cpp index 922ca181ce..6c735ccbbd 100644 --- a/plugins/CryptoPP/src/main.cpp +++ b/plugins/CryptoPP/src/main.cpp @@ -1,9 +1,9 @@ #include "commonheaders.h" +CMPlugin g_plugin; int hLangpack; LPCSTR szModuleName = MODULENAME; LPCSTR szVersionStr = MODULENAME" DLL (" __VERSION_STRING_DOTS ")"; -HINSTANCE g_hInst; HANDLE hPGPPRIV = nullptr; HANDLE hRSA4096 = nullptr; @@ -24,12 +24,6 @@ PLUGININFOEX pluginInfoEx = { {0x3613F2D9, 0xC040, 0x4361, {0xA4, 0x4F, 0xDF, 0x7B, 0x5A, 0xAA, 0xCF, 0x6E}} }; -BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID) -{ - g_hInst = hInst; - return TRUE; -} - extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) { return &pluginInfoEx; @@ -46,7 +40,7 @@ int onModulesLoaded(WPARAM wParam, LPARAM lParam) extern "C" __declspec(dllexport) int Load() { - DisableThreadLibraryCalls(g_hInst); + DisableThreadLibraryCalls(g_plugin.getInst()); // get memoryManagerInterface address mir_getLP(&pluginInfoEx); @@ -66,15 +60,15 @@ extern "C" __declspec(dllexport) int Unload() BOOL ExtractFileFromResource(HANDLE FH, int ResType, int ResId, DWORD* Size) { - HRSRC RH = FindResource(g_hInst, MAKEINTRESOURCE(ResId), MAKEINTRESOURCE(ResType)); + HRSRC RH = FindResource(g_plugin.getInst(), MAKEINTRESOURCE(ResId), MAKEINTRESOURCE(ResType)); if (RH == nullptr) return FALSE; - PBYTE RP = (PBYTE)LoadResource(g_hInst, RH); + PBYTE RP = (PBYTE)LoadResource(g_plugin.getInst(), RH); if (RP == nullptr) return FALSE; - DWORD x, s = SizeofResource(g_hInst, RH); + DWORD x, s = SizeofResource(g_plugin.getInst(), RH); if (!WriteFile(FH, RP, s, &x, nullptr)) return FALSE; if (x != s) return FALSE; if (Size) *Size = s; -- cgit v1.2.3