📄 autoreg.cpp
字号:
continue;
dwSigLength = GetFileSize(hSigFile, NULL);
if ((dwSigLength > sizeof(pbSignature))
|| (dwSigLength < 72)) // Accept a 512-bit signature
{
hReturnStatus = NTE_BAD_SIGNATURE;
goto ErrorExit;
}
fStatus = ReadFile(
hSigFile,
pbSignature,
sizeof(pbSignature),
&dwSigLength,
NULL);
if (!fStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(GetLastError());
goto ErrorExit;
}
fStatus = CloseHandle(hSigFile);
hSigFile = NULL;
if (!fStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(GetLastError());
goto ErrorExit;
}
fSignatureFound = TRUE;
break;
//
// Other cases may be added in the future.
//
default:
hReturnStatus = NTE_BAD_SIGNATURE;
goto ErrorExit;
}
if (fSignatureFound)
{
for (dwIndex = 0; dwIndex < dwSigLength; dwIndex += 1)
{
if (0 != pbSignature[dwIndex])
break;
}
if (dwIndex >= dwSigLength)
fSignatureFound = FALSE;
}
}
//
// We've found a signature somewhere! Install it.
//
nStatus = RegSetValueEx(
hMyCsp,
TEXT("Signature"),
0,
REG_BINARY,
pbSignature,
dwSigLength);
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
}
nStatus = RegCloseKey(hMyCsp);
hMyCsp = NULL;
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
#ifdef SCARD_CSP
//
// Introduce the vendor card. Try various techniques until one works.
//
for (dwIndex = 0; !fCardIntroduced; dwIndex += 1)
{
switch (dwIndex)
{
case 0:
{
HMODULE hWinSCard = NULL;
LPSETCARDTYPEPROVIDERNAME pfSetCardTypeProviderName = NULL;
hWinSCard = GetModuleHandle(TEXT("WinSCard.DLL"));
if (NULL == hWinSCard)
continue;
#if defined(UNICODE)
pfSetCardTypeProviderName =
(LPSETCARDTYPEPROVIDERNAME)GetProcAddress(
hWinSCard,
TEXT("SCardSetCardTypeProviderNameW"));
#else
pfSetCardTypeProviderName =
(LPSETCARDTYPEPROVIDERNAME)GetProcAddress(
hWinSCard,
TEXT("SCardSetCardTypeProviderNameA"));
#endif
if (NULL == pfSetCardTypeProviderName)
continue;
dwStatus = SCardIntroduceCardType(
NULL,
l_szCardName,
NULL,
NULL,
0,
l_rgbATR,
l_rgbATRMask,
sizeof(l_rgbATR));
if ((ERROR_SUCCESS != dwStatus)
&& (ERROR_ALREADY_EXISTS != dwStatus))
continue;
dwStatus = (*pfSetCardTypeProviderName)(
NULL,
l_szCardName,
SCARD_PROVIDER_CSP,
l_szProviderName);
if (ERROR_SUCCESS != dwStatus)
{
if (0 == (dwStatus & 0xffff0000))
hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
else
hReturnStatus = (HRESULT)dwStatus;
goto ErrorExit;
}
fCardIntroduced = TRUE;
break;
}
case 1:
dwStatus = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0, &hCtx);
if (ERROR_SUCCESS != dwStatus)
continue;
dwStatus = SCardIntroduceCardType(
hCtx,
l_szCardName,
NULL,
NULL,
0,
l_rgbATR,
l_rgbATRMask,
sizeof(l_rgbATR));
if ((ERROR_SUCCESS != dwStatus)
&& (ERROR_ALREADY_EXISTS != dwStatus))
{
if (0 == (dwStatus & 0xffff0000))
hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
else
hReturnStatus = (HRESULT)dwStatus;
goto ErrorExit;
}
dwStatus = SCardReleaseContext(hCtx);
hCtx = NULL;
if (ERROR_SUCCESS != dwStatus)
{
if (0 == (dwStatus & 0xffff0000))
hReturnStatus = HRESULT_FROM_WIN32(dwStatus);
else
hReturnStatus = (HRESULT)dwStatus;
goto ErrorExit;
}
nStatus = RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards"),
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hCalais,
&dwDisp);
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegCreateKeyEx(
hCalais,
l_szCardName,
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hVendor,
&dwDisp);
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegCloseKey(hCalais);
hCalais = NULL;
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegSetValueEx(
hVendor,
TEXT("Crypto Provider"),
0,
REG_SZ,
(LPBYTE)l_szProviderName,
(_tcslen(l_szProviderName) + 1) * sizeof(TCHAR));
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegCloseKey(hVendor);
hVendor = NULL;
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
fCardIntroduced = TRUE;
break;
case 2:
nStatus = RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards"),
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hCalais,
&dwDisp);
if (ERROR_SUCCESS != nStatus)
continue;
nStatus = RegCreateKeyEx(
hCalais,
l_szCardName,
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hVendor,
&dwDisp);
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegCloseKey(hCalais);
hCalais = NULL;
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegSetValueEx(
hVendor,
TEXT("Primary Provider"),
0,
REG_BINARY,
(LPCBYTE)&l_guidPrimaryProv,
sizeof(l_guidPrimaryProv));
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegSetValueEx(
hVendor,
TEXT("ATR"),
0,
REG_BINARY,
l_rgbATR,
sizeof(l_rgbATR));
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegSetValueEx(
hVendor,
TEXT("ATRMask"),
0,
REG_BINARY,
l_rgbATRMask,
sizeof(l_rgbATRMask));
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegSetValueEx(
hVendor,
TEXT("Crypto Provider"),
0,
REG_SZ,
(LPBYTE)l_szProviderName,
(_tcslen(l_szProviderName) + 1) * sizeof(TCHAR));
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
nStatus = RegCloseKey(hVendor);
hVendor = NULL;
if (ERROR_SUCCESS != nStatus)
{
hReturnStatus = HRESULT_FROM_WIN32(nStatus);
goto ErrorExit;
}
fCardIntroduced = TRUE;
break;
default:
hReturnStatus = ERROR_ACCESS_DENIED;
goto ErrorExit;
}
}
#endif
//
// ?vendor?
// Add any additional initialization required here.
//
//
// All done!
//
return hReturnStatus;
//
// An error was detected. Clean up any outstanding resources and
// return the error.
//
ErrorExit:
#ifdef SCARD_CSP
if (NULL != hCtx)
SCardReleaseContext(hCtx);
if (NULL != hCalais)
RegCloseKey(hCalais);
#endif
if (NULL != hVendor)
RegCloseKey(hVendor);
if (INVALID_HANDLE_VALUE != hSigFile)
CloseHandle(hSigFile);
if (NULL != hMyCsp)
RegCloseKey(hMyCsp);
if (NULL != hProviders)
RegCloseKey(hProviders);
DllUnregisterServer();
return hReturnStatus;
}
/*++
GetInstanceHandle:
This routine is CSP dependant. It returns the DLL instance handle. This
is typically provided by the DllMain routine and stored in a global
location.
Arguments:
None
Return Value:
The DLL Instance handle provided to the DLL when DllMain was called.
Author:
Doug Barlow (dbarlow) 3/11/1998
--*/
extern "C" HINSTANCE g_hModule;
static HINSTANCE
GetInstanceHandle(
void)
{
#ifdef _AFXDLL
return AfxGetInstanceHandle();
#else
// ?vendor?
// Make sure this returns your DLL instance handle.
return g_hModule;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -