⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msrc4plugin.cpp

📁 DSM Plugin.加密文件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// -----------------------------------------------------------------



// -----------------------------------------------------------------
//  Plugin internal Config Dialog Box 
// -----------------------------------------------------------------


// Move the given window to the centre of the screen
// and bring it to the top.
void CentreWindow(HWND hwnd)
{
    RECT winrect, workrect;
    
    // Find how large the desktop work area is
    SystemParametersInfo(SPI_GETWORKAREA, 0, &workrect, 0);
    int workwidth = workrect.right -  workrect.left;
    int workheight = workrect.bottom - workrect.top;
    
    // And how big the window is
    GetWindowRect(hwnd, &winrect);
    int winwidth = winrect.right - winrect.left;
    int winheight = winrect.bottom - winrect.top;
	
    // Make sure it's not bigger than the work area
    winwidth = min(winwidth, workwidth);
    winheight = min(winheight, workheight);
	
    // Now centre it
    SetWindowPos(hwnd, 
        HWND_TOP,
        workrect.left + (workwidth-winwidth) / 2,
        workrect.top + (workheight-winheight) / 2,
        winwidth, winheight, 
        SWP_SHOWWINDOW);
    SetForegroundWindow(hwnd);
}


//
// Display the Plugin Config Dialog box
//
int DoDialog(void)
{
    PrintLog((DEST,"DoDialog."));
    return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG_DIALOG), 
        NULL, (DLGPROC) ConfigDlgProc, (LONG) pPlugin);
}

//Display the plugin Error dialog
int DoError(void)
{
    PrintLog((DEST,"DoError."));
    return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 
        NULL, (DLGPROC) ErrorDlgProc, (LONG) pPlugin);
}


//
// Config Dialog box callback
//
BOOL CALLBACK ConfigDlgProc(HWND hwnd,  UINT uMsg,  WPARAM wParam, LPARAM lParam )
{
    //PLUGINSTRUCT* _this = (PLUGINSTRUCT*) GetWindowLong(hwnd, GWL_USERDATA);

#ifdef _WITH_REGISTRY
    REGISTRY *m_pREGISTRY;
#endif
long iCryptVer=0;
DWORD keyLen = 0;


    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
	char output[OUTPUT_BUFFER_SIZE];
    HANDLE      hKeyFile = 0;
            // Init the various fields with the saved values if they exist.
            CentreWindow(hwnd);
			FindKey(PLUGIN_FILE, sDefaultKeyName, sVariable, &hKeyFile, output);
			CloseHandle(hKeyFile);
            SetDlgItemText(hwnd, IDC_STATUS, output  );

            SetDlgItemText(hwnd, IDC_CLIENT, pPlugin->szHKCUViewer  );
            SetDlgItemText(hwnd, IDC_SERVER_USER, pPlugin->szHKCUServer  );
            SetDlgItemText(hwnd, IDC_KEYLOCATION, pPlugin->szHKCUGenKey  );
            SetDlgItemText(hwnd, IDC_SERVER_SERVICE, pPlugin->szHKLMServer  );


#ifndef _WITH_REGISTRY
			//grey out key filename options for "no registry"
            EnableWindow(GetDlgItem(hwnd, IDC_CLIENT), false);
            EnableWindow(GetDlgItem(hwnd, IDC_SERVER_USER), false);
            EnableWindow(GetDlgItem(hwnd, IDC_KEYLOCATION), true);
            EnableWindow(GetDlgItem(hwnd, IDC_SERVER_SERVICE), false);
#else
            EnableWindow(GetDlgItem(hwnd, IDC_CLIENT), true);
            EnableWindow(GetDlgItem(hwnd, IDC_SERVER_USER), true);
            EnableWindow(GetDlgItem(hwnd, IDC_KEYLOCATION), true);
            EnableWindow(GetDlgItem(hwnd, IDC_SERVER_SERVICE), true);
#endif

			iCryptVer = GetCryptoVersion();
			//Grey out invalid options
			if (iCryptVer == 1) {
				EnableWindow(GetDlgItem(hwnd,IDC_RADIO1),false);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIO2),false);
				EnableWindow(GetDlgItem(hwnd,IDC_RADIO3),false);
			}
			else {
				if (maxKeyLen == KEYLEN_128BIT) {
					CheckDlgButton(hwnd, IDC_RADIO2,BST_CHECKED);
					EnableWindow(GetDlgItem(hwnd,IDC_RADIO2),true);
					EnableWindow(GetDlgItem(hwnd,IDC_RADIO1),true);
					EnableWindow(GetDlgItem(hwnd,IDC_RADIO3),true);
				}
				else {
					if (maxKeyLen == KEYLEN_56BIT) {
						CheckDlgButton(hwnd, IDC_RADIO3,BST_CHECKED);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO2),false);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO1),true);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO3),true);
					}
					else {
						CheckDlgButton(hwnd, IDC_RADIO1,BST_CHECKED);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO1),true);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO2),false);
						EnableWindow(GetDlgItem(hwnd,IDC_RADIO3),false);
					}
				}
			}
            return TRUE;
        }
		
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDOK:
            // Save the parameters in an ini file or registry for instance/
//            GetDlgItemText(hwnd, IDC_CLIENT, pPlugin->szHKCUViewer, KEYFILENAME_SIZE );
//            GetDlgItemText(hwnd, IDC_SERVER_USER, pPlugin->szHKCUServer, KEYFILENAME_SIZE );
//            GetDlgItemText(hwnd, IDC_KEYLOCATION, pPlugin->szHKCUGenKey, KEYFILENAME_SIZE );
//            GetDlgItemText(hwnd, IDC_SERVER_SERVICE, pPlugin->szHKLMServer, KEYFILENAME_SIZE );
			
#ifdef _WITH_REGISTRY
			//HKLM/Server
//            m_pREGISTRY = new REGISTRY(HKEY_LOCAL_MACHINE, MSRC4_KEY_NAME_SERVER, true);
//            m_pREGISTRY->WriteItem(pPlugin->szHKLMServer ,INDEXVAL_KEYFILE);
//            m_pREGISTRY->WriteItem(pPlugin->szHKCUGenKey ,INDEXVAL_KEYGEN);
//            delete m_pREGISTRY;
            
			//HKCU/Server
//            m_pREGISTRY = new REGISTRY(HKEY_CURRENT_USER, MSRC4_KEY_NAME_SERVER, true);
//            m_pREGISTRY->WriteItem(pPlugin->szHKCUServer,INDEXVAL_KEYFILE);
//            m_pREGISTRY->WriteItem(pPlugin->szHKCUGenKey ,INDEXVAL_KEYGEN);
//            delete m_pREGISTRY;
			
			//HKCU/Viewer
//            m_pREGISTRY = new REGISTRY(HKEY_CURRENT_USER, MSRC4_KEY_NAME_VIEWER, true);
//            m_pREGISTRY->WriteItem(pPlugin->szHKCUViewer,INDEXVAL_KEYFILE);
//            m_pREGISTRY->WriteItem(pPlugin->szHKCUGenKey ,INDEXVAL_KEYGEN);
//            delete m_pREGISTRY;
			
#endif
			
            EndDialog(hwnd, TRUE);
            return TRUE;
        case IDC_KEYGEN:

			GetDlgItemText(hwnd, IDC_KEYLOCATION, pPlugin->szHKCUGenKey , KEYFILENAME_SIZE );
			if (IsDlgButtonChecked(hwnd, IDC_RADIO2))
				keyLen = KEYLEN_128BIT;
			else {
				if (IsDlgButtonChecked(hwnd, IDC_RADIO3))
					keyLen = KEYLEN_56BIT;
				else 
					keyLen = KEYLEN_40BIT;
			}
			//Button Generate Key
			//Generates a file in c:\program files\ultravnc\new_rc4.key
			//you will need to copy it to the client AND the server as 
			//c:\program files\ultravnc\rc4.key
			
			//save the path in case they changed it!
#ifdef _WITH_REGISTRY
            m_pREGISTRY = new REGISTRY(HKEY_CURRENT_USER, MSRC4_KEY_FILE, false);
            m_pREGISTRY->WriteItem(pPlugin->szHKCUGenKey, INDEXVAL_KEYGEN);
            delete m_pREGISTRY;
#endif
            if (!GenKey(pPlugin->szHKCUGenKey , keyLen))
			{
				strcpy(pPlugin->szDescription2, "An unrecoverable error occurred.");
				strcpy(pPlugin->szDescription,"GenerateKey Failed");
				DoError();
			}
			keyLen = KEYLEN_128BIT;  //default back to 128bit
            EndDialog(hwnd, TRUE);
            return TRUE;
        case IDCANCEL:
            EndDialog(hwnd, FALSE);
            return TRUE;
        }
        break;
		
		case WM_DESTROY:
			EndDialog(hwnd, FALSE);
			return TRUE;
    }
    return 0;
}


//
// Error Dialog box callback
//
BOOL CALLBACK ErrorDlgProc(HWND hwnd,  UINT uMsg,  WPARAM wParam, LPARAM lParam )
{
//    PLUGINSTRUCT* _this = (PLUGINSTRUCT*) GetWindowLong(hwnd, GWL_USERDATA);
	
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            // Init the various fields with the saved values if they exist.
            CentreWindow(hwnd);
            SetDlgItemText(hwnd, ID_MSG2, pPlugin->szDescription2  );
            SetDlgItemText(hwnd, IDC_MSG, pPlugin->szDescription  );
            return TRUE;
        }
		
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDOK:
            //
            EndDialog(hwnd, FALSE);
            return TRUE;
        case IDCANCEL:
            EndDialog(hwnd, FALSE);
            return TRUE;
        }
        break;
		
		case WM_DESTROY:
			EndDialog(hwnd, FALSE);
			return TRUE;
    }
    return 0;
}



// -----------------------------------------------------------------
// Others internal functions, some depending on what the Plugin does
// -----------------------------------------------------------------

//
BOOL MyStrToken(LPSTR szToken, LPSTR lpString, int nTokenNum, char cSep)
{
    int i = 1;
    while (i < nTokenNum)
    {
        while ( *lpString && (*lpString != cSep) &&(*lpString != '\0'))
        {
            lpString++;
        }
        i++;
        lpString++;
    }
    while ((*lpString != cSep) && (*lpString != '\0'))
    {
        *szToken = *lpString;
        szToken++;
        lpString++;
    }
    *szToken = '\0' ;
    if (( ! *lpString ) || (! *szToken)) return NULL;
    return FALSE;
}


//
// Calculate the len of the data after transformation and return it. 
// 
// MANDATORY: The calculation must be possible by
// ONLY knowing the source data length ! (=> forget compression algos...)
//
// Example:
// For 128bits key encryption, the typical calculation would be;
// Pad the DataBuffer so it is 16 bytes (128 bits) modulo 
//      nPad = (nDataLen % 16 == 0) ? 0 : (16 - (nDataLen % 16));
// Then add a 16 bytes to store the original buffer length (this way it's 
// still 16 bytes modulo) that will be necessary for decryption
//      *pnTransformedDataLen = nDataLen + nPad + 16;

int GiveTransDataLen(int nDataLen)
{
    int nTransDataLen = nDataLen; // STREAM encryption, the datalen remains unchanged

			//if the message had a header, it is SALT, add it in.
	if (bTransHeader)
		nTransDataLen = nDataLen + SALT_SIZE + IV_SIZE;

    return nTransDataLen;
}

//
// Calculate the len of the data after Restauration and return it. 
// 
// MANDATORY: The calculation must be possible by
// ONLY knowing the source data length ! (=> forget compression algos...)
//
int GiveRestDataLen(int nDataLen)
{
    int nRestDataLen = nDataLen; // STREAM encryption, the datalen remains unchanged

			//if the message had a header, it is SALT, add it in.
	if (bSaltD)
		nRestDataLen = nDataLen - (SALT_SIZE + IV_SIZE);

    return nRestDataLen;
}



//
// Allocate more space for the local transformation buffer if necessary
// and returns the pointer to this buffer
//
BYTE* CheckLocalTransBufferSize(int nBufferSize)
{
    if (nLocalTransBufferSize >= nBufferSize) return pLocalTransBuffer;
	
    BYTE *pNewBuffer = (BYTE *) malloc (nBufferSize + 256);
    if (pNewBuffer == NULL) 
    {
        return NULL;
    }
    if (pLocalTransBuffer != NULL)
        free(pLocalTransBuffer);
	
    pLocalTransBuffer = pNewBuffer;
    nLocalTransBufferSize = nBufferSize + 256;
	
    memset(pLocalTransBuffer, 0, nLocalTransBufferSize);
	
    return pLocalTransBuffer;
}


//
// Allocate more space for the local restoration buffer if necessary
// and returns the pointer to this buffer
//
BYTE* CheckLocalRestBufferSize(int nBufferSize)
{
    if (nLocalRestBufferSize >= nBufferSize) return pLocalRestBuffer;
	
    BYTE *pNewBuffer = (BYTE *) malloc (nBufferSize + 256);
    if (pNewBuffer == NULL) 
    {
        return NULL;
    }
    if (pLocalRestBuffer != NULL)
        free(pLocalRestBuffer);
	
    pLocalRestBuffer = pNewBuffer;
    nLocalRestBufferSize = nBufferSize + 256;
	
    memset(pLocalRestBuffer, 0, nLocalRestBufferSize);
	
    return pLocalRestBuffer;
}



//
// DLL Main Entry point  
// 
BOOL WINAPI DllMain( HINSTANCE hInst, 
					DWORD  ul_reason_for_call, 
					LPVOID lpReserved
					)
{
    switch (ul_reason_for_call)
    {
	case DLL_PROCESS_ATTACH:
		hInstance = hInst;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
    }
    return TRUE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -