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

📄 cspinstl.cpp

📁 微软出的CSPDK
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//  FILE          : cspinstl.cpp                                           //
//  DESCRIPTION   : To install CSP DLL with Crypto API                     //
//  USAGE         : Must have the provider csp.dll and file csp.sig        //
//                  which is the signature in directory pointed to by      //
//                  _FLATRELEASEDIR.                                       //
//  AUTHOR        :                                                        //
//  HISTORY       :                                                        //                            //
//      Nov 18 1998 davidteo Ported to Windows CE                          //
//                                                                         //
//  Copyright (C) 1993 Microsoft Corporation   All Rights Reserved         //
/////////////////////////////////////////////////////////////////////////////
#define APPNAME L"CSPINSTL"
#include "..\inc\csp.h"

// HKEY_LOCAL_MACHINE registry path for our Provider
TCHAR szprovider[] = L"Comm\\Security\\Crypto\\Defaults\\Provider\\" CSP_PROV;

// HKEY_LOCAL_MACHINE registry path for our DLL on the platform
TCHAR szImagePath[] = L"\\Windows\\" CSP_FILE;

// HEKY_LOCAL_MACHINE registry path for making our provider the default for its
// type.
TCHAR sztype[] = L"Comm\\Security\\Crypto\\Defaults\\Provider Types\\Type %03d";

//******************************************************************************

extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                              LPTSTR lpCmdLine, int nCmdShow)
{
	DWORD     	    dwIgn;
	HKEY      	    hKey;
	DWORD           err        = ERROR_SUCCESS;
	DWORD           dwValue    = CSP_PROV_TYPE;
	PVOID          	lpvAddress = NULL;    
	WORD           	NumBytes   = 0;

	int				iSigFile   = -1;
	BOOL   			fSuccess   = FALSE;

    // If the image file does not exist in its destination directory, then 
    // copy it across the CESH link and quit if there is an error.
    // Otherwise, carry on.
   
    if ((GetFileAttributes (szImagePath) == 0xffffffff) &&
   	 	 !CopyCESH (CSP_FILE, szImagePath))
    {
        return (FALSE);
    }
   
 	//
    // Just to open csp.sig signature file.  This file was created by
    // sign.exe.
    //

    __try
    {   
        // Open the source file for read across CESH link.
        if ((iSigFile = U_ropen(CSP_SIG_FILE, _O_RDONLY | _O_SEQUENTIAL)) == -1)
        {
            TRACE(TEXT("Error %u trying to open \"%s\"."), GetLastError(), CSP_SIG_FILE);
            __leave;
        }

        // Get the size of the file
        NumBytes = U_rlseek(iSigFile, 0, SEEK_END);
        U_rlseek(iSigFile, 0, SEEK_SET);

        // Make sure we have a valid file size.
        if (NumBytes == 0xFFFFFFFF)
        {
    	    TRACE(TEXT("Error %u trying to get size of \"%s\"."), GetLastError(), CSP_SIG_FILE);
            __leave;
        }
      
        if ((lpvAddress = VirtualAlloc(NULL, NumBytes, MEM_RESERVE |
	                                    MEM_COMMIT,
                                   		PAGE_READWRITE)) == NULL)
        {
            TRACE(L"Install failed: Alloc to read uisign: %x\n",
                    GetLastError());
            __leave;
        }

        if (U_rread(iSigFile, (unsigned char *) lpvAddress, NumBytes) != (int)NumBytes)
        {
            TRACE (L"Install failed: Reading uisign: %x\n",
                    GetLastError());
            VirtualFree(lpvAddress, 0, MEM_RELEASE);
            __leave;
        }

        fSuccess = TRUE;
        
     }
     __finally
     {

        // Close any remote source file we may have opened.
        if (iSigFile != -1)
        {
            U_rclose(iSigFile);
        }
     }

	if (!fSuccess)
		return (FALSE);
		
	//
	// Create or open in local machine for provider:
	//
    if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                                szprovider,
                                0L, L"", REG_OPTION_NON_VOLATILE,
                                KEY_ALL_ACCESS, NULL, &hKey,
                                &dwIgn)) != ERROR_SUCCESS)
    {
        TRACE (L"Install failed: RegCreateKeyEx\n");
    }

	//
	// Set Image path to: csp.dll
	//
    if ((err = RegSetValueEx(hKey, L"Image Path", 0L, REG_SZ, (const BYTE *)szImagePath,
	                            (wcslen(szImagePath)+1)*sizeof (TCHAR))) != ERROR_SUCCESS)
    {
        TRACE(L"Install failed: Setting Image Path value\n");
        return(FALSE);
    }

	//
	// Set Type to: Type 900
	//
    if ((err = RegSetValueEx(hKey, L"Type", 0L, REG_DWORD,
                                (const BYTE *) &dwValue,
                                sizeof(DWORD))) != ERROR_SUCCESS)
    {
        TRACE(L"Install failed: Setting Type value: %x\n", err);
        return(FALSE);
    }

	//
	// Place signature
	//

    if ((err = RegSetValueEx(hKey, L"Signature", 0L, REG_BINARY, 
                                (const BYTE *) lpvAddress,
                                NumBytes)) != ERROR_SUCCESS)
    {
        TRACE(L"Install failed: Setting Signature value for cspsign: %x\n", err);
        return(FALSE);
    }

    RegCloseKey(hKey);
    VirtualFree(lpvAddress, 0, MEM_RELEASE);
      

	//
	// Create or open in local machine for provider type:
	// Type 900
	//
	wsprintf (sztype, sztype, CSP_PROV_TYPE);
    if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                                sztype,
                                0L, L"", REG_OPTION_NON_VOLATILE,
                                KEY_ALL_ACCESS, NULL, &hKey,
                                &dwIgn)) != ERROR_SUCCESS)
    {
        TRACE(L"Install failed: Registry entry existed: %x\n", err);
    }

    if ((err = RegSetValueEx(hKey, L"Name", 0L, REG_SZ, (const BYTE *)CSP_PROV,
                                (wcslen(CSP_PROV)+1)*sizeof(TCHAR))) != ERROR_SUCCESS)
    {
        TRACE(L"Install failed: Setting Default type: %x\n", err);
        return(FALSE);
    }

	TRACE (L"Installed: %s\n", szImagePath);
	  
    return (TRUE);
}

⌨️ 快捷键说明

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