The amount of strong name support that CoreCLR needs is very small (really just a method to convert public key to public key token). It is not worth it to build a separate .lib for just this single method. Fold the strong name APIs into metadata and change the API to return HRESULT.
include_directories("inc")
-include_directories("strongname/inc")
include_directories("inc/winrt")
include_directories("debug/inc")
include_directories("debug/inc/${ARCH_SOURCES_DIR}")
add_subdirectory(md)
add_subdirectory(debug)
add_subdirectory(inc)
-add_subdirectory(strongname)
add_subdirectory(binder)
add_subdirectory(classlibnative)
add_subdirectory(dlls)
#include "variables.hpp"
#include "stringarraylist.h"
-#include "strongname.h"
-
#define APP_DOMAIN_LOCKED_UNLOCKED 0x02
#define APP_DOMAIN_LOCKED_CONTEXT 0x04
#include <windows.h>
#include <winerror.h>
-#include "strongname.h"
+#include "strongnameinternal.h"
#include "fusionhelpers.hpp"
#include "fusionassemblyname.hpp"
#define REMAINING_BUFFER_SIZE ((*pccDisplayName) - (pszBuf - szDisplayName))
// ---------------------------------------------------------------------------
-// Private Helpers
-// ---------------------------------------------------------------------------
-namespace
-{
- HRESULT GetPublicKeyTokenFromPKBlob(LPBYTE pbPublicKeyToken, DWORD cbPublicKeyToken,
- LPBYTE *ppbSN, LPDWORD pcbSN)
- {
- HRESULT hr = S_OK;
-
- // Generate the hash of the public key.
- if (!StrongNameTokenFromPublicKey(pbPublicKeyToken, cbPublicKeyToken, ppbSN, pcbSN))
- {
- hr = StrongNameErrorInfo();
- }
-
- return hr;
- }
-};
-
-// ---------------------------------------------------------------------------
// CPropertyArray ctor
// ---------------------------------------------------------------------------
CPropertyArray::CPropertyArray()
if (pvProperty && cbProperty)
{
// Generate the public key token from the pk.
- if (FAILED(hr = GetPublicKeyTokenFromPKBlob((LPBYTE) pvProperty, cbProperty, &pbSN, &cbSN)))
+ if (FAILED(hr = StrongNameTokenFromPublicKey((LPBYTE) pvProperty, cbProperty, &pbSN, &cbSN)))
goto exit;
// Set the public key token property.
#include "utils.hpp"
-#include "strongname.h"
+#include "strongnameinternal.h"
#include "corpriv.h"
namespace BINDER_SPACE
BYTE *pByteToken = NULL;
DWORD dwTokenLen = 0;
- if (!StrongNameTokenFromPublicKey(const_cast<BYTE *>(pByteKey),
- dwKeyLen,
- &pByteToken,
- &dwTokenLen))
- {
- IF_FAIL_GO(StrongNameErrorInfo());
- }
- else
- {
- _ASSERTE(pByteToken != NULL);
- publicKeyTokenBLOB.Set(pByteToken, dwTokenLen);
- StrongNameFreeBuffer(pByteToken);
- }
+ IF_FAIL_GO(StrongNameTokenFromPublicKey(
+ const_cast<BYTE*>(pByteKey),
+ dwKeyLen,
+ &pByteToken,
+ &dwTokenLen));
+
+ _ASSERTE(pByteToken != NULL);
+ publicKeyTokenBLOB.Set(pByteToken, dwTokenLen);
+ StrongNameFreeBuffer(pByteToken);
Exit:
return hr;
mdhotdata_dac
mdruntime_dac
mdruntimerw_dac
- strongname_dac
utilcode_dac
unwinder_dac
${END_LIBRARY_GROUP} # End group of libraries that have circular references
corguids
gcinfo # Condition="'$(TargetCpu)'=='amd64' or '$(TargetCpu)' == 'arm' or '$(TargetCpu)' == 'arm64'"
ildbsymlib
- strongname_wks
utilcode
v3binder
)
return result;
}
-#ifndef __GNUC__
-__declspec(thread) Thread * pCurrentThread;
-#else // !__GNUC__
thread_local Thread * pCurrentThread;
-#endif // !__GNUC__
Thread * GetThread()
{
mdcompiler_wks
mdruntime_wks
mdruntimerw_wks
- strongname_tool
mdstaticapi
${END_LIBRARY_GROUP} # End group of libraries that have circular references
ceefgen
#include "ilasmpch.h"
#include "assembler.h"
-#include "strongname.h"
+#include "strongnameinternal.h"
#include <limits.h>
#include <fusion.h>
#ifndef ASMMAN_HPP
#define ASMMAN_HPP
-#include "strongname.h"
#include "specstrings.h"
struct AsmManFile
#include "assembler.h"
-//#include "ceefilegenwriter.h"
-#include "strongname.h"
-
int ist=0;
#define REPT_STEP //printf("Step %d\n",++ist);
mdcompiler_wks
mdruntime_wks
mdruntimerw_wks
- strongname_tool
mdstaticapi
${END_LIBRARY_GROUP} # End group of libraries that have circular references
corguids
CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_MaxStubUnwindInfoSegmentSize, W("MaxStubUnwindInfoSegmentSize"), "")
CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_MaxThreadRecord, W("MaxThreadRecord"), "")
CONFIG_DWORD_INFO(INTERNAL_MessageDebugOut, W("MessageDebugOut"), 0, "")
-CONFIG_DWORD_INFO_EX(INTERNAL_MscorsnLogging, W("MscorsnLogging"), 0, "Enables strong name logging", CLRConfig::REGUTIL_default)
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_NativeImageRequire, W("NativeImageRequire"), 0, "", CLRConfig::REGUTIL_default)
CONFIG_DWORD_INFO_EX(INTERNAL_NestedEhOom, W("NestedEhOom"), 0, "", CLRConfig::REGUTIL_default)
#define INTERNAL_NoGuiOnAssert_Default 1
// them.
enum PredefinedTlsSlots
{
- TlsIdx_StrongName,
+ TlsIdx_OwnedCrstsChain, // slot to store the Crsts owned by this thread
TlsIdx_JitPerf,
TlsIdx_JitX86Perf,
TlsIdx_JitLogEnv,
// Add more indices here.
TlsIdx_ThreadType, // bit flags to indicate special thread's type
- TlsIdx_OwnedCrstsChain, // slot to store the Crsts owned by this thread
TlsIdx_CantAllocCount, //Can't allocate memory on heap in this thread
// A transient thread value that indicates this thread is currently walking its stack
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-// The VM statically links StrongName APIs so we can suppress the warning.
-
-#define USE_DEPRECATED_CLR_API_WITHOUT_WARNING
-#include "../strongname/inc/strongname.h"
-#undef USE_DEPRECATED_CLR_API_WITHOUT_WARNING
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#ifndef __STRONGNAME_HOLDERS_H__
+#define __STRONGNAME_HOLDERS_H__
+
+#include <holder.h>
+#include <strongnameinternal.h>
+
+//
+// Holder classes for types returned from and used in strong name APIs
+//
+
+// Holder for any memory allocated by the strong name APIs
+template<class T>
+void VoidStrongNameFreeBuffer(__in T *pBuffer)
+{
+ StrongNameFreeBuffer(reinterpret_cast<BYTE *>(pBuffer));
+}
+NEW_WRAPPER_TEMPLATE1(StrongNameBufferHolder, VoidStrongNameFreeBuffer<_TYPE>);
+
+#endif // !__STRONGNAME_HOLDERS_H__
#ifndef _STRONGNAME_INTERNAL_H
#define _STRONGNAME_INTERNAL_H
-#include <strongname.h>
+// Public key blob binary format.
+typedef struct {
+ unsigned int SigAlgID; // (ALG_ID) signature algorithm used to create the signature
+ unsigned int HashAlgID; // (ALG_ID) hash algorithm used to create the signature
+ ULONG cbPublicKey; // length of the key in bytes
+ BYTE PublicKey[1]; // variable length byte array containing the key value in format output by CryptoAPI
+} PublicKeyBlob;
// Determine the number of bytes in a public key
DWORD StrongNameSizeOfPublicKey(const PublicKeyBlob &keyPublicKey);
bool StrongNameIsEcmaKey(__in_ecount(cbKey) const BYTE *pbKey, DWORD cbKey);
bool StrongNameIsEcmaKey(const PublicKeyBlob &keyPublicKey);
+HRESULT StrongNameTokenFromPublicKey(BYTE* pbPublicKeyBlob, // [in] public key blob
+ ULONG cbPublicKeyBlob,
+ BYTE** ppbStrongNameToken, // [out] strong name token
+ ULONG* pcbStrongNameToken);
+
+VOID StrongNameFreeBuffer(BYTE* pbMemory);
+
#endif // !_STRONGNAME_INTERNAL_H
// If you are using it more broadly in retail code, you would need to understand the
// performance implications of accessing TLS.
-#ifndef __GNUC__
-__declspec(thread) void* gJitTls = nullptr;
-#else // !__GNUC__
thread_local void* gJitTls = nullptr;
-#endif // !__GNUC__
static void* GetJitTls()
{
../../inc/mdcommon.h
../../inc/metadata.h
../../inc/posterror.h
- ../../inc/strongname.h
../../inc/sstring.h
../../inc/switches.h
../inc/cahlprinternal.h
#include "mdlog.h"
#include "importhelper.h"
-#include <strongname.h>
-
#ifdef _MSC_VER
#pragma warning(disable: 4102)
#endif
#include "mdlog.h"
#include "importhelper.h"
-#include <strongname.h>
-
#ifdef _MSC_VER
#pragma warning(disable: 4102)
#endif
#include "mdutil.h"
#include "rwutil.h"
#include "mdlog.h"
-#include "strongname.h"
+#include "strongnameinternal.h"
#include "sstring.h"
#define COM_RUNTIME_LIBRARY "ComRuntimeLibrary"
return E_FAIL;
#else //!FEATURE_METADATA_EMIT_IN_DEBUGGER || DACCESS_COMPILE
// Need to compress target public key to see if it matches.
- if (!StrongNameTokenFromPublicKey((BYTE*)pbTmp,
- cbTmp,
- (BYTE**)&pbTmpToken,
- &cbTmpToken))
- {
- return StrongNameErrorInfo();
- }
+ IfFailRet(StrongNameTokenFromPublicKey((BYTE*)pbTmp,
+ cbTmp,
+ (BYTE**)&pbTmpToken,
+ &cbTmpToken));
fMatch = cbTmpToken == cbPublicKeyOrToken && !memcmp(pbTmpToken, pbPublicKeyOrToken, cbTmpToken);
StrongNameFreeBuffer((BYTE*)pbTmpToken);
if (!fMatch)
#if defined(FEATURE_METADATA_EMIT_IN_DEBUGGER) && !defined(DACCESS_COMPILE)
return E_FAIL;
#else //!FEATURE_METADATA_EMIT_IN_DEBUGGER || DACCESS_COMPILE
- if (!StrongNameTokenFromPublicKey((BYTE*)pbPublicKeyOrToken,
- cbPublicKeyOrToken,
- (BYTE**)&pbToken,
- &cbToken))
- {
- return StrongNameErrorInfo();
- }
+ IfFailRet(StrongNameTokenFromPublicKey((BYTE*)pbPublicKeyOrToken,
+ cbPublicKeyOrToken,
+ (BYTE**)&pbToken,
+ &cbToken));
#endif //!FEATURE_METADATA_EMIT_IN_DEBUGGER || DACCESS_COMPILE
}
if (cbTmp != cbToken || memcmp(pbTmp, pbToken, cbToken))
{
_ASSERTE(IsAfPublicKey(dwFlags));
dwFlags &= ~afPublicKey;
- if (!StrongNameTokenFromPublicKey((BYTE*)pbPublicKey,
- cbPublicKey,
- (BYTE**)&pbToken,
- &cbToken))
- IfFailGo(StrongNameErrorInfo());
+ IfFailGo(StrongNameTokenFromPublicKey((BYTE*)pbPublicKey,
+ cbPublicKey,
+ (BYTE**)&pbToken,
+ &cbToken));
}
else
_ASSERTE(!IsAfPublicKey(dwFlags));
return S_FALSE;
// Otherwise we need to compress the def public key into a token.
- if (!StrongNameTokenFromPublicKey((BYTE*)pbPublicKey2,
- cbPublicKey2,
- (BYTE**)&pbToken,
- &cbToken))
- return StrongNameErrorInfo();
+ IfFailRet(StrongNameTokenFromPublicKey((BYTE*)pbPublicKey2,
+ cbPublicKey2,
+ (BYTE**)&pbToken,
+ &cbToken));
fMatch = cbPublicKeyOrToken1 == cbToken &&
!memcmp(pbPublicKeyOrToken1, pbToken, cbPublicKeyOrToken1);
recordpool.cpp
mdinternaldisp.cpp
mdinternalro.cpp
+ strongnameinternal.cpp
)
set(MDRUNTIME_HEADERS
metamodelcolumndefs.h
mdinternaldisp.h
mdinternalro.h
- metamodel.cpp
- metamodelro.cpp
- recordpool.cpp
)
convert_to_absolute_path(MDRUNTIME_HEADERS ${MDRUNTIME_HEADERS})
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-
-// ===========================================================================
-// File: StrongName.cpp
//
-// Wrappers for signing and hashing functions needed to implement strong names
-// ===========================================================================
-
-#include "common.h"
-#include <imagehlp.h>
-
-#include <winwrap.h>
-#include <windows.h>
-#include <wincrypt.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <malloc.h>
-#include <cor.h>
-#include <corimage.h>
-#include <metadata.h>
-#include <daccess.h>
-#include <limits.h>
-#include <ecmakey.h>
-#include <sha1.h>
-
-#include "strongname.h"
-#include "ex.h"
-#include "pedecoder.h"
-#include "strongnameholders.h"
+// Strong name APIs which are not exposed publicly but are used by CLR code
+//
+
+#include "stdafx.h"
#include "strongnameinternal.h"
-#include "common.h"
-#include "classnames.h"
+#include "thekey.h"
+#include "ecmakey.h"
+#include "sha1.h"
-// Debug logging.
-#if !defined(_DEBUG) || defined(DACCESS_COMPILE)
-#define SNLOG(args)
-#endif // !_DEBUG || DACCESS_COMPILE
+//---------------------------------------------------------------------------------------
+//
+// Check to see if a public key blob is the ECMA public key blob
+//
+// Arguments:
+// pbKey - public key blob to check
+// cbKey - size in bytes of pbKey
+//
-#ifndef DACCESS_COMPILE
+bool StrongNameIsEcmaKey(__in_ecount(cbKey) const BYTE *pbKey, DWORD cbKey)
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_NOTRIGGER;
+ }
+ CONTRACTL_END;
-// Debug logging.
-#if defined(_DEBUG)
-#include <stdarg.h>
+ // The key should be the same size as the ECMA key
+ if (cbKey != sizeof(g_rbNeutralPublicKey))
+ {
+ return false;
+ }
-BOOLEAN g_fLoggingInitialized = FALSE;
-DWORD g_dwLoggingFlags = FALSE;
+ const PublicKeyBlob *pKeyBlob = reinterpret_cast<const PublicKeyBlob *>(pbKey);
+ return StrongNameIsEcmaKey(*pKeyBlob);
+}
-#define SNLOG(args) Log args
+//---------------------------------------------------------------------------------------
+//
+// Check to see if a public key blob is the ECMA public key blob
+//
+// Arguments:
+// keyPublicKey - Key to check to see if it matches the ECMA key
+//
-void Log(__in_z const WCHAR *wszFormat, ...)
+bool StrongNameIsEcmaKey(const PublicKeyBlob &keyPublicKey)
{
- if (g_fLoggingInitialized && !g_dwLoggingFlags)
- return;
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_NOTRIGGER;
+ }
+ CONTRACTL_END;
+
+ return StrongNameSizeOfPublicKey(keyPublicKey) == sizeof(g_rbNeutralPublicKey) &&
+ memcmp(reinterpret_cast<const BYTE *>(&keyPublicKey), g_rbNeutralPublicKey, sizeof(g_rbNeutralPublicKey)) == 0;
+}
- DWORD dwError = GetLastError();
+//---------------------------------------------------------------------------------------
+//
+// Verify that a public key blob looks like a reasonable public key
+//
+// Arguments:
+// pbBuffer - buffer to verify the format of
+// cbBuffer - size of pbBuffer
+//
+
+bool StrongNameIsValidPublicKey(__in_ecount(cbBuffer) const BYTE *pbBuffer, DWORD cbBuffer)
+{
+ CONTRACTL
+ {
+ PRECONDITION(CheckPointer(pbBuffer));
+ NOTHROW;
+ GC_NOTRIGGER;
+ }
+ CONTRACTL_END;
+
+ // The buffer must be at least as large as the public key structure
+ if (cbBuffer < sizeof(PublicKeyBlob))
+ {
+ return false;
+ }
+
+ // The buffer must be the same size as the structure header plus the trailing key data
+ const PublicKeyBlob *pkeyPublicKey = reinterpret_cast<const PublicKeyBlob *>(pbBuffer);
+ if (GET_UNALIGNED_VAL32(&pkeyPublicKey->cbPublicKey) != cbBuffer - offsetof(PublicKeyBlob, PublicKey))
+ {
+ return false;
+ }
+
+ // The buffer itself looks reasonable, but the public key structure needs to be validated as well
+ return StrongNameIsValidPublicKey(*pkeyPublicKey);
+}
+
+//---------------------------------------------------------------------------------------
+//
+// Verify that a public key blob looks like a reasonable public key.
+//
+// Arguments:
+// keyPublicKey - key blob to verify
+//
+// Notes:
+// This can be a very expensive operation, since it involves importing keys.
+//
+
+bool StrongNameIsValidPublicKey(const PublicKeyBlob &keyPublicKey)
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_NOTRIGGER;
+ }
+ CONTRACTL_END;
+
+ // The ECMA key doesn't look like a valid key so it will fail the below checks. If we were passed that
+ // key, then we can skip them
+ if (StrongNameIsEcmaKey(keyPublicKey))
+ {
+ return true;
+ }
- if (!g_fLoggingInitialized) {
- g_dwLoggingFlags = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MscorsnLogging);
- g_fLoggingInitialized = TRUE;
+ // If a hash algorithm is specified, it must be a sensible value
+ bool fHashAlgorithmValid = GET_ALG_CLASS(GET_UNALIGNED_VAL32(&keyPublicKey.HashAlgID)) == ALG_CLASS_HASH &&
+ GET_ALG_SID(GET_UNALIGNED_VAL32(&keyPublicKey.HashAlgID)) >= ALG_SID_SHA1;
+ if (keyPublicKey.HashAlgID != 0 && !fHashAlgorithmValid)
+ {
+ return false;
}
- if (!g_dwLoggingFlags) {
- SetLastError(dwError);
- return;
+ // If a signature algorithm is specified, it must be a sensible value
+ bool fSignatureAlgorithmValid = GET_ALG_CLASS(GET_UNALIGNED_VAL32(&keyPublicKey.SigAlgID)) == ALG_CLASS_SIGNATURE;
+ if (keyPublicKey.SigAlgID != 0 && !fSignatureAlgorithmValid)
+ {
+ return false;
}
- va_list pArgs;
- WCHAR wszBuffer[1024];
- static WCHAR wszPrefix[] = W("SN: ");
+ // The key blob must indicate that it is a PUBLICKEYBLOB
+ if (keyPublicKey.PublicKey[0] != PUBLICKEYBLOB)
+ {
+ return false;
+ }
- wcscpy_s(wszBuffer, COUNTOF(wszBuffer), wszPrefix);
+ return true;
+}
- va_start(pArgs, wszFormat);
- _vsnwprintf_s(&wszBuffer[COUNTOF(wszPrefix) - 1],
- COUNTOF(wszBuffer) - COUNTOF(wszPrefix),
- _TRUNCATE,
- wszFormat,
- pArgs);
- wszBuffer[COUNTOF(wszBuffer) - 1] = W('\0');
- va_end(pArgs);
+//---------------------------------------------------------------------------------------
+//
+// Determine the number of bytes that a public key blob occupies, including the key portion
+//
+// Arguments:
+// keyPublicKey - key blob to calculate the size of
+//
- if (g_dwLoggingFlags & 1)
- wprintf(W("%s"), wszBuffer);
- if (g_dwLoggingFlags & 2)
- WszOutputDebugString(wszBuffer);
- if (g_dwLoggingFlags & 4)
+DWORD StrongNameSizeOfPublicKey(const PublicKeyBlob &keyPublicKey)
+{
+ CONTRACTL
{
- MAKE_UTF8PTR_FROMWIDE_NOTHROW(szMessage, wszBuffer);
- if(szMessage != NULL)
- LOG((LF_SECURITY, LL_INFO100, szMessage));
+ NOTHROW;
+ GC_NOTRIGGER;
}
+ CONTRACTL_END;
- SetLastError(dwError);
+ return offsetof(PublicKeyBlob, PublicKey) + // Size of the blob header plus
+ GET_UNALIGNED_VAL32(&keyPublicKey.cbPublicKey); // the number of bytes in the key
}
-#endif // _DEBUG
+
+
// Size in bytes of strong name token.
#define SN_SIZEOF_TOKEN 8
-// We cache a couple of things on a per thread basis: the last error encountered
-// and (potentially) CSP contexts. The following structure tracks these and is
-// allocated lazily as needed.
-struct SN_THREAD_CTX {
- DWORD m_dwLastError;
-};
-
-#endif // !DACCESS_COMPILE
-
-// Macro containing common code used at the start of most APIs.
-#define SN_COMMON_PROLOG() do { \
- SetStrongNameErrorInfo(S_OK); \
-} while (0)
-
-// Macro to return an error from a SN entrypoint API
-#define SN_ERROR(__hr) do { \
- if (FAILED(__hr)) { \
- SetStrongNameErrorInfo(__hr); \
- retVal = FALSE; \
- goto Exit; \
- } \
-} while (false)
-
// Determine the size of a PublicKeyBlob structure given the size of the key
// portion.
#define SN_SIZEOF_KEY(_pKeyBlob) (offsetof(PublicKeyBlob, PublicKey) + GET_UNALIGNED_VAL32(&(_pKeyBlob)->cbPublicKey))
// Free buffer allocated by routines below.
-SNAPI_(VOID) StrongNameFreeBuffer(BYTE *pbMemory) // [in] address of memory to free
+VOID StrongNameFreeBuffer(BYTE *pbMemory) // [in] address of memory to free
{
- BEGIN_ENTRYPOINT_VOIDRET;
-
- SNLOG((W("StrongNameFreeBuffer(%08X)\n"), pbMemory));
-
if (pbMemory != (BYTE*)SN_THE_KEY() && pbMemory != g_rbNeutralPublicKey)
delete [] pbMemory;
- END_ENTRYPOINT_VOIDRET;
-
-}
-
-#ifndef DACCESS_COMPILE
-// Retrieve per-thread context, lazily allocating it if necessary.
-SN_THREAD_CTX *GetThreadContext()
-{
- SN_THREAD_CTX *pThreadCtx = (SN_THREAD_CTX*)ClrFlsGetValue(TlsIdx_StrongName);
- if (pThreadCtx == NULL) {
- pThreadCtx = new (nothrow) SN_THREAD_CTX;
- if (pThreadCtx == NULL)
- return NULL;
- pThreadCtx->m_dwLastError = S_OK;
-
- EX_TRY {
- ClrFlsSetValue(TlsIdx_StrongName, pThreadCtx);
- }
- EX_CATCH {
- delete pThreadCtx;
- pThreadCtx = NULL;
- }
- EX_END_CATCH (SwallowAllExceptions);
- }
- return pThreadCtx;
-}
-
-// Set the per-thread last error code.
-VOID SetStrongNameErrorInfo(DWORD dwStatus)
-{
- SN_THREAD_CTX *pThreadCtx = GetThreadContext();
- if (pThreadCtx == NULL)
- // We'll return E_OUTOFMEMORY when we attempt to get the error.
- return;
- pThreadCtx->m_dwLastError = dwStatus;
-}
-
-#endif // !DACCESS_COMPILE
-
-// Return last error.
-SNAPI_(DWORD) StrongNameErrorInfo(VOID)
-{
- HRESULT hr = E_FAIL;
-
- BEGIN_ENTRYPOINT_NOTHROW;
-
-#ifndef DACCESS_COMPILE
- SN_THREAD_CTX *pThreadCtx = GetThreadContext();
- if (pThreadCtx == NULL)
- hr = E_OUTOFMEMORY;
- else
- hr = pThreadCtx->m_dwLastError;
-#else
- hr = E_FAIL;
-#endif // #ifndef DACCESS_COMPILE
- END_ENTRYPOINT_NOTHROW;
-
- return hr;
}
// Create a strong name token from a public key blob.
-SNAPI StrongNameTokenFromPublicKey(BYTE *pbPublicKeyBlob, // [in] public key blob
+HRESULT StrongNameTokenFromPublicKey(BYTE *pbPublicKeyBlob, // [in] public key blob
ULONG cbPublicKeyBlob,
BYTE **ppbStrongNameToken, // [out] strong name token
ULONG *pcbStrongNameToken)
{
- BOOLEAN retVal = FALSE;
-
- BEGIN_ENTRYPOINT_VOIDRET;
+ HRESULT hr = S_OK;
#ifndef DACCESS_COMPILE
PublicKeyBlob *pPublicKey = NULL;
DWORD dwHashLenMinusTokenSize = 0;
- SNLOG((W("StrongNameTokenFromPublicKey(%08X, %08X, %08X, %08X)\n"), pbPublicKeyBlob, cbPublicKeyBlob, ppbStrongNameToken, pcbStrongNameToken));
-
-#if STRONGNAME_IN_VM
- FireEtwSecurityCatchCall_V1(GetClrInstanceId());
-#endif // STRONGNAME_IN_VM
-
- SN_COMMON_PROLOG();
-
- if (pbPublicKeyBlob == NULL)
- SN_ERROR(E_POINTER);
if (!StrongNameIsValidPublicKey(pbPublicKeyBlob, cbPublicKeyBlob))
- SN_ERROR(CORSEC_E_INVALID_PUBLICKEY);
- if (ppbStrongNameToken == NULL)
- SN_ERROR(E_POINTER);
- if (pcbStrongNameToken == NULL)
- SN_ERROR(E_POINTER);
+ {
+ hr = CORSEC_E_INVALID_PUBLICKEY;
+ goto Exit;
+ }
// Allocate a buffer for the output token.
*ppbStrongNameToken = new (nothrow) BYTE[SN_SIZEOF_TOKEN];
if (*ppbStrongNameToken == NULL) {
- SetStrongNameErrorInfo(E_OUTOFMEMORY);
+ hr = E_OUTOFMEMORY;
goto Exit;
}
*pcbStrongNameToken = SN_SIZEOF_TOKEN;
// We cache a couple of common cases.
if (SN_IS_NEUTRAL_KEY(pbPublicKeyBlob)) {
memcpy_s(*ppbStrongNameToken, *pcbStrongNameToken, g_rbNeutralPublicKeyToken, SN_SIZEOF_TOKEN);
- retVal = TRUE;
goto Exit;
}
if (cbPublicKeyBlob == SN_SIZEOF_THE_KEY() &&
memcmp(pbPublicKeyBlob, SN_THE_KEY(), cbPublicKeyBlob) == 0) {
memcpy_s(*ppbStrongNameToken, *pcbStrongNameToken, SN_THE_KEYTOKEN(), SN_SIZEOF_TOKEN);
- retVal = TRUE;
goto Exit;
}
if (SN_IS_THE_SILVERLIGHT_PLATFORM_KEY(pbPublicKeyBlob))
{
memcpy_s(*ppbStrongNameToken, *pcbStrongNameToken, SN_THE_SILVERLIGHT_PLATFORM_KEYTOKEN(), SN_SIZEOF_TOKEN);
- retVal = TRUE;
goto Exit;
}
if (SN_IS_THE_SILVERLIGHT_KEY(pbPublicKeyBlob))
{
memcpy_s(*ppbStrongNameToken, *pcbStrongNameToken, SN_THE_SILVERLIGHT_KEYTOKEN(), SN_SIZEOF_TOKEN);
- retVal = TRUE;
goto Exit;
}
// which could make finding a public key token collision a significantly easier task
// since an attacker wouldn't need to work hard on generating valid key pairs before hashing.
if (cbPublicKeyBlob <= sizeof(PublicKeyBlob)) {
- SetLastError(CORSEC_E_INVALID_PUBLICKEY);
+ hr = CORSEC_E_INVALID_PUBLICKEY;
goto Error;
}
pPublicKey = (PublicKeyBlob*) pbPublicKeyBlob;
if (pPublicKey->PublicKey + GET_UNALIGNED_VAL32(&pPublicKey->cbPublicKey) < pPublicKey->PublicKey) {
- SetLastError(CORSEC_E_INVALID_PUBLICKEY);
+ hr = CORSEC_E_INVALID_PUBLICKEY;
goto Error;
}
if (cbPublicKeyBlob < SN_SIZEOF_KEY(pPublicKey)) {
- SetLastError(CORSEC_E_INVALID_PUBLICKEY);
+ hr = CORSEC_E_INVALID_PUBLICKEY;
goto Error;
}
if (*(BYTE*) pPublicKey->PublicKey /* PUBLICKEYSTRUC->bType */ != PUBLICKEYBLOB) {
- SetLastError(CORSEC_E_INVALID_PUBLICKEY);
+ hr = CORSEC_E_INVALID_PUBLICKEY;
goto Error;
}
for (i = 0; i < SN_SIZEOF_TOKEN; i++)
(*ppbStrongNameToken)[SN_SIZEOF_TOKEN - (i + 1)] = pHash[i + dwHashLenMinusTokenSize];
- retVal = TRUE;
goto Exit;
Error:
- SetStrongNameErrorInfo(HRESULT_FROM_GetLastError());
-
if (*ppbStrongNameToken) {
delete [] *ppbStrongNameToken;
*ppbStrongNameToken = NULL;
#else
DacNotImpl();
#endif // #ifndef DACCESS_COMPILE
- END_ENTRYPOINT_VOIDRET;
-
- return retVal;
+ return hr;
}
+++ /dev/null
-add_subdirectory(api)
\ No newline at end of file
+++ /dev/null
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-#this will again add vm to include directories. However, this will add vm to be the first include folder.
-#This is required because util.hpp is also present in ildasm folder and so due to ordering wrong util.hpp
-#is pickedup.
-include_directories(BEFORE ${VM_DIR})
-
-include_directories(${VM_DIR}/${ARCH_SOURCES_DIR})
-include_directories(${CLR_DIR}/src/md/compiler)
-
-add_definitions(-DSNAPI_INTERNAL)
-
-set(STRONGNAME_SOURCES
- strongname.cpp
- strongnameinternal.cpp
-)
-
-convert_to_absolute_path(STRONGNAME_SOURCES ${STRONGNAME_SOURCES})
-
-add_library_clr(strongname_tool ${STRONGNAME_SOURCES})
-
-add_library_clr(strongname_dac ${STRONGNAME_SOURCES})
-add_dependencies(strongname_dac eventing_headers)
-set_target_properties(strongname_dac PROPERTIES DAC_COMPONENT TRUE)
-target_compile_definitions(strongname_dac PRIVATE STRONGNAME_IN_VM)
-
-add_library_clr(strongname_wks ${STRONGNAME_SOURCES})
-add_dependencies(strongname_wks eventing_headers)
-target_compile_definitions(strongname_wks PRIVATE STRONGNAME_IN_VM)
-
-add_library_clr(strongname_crossgen ${STRONGNAME_SOURCES})
-add_dependencies(strongname_crossgen eventing_headers)
-set_target_properties(strongname_crossgen PROPERTIES CROSSGEN_COMPONENT TRUE)
-target_compile_definitions(strongname_crossgen PRIVATE STRONGNAME_IN_VM)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#include "common.h"
-
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-//
-// common.h - precompiled headers include for the COM+ Execution Engine
-//
-
-#ifndef _common_h_
-#define _common_h_
-
-#if defined(_MSC_VER) && defined(_X86_) && !defined(FPO_ON)
-#pragma optimize("y", on) // Small critical routines, don't put in EBP frame
-#define FPO_ON 1
-#define COMMON_TURNED_FPO_ON 1
-#endif
-
-#if STRONGNAME_IN_VM
-
-#define USE_COM_CONTEXT_DEF
-
-#ifdef _DEBUG
-#define DEBUG_REGDISPLAY
-#endif
-
-#ifdef _MSC_VER
-
- // These don't seem useful, so turning them off is no big deal
-#pragma warning(disable:4244) // loss of data int -> char ..
-
-#ifndef DEBUG
-#pragma warning(disable:4189) // local variable initialized but not used
-#pragma warning(disable:4505) // unreferenced local function has been removed
-#pragma warning(disable:4313) // 'format specifier' in format string conflicts with argument %d of type 'type'
-#endif // !DEBUG
-
-
-#endif // _MSC_VER
-
-#endif // STRONGNAME_IN_VM
-
-#define _CRT_DEPENDENCY_ //this code depends on the crt file functions
-
-
-#include <stdint.h>
-#include <winwrap.h>
-
-#include <windows.h>
-#include <wincrypt.h>
-#include <winnt.h>
-#include <crosscomp.h>
-#include <clrnt.h>
-#include <stdlib.h>
-#include <wchar.h>
-#include <objbase.h>
-#include <stddef.h>
-#include <float.h>
-#include <math.h>
-#include <time.h>
-#include <limits.h>
-
-#include <olectl.h>
-
-#ifdef _MSC_VER
-//non inline intrinsics are faster
-#pragma function(memcpy,memcmp,strcmp,strcpy,strlen,strcat)
-#endif // _MSC_VER
-
-//-----------------------------------------------------------------------------------------------------------
-
-#include "strongname.h"
-#include "stdmacros.h"
-
-#define POISONC ((UINT_PTR)((sizeof(int *) == 4)?0xCCCCCCCCL:I64(0xCCCCCCCCCCCCCCCC)))
-
-#include "ndpversion.h"
-#include "switches.h"
-#include "holder.h"
-
-#if STRONGNAME_IN_VM
-#include "classnames.h"
-#include "util.hpp"
-#endif // STRONGNAME_IN_VM
-
-#include "corpriv.h"
-
-#include <daccess.h>
-
-#if STRONGNAME_IN_VM
-
-typedef VPTR(class LoaderAllocator) PTR_LoaderAllocator;
-typedef VPTR(class AppDomain) PTR_AppDomain;
-typedef DPTR(class ArrayBase) PTR_ArrayBase;
-typedef DPTR(class ArrayTypeDesc) PTR_ArrayTypeDesc;
-typedef DPTR(class Assembly) PTR_Assembly;
-typedef DPTR(class AssemblyBaseObject) PTR_AssemblyBaseObject;
-typedef DPTR(class AssemblyLoadContextBaseObject) PTR_AssemblyLoadContextBaseObject;
-typedef DPTR(class AssemblyNameBaseObject) PTR_AssemblyNameBaseObject;
-typedef VPTR(class BaseDomain) PTR_BaseDomain;
-typedef DPTR(class MscorlibBinder) PTR_MscorlibBinder;
-typedef DPTR(class ClassLoader) PTR_ClassLoader;
-typedef DPTR(class ComCallMethodDesc) PTR_ComCallMethodDesc;
-typedef VPTR(class CompilationDomain) PTR_CompilationDomain;
-typedef DPTR(class ComPlusCallMethodDesc) PTR_ComPlusCallMethodDesc;
-typedef VPTR(class DebugInterface) PTR_DebugInterface;
-typedef DPTR(class Dictionary) PTR_Dictionary;
-typedef VPTR(class DomainAssembly) PTR_DomainAssembly;
-typedef VPTR(class DomainFile) PTR_DomainFile;
-typedef VPTR(class DomainModule) PTR_DomainModule;
-typedef DPTR(struct FailedAssembly) PTR_FailedAssembly;
-typedef VPTR(class EditAndContinueModule) PTR_EditAndContinueModule;
-typedef DPTR(class EEClass) PTR_EEClass;
-typedef DPTR(class DelegateEEClass) PTR_DelegateEEClass;
-typedef DPTR(struct DomainLocalModule) PTR_DomainLocalModule;
-typedef VPTR(class EECodeManager) PTR_EECodeManager;
-typedef DPTR(class EEConfig) PTR_EEConfig;
-typedef VPTR(class EEDbgInterfaceImpl) PTR_EEDbgInterfaceImpl;
-typedef VPTR(class DebugInfoManager) PTR_DebugInfoManager;
-typedef DPTR(class FieldDesc) PTR_FieldDesc;
-typedef VPTR(class Frame) PTR_Frame;
-typedef DPTR(class GCFrame) PTR_GCFrame;
-typedef VPTR(class ICodeManager) PTR_ICodeManager;
-typedef VPTR(class IJitManager) PTR_IJitManager;
-typedef DPTR(class InstMethodHashTable) PTR_InstMethodHashTable;
-typedef DPTR(class MetaSig) PTR_MetaSig;
-typedef DPTR(class MethodDesc) PTR_MethodDesc;
-typedef DPTR(class MethodDescChunk) PTR_MethodDescChunk;
-typedef DPTR(class MethodImpl) PTR_MethodImpl;
-typedef DPTR(class MethodTable) PTR_MethodTable;
-typedef VPTR(class Module) PTR_Module;
-typedef DPTR(class NDirectMethodDesc) PTR_NDirectMethodDesc;
-typedef DPTR(class Thread) PTR_Thread;
-typedef DPTR(class Object) PTR_Object;
-typedef DPTR(PTR_Object) PTR_PTR_Object;
-typedef DPTR(class ObjHeader) PTR_ObjHeader;
-typedef DPTR(class Precode) PTR_Precode;
-typedef VPTR(class ReflectionModule) PTR_ReflectionModule;
-typedef DPTR(class ReflectClassBaseObject) PTR_ReflectClassBaseObject;
-typedef DPTR(class ReflectModuleBaseObject) PTR_ReflectModuleBaseObject;
-typedef DPTR(class ReflectMethodObject) PTR_ReflectMethodObject;
-typedef DPTR(class ReflectFieldObject) PTR_ReflectFieldObject;
-typedef DPTR(class ReJitManager) PTR_ReJitManager;
-typedef DPTR(struct ReJitInfo) PTR_ReJitInfo;
-typedef DPTR(struct SharedReJitInfo) PTR_SharedReJitInfo;
-typedef DPTR(class StringObject) PTR_StringObject;
-#ifdef FEATURE_UTF8STRING
-typedef DPTR(class Utf8StringObject) PTR_Utf8StringObject;
-#endif // FEATURE_UTF8STRING
-typedef DPTR(class TypeHandle) PTR_TypeHandle;
-#ifdef STUB_DISPATCH
-typedef VPTR(class VirtualCallStubManager) PTR_VirtualCallStubManager;
-typedef VPTR(class VirtualCallStubManagerManager) PTR_VirtualCallStubManagerManager;
-#endif
-typedef VPTR(class IGCHeap) PTR_IGCHeap;
-
-//
-// _UNCHECKED_OBJECTREF is for code that can't deal with DEBUG OBJECTREFs
-//
-typedef PTR_Object _UNCHECKED_OBJECTREF;
-typedef DPTR(PTR_Object) PTR_UNCHECKED_OBJECTREF;
-
-#ifdef USE_CHECKED_OBJECTREFS
-class OBJECTREF;
-#else
-typedef PTR_Object OBJECTREF;
-#endif
-typedef DPTR(OBJECTREF) PTR_OBJECTREF;
-typedef DPTR(PTR_OBJECTREF) PTR_PTR_OBJECTREF;
-
-
-EXTERN_C Thread* STDCALL GetThread();
-
-// This is a mechanism by which macros can make the Thread pointer available to inner scopes
-// that is robust to code changes. If the outer Thread no longer is available for some reason
-// (e.g. code refactoring), this GET_THREAD() macro will fall back to calling GetThread().
-const bool CURRENT_THREAD_AVAILABLE = false;
-Thread * const CURRENT_THREAD = NULL;
-#define GET_THREAD() (CURRENT_THREAD_AVAILABLE ? CURRENT_THREAD : GetThread())
-
-#define MAKE_CURRENT_THREAD_AVAILABLE() \
- Thread * __pThread = GET_THREAD(); \
- MAKE_CURRENT_THREAD_AVAILABLE_EX(__pThread)
-
-#define MAKE_CURRENT_THREAD_AVAILABLE_EX(__pThread) \
- Thread * CURRENT_THREAD = __pThread; \
- const bool CURRENT_THREAD_AVAILABLE = true; \
- (void)CURRENT_THREAD_AVAILABLE; /* silence "local variable initialized but not used" warning */ \
-
-#ifndef DACCESS_COMPILE
-EXTERN_C AppDomain* STDCALL GetAppDomain();
-#endif //!DACCESS_COMPILE
-
-inline void RetailBreak()
-{
-#if defined(_TARGET_X86_)
- __asm int 3
-#else
- DebugBreak();
-#endif
-}
-
-extern BOOL isMemoryReadable(const TADDR start, unsigned len);
-
-#ifndef memcpyUnsafe_f
-#define memcpyUnsafe_f
-
-// use this when you want to memcpy something that contains GC refs
-inline void* memcpyUnsafe(void *dest, const void *src, size_t len)
-{
- WRAPPER_NO_CONTRACT;
- return memcpy(dest, src, len);
-}
-
-#endif // !memcpyUnsafe_f
-
-//
-// By default logging, and debug GC are enabled under debug
-//
-// These can be enabled in non-debug by removing the #ifdef _DEBUG
-// allowing one to log/check_gc a free build.
-//
-#if defined(_DEBUG) && !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
-
- //If memcpy has been defined to PAL_memcpy, we undefine it so that this case
- //can be covered by the if !defined(memcpy) block below
- #ifdef FEATURE_PAL
- #if IS_REDEFINED_IN_PAL(memcpy)
- #undef memcpy
- #endif //IS_REDEFINED_IN_PAL
- #endif //FEATURE_PAL
-
- // You should be using CopyValueClass if you are doing an memcpy
- // in the CG heap.
- #if !defined(memcpy)
- inline void* memcpyNoGCRefs(void * dest, const void * src, size_t len) {
- WRAPPER_NO_CONTRACT;
-
- #ifndef FEATURE_PAL
- return memcpy(dest, src, len);
- #else //FEATURE_PAL
- return PAL_memcpy(dest, src, len);
- #endif //FEATURE_PAL
-
- }
- extern "C" void * __cdecl GCSafeMemCpy(void *, const void *, size_t);
- #define memcpy(dest, src, len) GCSafeMemCpy(dest, src, len)
- #endif // !defined(memcpy)
-#else // !_DEBUG && !DACCESS_COMPILE && !CROSSGEN_COMPILE
- inline void* memcpyNoGCRefs(void * dest, const void * src, size_t len) {
- WRAPPER_NO_CONTRACT;
- return memcpy(dest, src, len);
- }
-#endif // !_DEBUG && !DACCESS_COMPILE && !CROSSGEN_COMPILE
-
-namespace Loader
-{
- typedef enum
- {
- Load, //should load
- DontLoad, //should not load
- SafeLookup //take no locks, no allocations
- } LoadFlag;
-}
-
-#endif // STRONGNAME_IN_VM
-
-// src/inc
-#include "utilcode.h"
-#include "log.h"
-#include "loaderheap.h"
-
-#if STRONGNAME_IN_VM
-
-// src/vm
-#include "gcenv.interlocked.h"
-#include "gcenv.interlocked.inl"
-
-#include "util.hpp"
-#include "ibclogger.h"
-#include "eepolicy.h"
-
-#include "vars.hpp"
-#include "crst.h"
-#include "argslot.h"
-#include "stublink.h"
-#include "cgensys.h"
-#include "ceemain.h"
-#include "hash.h"
-#include "eecontract.h"
-#include "pedecoder.h"
-#include "sstring.h"
-#include "slist.h"
-
-#include "eeconfig.h"
-
-#include "spinlock.h"
-#include "cgensys.h"
-
-#ifdef FEATURE_COMINTEROP
-#include "stdinterfaces.h"
-#endif
-
-#include "typehandle.h"
-#include "methodtable.h"
-#include "typectxt.h"
-
-#include "eehash.h"
-
-#include "vars.hpp"
-#include "eventstore.hpp"
-
-#include "synch.h"
-#include "regdisp.h"
-#include "stackframe.h"
-#include "gms.h"
-#include "fcall.h"
-#include "syncblk.h"
-#include "gcdesc.h"
-#include "specialstatics.h"
-#include "object.h" // <NICE> We should not really need to put this so early... </NICE>
-#include "gchelpers.h"
-#include "pefile.h"
-#include "clrex.h"
-#include "clsload.hpp" // <NICE> We should not really need to put this so early... </NICE>
-#include "siginfo.hpp"
-#include "binder.h"
-#include "jitinterface.h" // <NICE> We should not really need to put this so early... </NICE>
-#include "ceeload.h"
-#include "memberload.h"
-#include "genericdict.h"
-#include "class.h"
-#include "codeman.h"
-#include "threads.h"
-#include "clrex.inl"
-#include "loaderallocator.hpp"
-#include "appdomain.hpp"
-#include "assembly.hpp"
-#include "pefile.inl"
-#include "excep.h"
-#include "method.hpp"
-#include "frames.h"
-
-#include "stackwalk.h"
-#include "stackingallocator.h"
-#include "interoputil.h"
-#include "wrappers.h"
-#include "dynamicmethod.h"
-
-
-HRESULT EnsureRtlFunctions();
-HINSTANCE GetModuleInst();
-
-
-#if defined(_DEBUG)
-
-// This catches CANNOTTHROW macros that occur outside the scope of a CONTRACT.
-// Note that it's important for m_CannotThrowLineNums to be NULL.
-struct DummyGlobalContract
-{
- int *m_CannotThrowLineNums; //= NULL;
- LPVOID *m_CannotThrowRecords; //= NULL;
-};
-
-extern DummyGlobalContract ___contract;
-
-#endif // defined(_DEBUG)
-
-
-// All files get to see all of these .inl files to make sure all files
-// get the benefit of inlining.
-#include "ceeload.inl"
-#include "typedesc.inl"
-#include "class.inl"
-#include "methodtable.inl"
-#include "typehandle.inl"
-#include "object.inl"
-#include "ceeload.inl"
-#include "clsload.inl"
-#include "domainfile.inl"
-#include "clsload.inl"
-#include "method.inl"
-#include "syncblk.inl"
-#include "threads.inl"
-#include "eehash.inl"
-
-#endif // STRONGNAME_IN_VM
-
-#include "pedecoder.h"
-
-#if defined(COMMON_TURNED_FPO_ON)
-#pragma optimize("", on) // Go back to command line default optimizations
-#undef COMMON_TURNED_FPO_ON
-#undef FPO_ON
-#endif
-
-#endif // !_common_h_
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-//
-// Strong name APIs which are not exposed publicly but are used by CLR code
-//
-
-#include "common.h"
-#include "strongnameinternal.h"
-#include "strongnameholders.h"
-#include "thekey.h"
-#include "ecmakey.h"
-
-//---------------------------------------------------------------------------------------
-//
-// Check to see if a public key blob is the ECMA public key blob
-//
-// Arguments:
-// pbKey - public key blob to check
-// cbKey - size in bytes of pbKey
-//
-
-bool StrongNameIsEcmaKey(__in_ecount(cbKey) const BYTE *pbKey, DWORD cbKey)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- // The key should be the same size as the ECMA key
- if (cbKey != sizeof(g_rbNeutralPublicKey))
- {
- return false;
- }
-
- const PublicKeyBlob *pKeyBlob = reinterpret_cast<const PublicKeyBlob *>(pbKey);
- return StrongNameIsEcmaKey(*pKeyBlob);
-}
-
-//---------------------------------------------------------------------------------------
-//
-// Check to see if a public key blob is the ECMA public key blob
-//
-// Arguments:
-// keyPublicKey - Key to check to see if it matches the ECMA key
-//
-
-bool StrongNameIsEcmaKey(const PublicKeyBlob &keyPublicKey)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- return StrongNameSizeOfPublicKey(keyPublicKey) == sizeof(g_rbNeutralPublicKey) &&
- memcmp(reinterpret_cast<const BYTE *>(&keyPublicKey), g_rbNeutralPublicKey, sizeof(g_rbNeutralPublicKey)) == 0;
-}
-
-//---------------------------------------------------------------------------------------
-//
-// Verify that a public key blob looks like a reasonable public key
-//
-// Arguments:
-// pbBuffer - buffer to verify the format of
-// cbBuffer - size of pbBuffer
-//
-
-bool StrongNameIsValidPublicKey(__in_ecount(cbBuffer) const BYTE *pbBuffer, DWORD cbBuffer)
-{
- CONTRACTL
- {
- PRECONDITION(CheckPointer(pbBuffer));
- NOTHROW;
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- // The buffer must be at least as large as the public key structure
- if (cbBuffer < sizeof(PublicKeyBlob))
- {
- return false;
- }
-
- // The buffer must be the same size as the structure header plus the trailing key data
- const PublicKeyBlob *pkeyPublicKey = reinterpret_cast<const PublicKeyBlob *>(pbBuffer);
- if (GET_UNALIGNED_VAL32(&pkeyPublicKey->cbPublicKey) != cbBuffer - offsetof(PublicKeyBlob, PublicKey))
- {
- return false;
- }
-
- // The buffer itself looks reasonable, but the public key structure needs to be validated as well
- return StrongNameIsValidPublicKey(*pkeyPublicKey);
-}
-
-//---------------------------------------------------------------------------------------
-//
-// Verify that a public key blob looks like a reasonable public key.
-//
-// Arguments:
-// keyPublicKey - key blob to verify
-//
-// Notes:
-// This can be a very expensive operation, since it involves importing keys.
-//
-
-bool StrongNameIsValidPublicKey(const PublicKeyBlob &keyPublicKey)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- // The ECMA key doesn't look like a valid key so it will fail the below checks. If we were passed that
- // key, then we can skip them
- if (StrongNameIsEcmaKey(keyPublicKey))
- {
- return true;
- }
-
- // If a hash algorithm is specified, it must be a sensible value
- bool fHashAlgorithmValid = GET_ALG_CLASS(GET_UNALIGNED_VAL32(&keyPublicKey.HashAlgID)) == ALG_CLASS_HASH &&
- GET_ALG_SID(GET_UNALIGNED_VAL32(&keyPublicKey.HashAlgID)) >= ALG_SID_SHA1;
- if (keyPublicKey.HashAlgID != 0 && !fHashAlgorithmValid)
- {
- return false;
- }
-
- // If a signature algorithm is specified, it must be a sensible value
- bool fSignatureAlgorithmValid = GET_ALG_CLASS(GET_UNALIGNED_VAL32(&keyPublicKey.SigAlgID)) == ALG_CLASS_SIGNATURE;
- if (keyPublicKey.SigAlgID != 0 && !fSignatureAlgorithmValid)
- {
- return false;
- }
-
- // The key blob must indicate that it is a PUBLICKEYBLOB
- if (keyPublicKey.PublicKey[0] != PUBLICKEYBLOB)
- {
- return false;
- }
-
- return true;
-}
-
-
-//---------------------------------------------------------------------------------------
-//
-// Determine the number of bytes that a public key blob occupies, including the key portion
-//
-// Arguments:
-// keyPublicKey - key blob to calculate the size of
-//
-
-DWORD StrongNameSizeOfPublicKey(const PublicKeyBlob &keyPublicKey)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- return offsetof(PublicKeyBlob, PublicKey) + // Size of the blob header plus
- GET_UNALIGNED_VAL32(&keyPublicKey.cbPublicKey); // the number of bytes in the key
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-#ifndef __STRONG_NAME_H
-#define __STRONG_NAME_H
-
-// ===========================================================================
-// File: StrongName.h
-//
-// Wrappers for signing and hashing functions needed to implement strong names
-// ===========================================================================
-
-
-#include <windows.h>
-#include <wincrypt.h>
-#include <ole2.h>
-
-#include <corerror.h>
-#include <winapifamily.h>
-
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
-
-#ifdef __cplusplus
-extern "C"{
-#endif
-
-
-// Public key blob binary format.
-typedef struct {
- unsigned int SigAlgID; // (ALG_ID) signature algorithm used to create the signature
- unsigned int HashAlgID; // (ALG_ID) hash algorithm used to create the signature
- ULONG cbPublicKey; // length of the key in bytes
- BYTE PublicKey[1]; // variable length byte array containing the key value in format output by CryptoAPI
-} PublicKeyBlob;
-
-
-// Location in the registry (under HKLM) that strong name configuration info is
-// stored.
-#define SN_CONFIG_KEY "Software\\Microsoft\\StrongName"
-#define SN_CONFIG_CSP "CSP" // REG_SZ
-#define SN_CONFIG_MACHINE_KEYSET "MachineKeyset" // REG_DWORD
-#define SN_CONFIG_KEYSPEC "KeySpec" // REG_DWORD
-#define SN_CONFIG_HASH_ALG "HashAlgorithm" // REG_DWORD
-#define SN_CONFIG_SIGN_ALG "SignAlgorithm" // REG_DWORD
-#define SN_CONFIG_VERIFICATION "Verification" // Registry subkey
-#define SN_CONFIG_USERLIST "UserList" // REG_MULTI_SZ
-#define SN_CONFIG_CACHE_VERIFY "CacheVerify" // REG_DWORD
-
-#define SN_CONFIG_KEY_W L"Software\\Microsoft\\StrongName"
-#define SN_CONFIG_CSP_W L"CSP" // REG_SZ
-#define SN_CONFIG_PROV_TYPE_W L"ProvType" // REG_DWORD
-#define SN_CONFIG_MACHINE_KEYSET_W L"MachineKeyset" // REG_DWORD
-#define SN_CONFIG_KEYSPEC_W L"KeySpec" // REG_DWORD
-#define SN_CONFIG_HASH_ALG_W L"HashAlgorithm" // REG_DWORD
-#define SN_CONFIG_SIGN_ALG_W L"SignAlgorithm" // REG_DWORD
-#define SN_CONFIG_VERIFICATION_W L"Verification" // Registry subkey
-#define SN_CONFIG_USERLIST_W L"UserList" // REG_MULTI_SZ
-#define SN_CONFIG_TESTPUBLICKEY_W L"TestPublicKey" // REG_SZ
-#define SN_CONFIG_CACHE_VERIFY_W L"CacheVerify" // REG_DWORD
-
-// VM related registry locations (Note, these values are under HKLM\Software\Microsoft\.NETFramework, rather
-// than SN_CONFIG_KEY
-#define SN_CONFIG_BYPASS_POLICY "AllowStrongNameBypass" // REG_DWORD
-#define SN_CONFIG_BYPASS_POLICY_W L"AllowStrongNameBypass" // REG_DWORD
-
-#if defined(_MSC_VER) && !defined(USE_DEPRECATED_CLR_API_WITHOUT_WARNING)
-#define DEPRECATED_CLR_API_MESG "This API has been deprecated. Refer to http://go.microsoft.com/fwlink/?LinkId=143720 for more details."
-#define DECLARE_DEPRECATED __declspec(deprecated(DEPRECATED_CLR_API_MESG))
-#else // _MSC_VER && !USE_DEPRECATED_CLR_API_WITHOUT_WARNING
-#define DECLARE_DEPRECATED
-#endif // _MSC_VER && !USE_DEPRECATED_CLR_API_WITHOUT_WARNING
-
-#define SNAPI DECLARE_DEPRECATED BOOLEAN __stdcall
-#define SNAPI_(_type) DECLARE_DEPRECATED _type __stdcall
-
-// Return last error.
-SNAPI_(DWORD) StrongNameErrorInfo(VOID);
-
-
-// Free buffer allocated by routines below.
-SNAPI_(VOID) StrongNameFreeBuffer(BYTE *pbMemory); // [in] address of memory to free
-
-
-// Generate a new key pair for strong name use.
-SNAPI StrongNameKeyGen(LPCWSTR wszKeyContainer, // [in] desired key container name
- DWORD dwFlags, // [in] flags (see below)
- BYTE **ppbKeyBlob, // [out] public/private key blob
- ULONG *pcbKeyBlob);
-
-// Generate a new key pair with the specified key size for strong name use.
-SNAPI StrongNameKeyGenEx(LPCWSTR wszKeyContainer, // [in] desired key container name, must be a non-empty string
- DWORD dwFlags, // [in] flags (see below)
- DWORD dwKeySize, // [in] desired key size.
- BYTE **ppbKeyBlob, // [out] public/private key blob
- ULONG *pcbKeyBlob);
-
-// Flags for StrongNameKeyGen.
-#define SN_LEAVE_KEY 0x00000001 // Leave key pair registered with CSP
-
-
-// Import key pair into a key container.
-SNAPI StrongNameKeyInstall(LPCWSTR wszKeyContainer,// [in] desired key container name, must be a non-empty string
- BYTE *pbKeyBlob, // [in] public/private key pair blob
- ULONG cbKeyBlob);
-
-
-// Delete a key pair.
-SNAPI StrongNameKeyDelete(LPCWSTR wszKeyContainer); // [in] desired key container name
-
-// Retrieve the public portion of a key pair.
-SNAPI StrongNameGetPublicKey (LPCWSTR wszKeyContainer, // [in] desired key container name
- BYTE *pbKeyBlob, // [in] public/private key blob (optional)
- ULONG cbKeyBlob,
- BYTE **ppbPublicKeyBlob, // [out] public key blob
- ULONG *pcbPublicKeyBlob);
-
-// Retrieve the public portion of a key pair.
-SNAPI StrongNameGetPublicKeyEx (LPCWSTR wszKeyContainer, // [in] desired key container name
- BYTE *pbKeyBlob, // [in] public/private key blob (optional)
- ULONG cbKeyBlob,
- BYTE **ppbPublicKeyBlob, // [out] public key blob
- ULONG *pcbPublicKeyBlob,
- ULONG uHashAlgId,
- ULONG uReserved); // reserved for future use
-
-// Hash and sign a manifest.
-SNAPI StrongNameSignatureGeneration(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- LPCWSTR wszKeyContainer, // [in] desired key container name
- BYTE *pbKeyBlob, // [in] public/private key blob (optional)
- ULONG cbKeyBlob,
- BYTE **ppbSignatureBlob, // [out] signature blob
- ULONG *pcbSignatureBlob);
-
-SNAPI StrongNameSignatureGenerationEx(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- LPCWSTR wszKeyContainer, // [in] desired key container name
- BYTE *pbKeyBlob, // [in] public/private key blob (optional)
- ULONG cbKeyBlob,
- BYTE **ppbSignatureBlob, // [out] signature blob
- ULONG *pcbSignatureBlob,
- DWORD dwFlags); // [in] modifer flags; see below
-
-#define SN_SIGN_ALL_FILES 0x00000001 // Rehash all linked modules as well as resigning the manifest
-#define SN_TEST_SIGN 0x00000002 // Test sign the assembly
-#define SN_ECMA_SIGN 0x00000004 // Sign the assembly treating the input key as the real ECMA key
-
-// Digest signing support
-
-// Generate the digest of an input assembly, which can be signed with StrongNameDigestSign
-SNAPI StrongNameDigestGenerate(_In_z_ LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- _Outptr_result_bytebuffer_(*pcbDigestBlob) BYTE** ppbDigestBlob, // [out] digest of the assembly, free with StrongNameFreeBuffer
- _Out_ ULONG* pcbDigestBlob, // [out] number of bytes in the assembly digest
- DWORD dwFlags); // [in] modifier flags (see StrongNameSignatureGenerationEx)
-
-// Sign an the digest of an assembly calculated by StrongNameDigestGenerate
-SNAPI StrongNameDigestSign(_In_opt_z_ LPCWSTR wszKeyContainer, // [in] desired key container name (optional)
- _In_reads_bytes_opt_(cbKeyBlob) BYTE* pbKeyBlob, // [in] public/private key blob (optional)
- ULONG cbKeyBlob,
- _In_reads_bytes_(cbDigestBlob) BYTE* pbDigestBlob, // [in] digest blob, from StrongNameDigestGenerate
- ULONG cbDigestBlob,
- DWORD hashAlgId, // [in] algorithm id of the hash algorithm used with pbDigestBlob
- _Outptr_result_bytebuffer_(*pcbSignatureBlob) BYTE** ppbSignatureBlob, // [out] signature blob, freed with StrongNameFreeBuffer
- _Out_ ULONG* pcbSignatureBlob,
- DWORD dwFlags); // [in] modifier flags (see StrongNameSignatureGenerationEx)
-
-// Embed a digest signature generated with StrongNameDigestSign into an assembly
-SNAPI StrongNameDigestEmbed(_In_z_ LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly to update
- _In_reads_bytes_(cbSignatureBlob) BYTE* pbSignatureBlob, // [in] signature blob for the assembly
- ULONG cbSignatureBlob);
-
-// Create a strong name token from an assembly file.
-SNAPI StrongNameTokenFromAssembly(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- BYTE **ppbStrongNameToken, // [out] strong name token
- ULONG *pcbStrongNameToken);
-
-// Create a strong name token from an assembly file and additionally return the full public key.
-SNAPI StrongNameTokenFromAssemblyEx(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- BYTE **ppbStrongNameToken, // [out] strong name token
- ULONG *pcbStrongNameToken,
- BYTE **ppbPublicKeyBlob, // [out] public key blob
- ULONG *pcbPublicKeyBlob);
-
-// Create a strong name token from a public key blob.
-SNAPI StrongNameTokenFromPublicKey(BYTE *pbPublicKeyBlob, // [in] public key blob
- ULONG cbPublicKeyBlob,
- BYTE **ppbStrongNameToken, // [out] strong name token
- ULONG *pcbStrongNameToken);
-
-
-// Verify a strong name/manifest against a public key blob.
-SNAPI StrongNameSignatureVerification(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- DWORD dwInFlags, // [in] flags modifying behaviour (see below)
- DWORD *pdwOutFlags); // [out] additional output info (see below)
-
-
-// Verify a strong name/manifest against a public key blob.
-SNAPI StrongNameSignatureVerificationEx(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- BOOLEAN fForceVerification, // [in] verify even if settings in the registry disable it
- BOOLEAN *pfWasVerified); // [out] set to false if verify succeeded due to registry settings
-
-// Verify a strong name/manifest against a public key blob.
-SNAPI StrongNameSignatureVerificationEx2(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- BOOLEAN fForceVerification, // [in] verify even if settings in the registry disable it
- BYTE *pbEcmaPublicKey, // [in] mapping from the ECMA public key to the real key used for verification
- DWORD cbEcmaPublicKey, // [in] length of the real ECMA public key
- BOOLEAN *pfWasVerified); // [out] set to false if verify succeeded due to registry settings
-
-// Verify a strong name/manifest against a public key blob when the assembly is
-// already memory mapped.
-SNAPI StrongNameSignatureVerificationFromImage(BYTE *pbBase, // [in] base address of mapped manifest file
- DWORD dwLength, // [in] length of mapped image in bytes
- DWORD dwInFlags, // [in] flags modifying behaviour (see below)
- DWORD *pdwOutFlags); // [out] additional output info (see below)
-
-// Flags for use with the verify routines.
-#define SN_INFLAG_FORCE_VER 0x00000001 // verify even if settings in the registry disable it
-#define SN_INFLAG_INSTALL 0x00000002 // verification is the first (on entry to the cache)
-#define SN_INFLAG_ADMIN_ACCESS 0x00000004 // cache protects assembly from all but admin access
-#define SN_INFLAG_USER_ACCESS 0x00000008 // cache protects user's assembly from other users
-#define SN_INFLAG_ALL_ACCESS 0x00000010 // cache provides no access restriction guarantees
-
-#define SN_INFLAG_RUNTIME 0x80000000 // internal debugging use only
-
-#define SN_OUTFLAG_WAS_VERIFIED 0x00000001 // set to false if verify succeeded due to registry settings
-#define SN_OUTFLAG_MICROSOFT_SIGNATURE 0x00000002 // set if the public key corresponds to SN_THE_KEY
-
-// Verify that two assemblies differ only by signature blob.
-SNAPI StrongNameCompareAssemblies(LPCWSTR wszAssembly1, // [in] file name of first assembly
- LPCWSTR wszAssembly2, // [in] file name of second assembly
- DWORD *pdwResult); // [out] result of comparison (see codes below)
-
-#define SN_CMP_DIFFERENT 0 // Assemblies contain different data
-#define SN_CMP_IDENTICAL 1 // Assemblies are exactly the same, even signatures
-#define SN_CMP_SIGONLY 2 // Assemblies differ only by signature (and checksum etc.)
-
-
-// Compute the size of buffer needed to hold a hash for a given hash algorithm.
-SNAPI StrongNameHashSize(ULONG ulHashAlg, // [in] hash algorithm
- DWORD *pcbSize); // [out] size of the hash in bytes
-
-
-// Compute the size that needs to be allocated for a signature in an assembly.
-SNAPI StrongNameSignatureSize(BYTE *pbPublicKeyBlob, // [in] public key blob
- ULONG cbPublicKeyBlob,
- DWORD *pcbSize); // [out] size of the signature in bytes
-
-
-SNAPI_(DWORD) GetHashFromAssemblyFile(LPCSTR szFilePath, // [IN] location of file to be hashed
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI_(DWORD) GetHashFromAssemblyFileW(LPCWSTR wszFilePath, // [IN] location of file to be hashed
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI_(DWORD) GetHashFromFile(LPCSTR szFilePath, // [IN] location of file to be hashed
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI_(DWORD) GetHashFromFileW(LPCWSTR wszFilePath, // [IN] location of file to be hashed
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI_(DWORD) GetHashFromHandle(HANDLE hFile, // [IN] handle of file to be hashed
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI_(DWORD) GetHashFromBlob(BYTE *pbBlob, // [IN] pointer to memory block to hash
- DWORD cchBlob, // [IN] length of blob
- unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
- BYTE *pbHash, // [OUT] hash buffer
- DWORD cchHash, // [IN] max size of buffer
- DWORD *pchHash); // [OUT] length of hash byte array
-
-SNAPI StrongNameGetBlob(LPCWSTR wszFilePath, // [in] valid path to the PE file for the assembly
- BYTE *pbBlob, // [in] buffer to fill with blob
- DWORD *pcbBlob); // [in/out] size of buffer/number of bytes put into buffer
-
-SNAPI StrongNameGetBlobFromImage(BYTE *pbBase, // [in] base address of mapped manifest file
- DWORD dwLength, // [in] length of mapped image in bytes
- BYTE *pbBlob, // [in] buffer to fill with blob
- DWORD *pcbBlob); // [in/out] size of buffer/number of bytes put into buffer
-
-#undef DECLARE_DEPRECATED
-#undef DEPRECATED_CLR_API_MESG
-#undef SNAPI
-#undef SNAPI_
-#define SNAPI BOOLEAN __stdcall
-#define SNAPI_(_type) _type __stdcall
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
-
-#endif
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#ifndef __STRONGNAME_HOLDERS_H__
-#define __STRONGNAME_HOLDERS_H__
-
-#include <holder.h>
-#include <strongname.h>
-#include <wincrypt.h>
-
-//
-// Holder classes for types returned from and used in strong name APIs
-//
-
-// Holder for any memory allocated by the strong name APIs
-template<class T>
-void VoidStrongNameFreeBuffer(__in T *pBuffer)
-{
- StrongNameFreeBuffer(reinterpret_cast<BYTE *>(pBuffer));
-}
-NEW_WRAPPER_TEMPLATE1(StrongNameBufferHolder, VoidStrongNameFreeBuffer<_TYPE>);
-
-#if defined(CROSSGEN_COMPILE) && !defined(PLATFORM_UNIX)
-// Holder for HCRYPTPROV handles directly allocated from CAPI
-inline void ReleaseCapiProvider(HCRYPTPROV hProv)
-{
- CryptReleaseContext(hProv, 0);
-}
-typedef Wrapper<HCRYPTPROV, DoNothing, ReleaseCapiProvider, 0> CapiProviderHolder;
-
-inline void ReleaseCapiKey(HCRYPTKEY hKey)
-{
- CryptDestroyKey(hKey);
-}
-typedef Wrapper<HCRYPTKEY, DoNothing, ReleaseCapiKey, 0> CapiKeyHolder;
-
-inline void ReleaseCapiHash(HCRYPTHASH hHash)
-{
- CryptDestroyHash(hHash);
-}
-typedef Wrapper<HCRYPTHASH, DoNothing, ReleaseCapiHash, 0> CapiHashHolder;
-#endif // defined(CROSSGEN_COMPILE) && !defined(PLATFORM_UNIX)
-
-#if SNAPI_INTERNAL
-
-// Context structure tracking information for a loaded assembly.
-struct SN_LOAD_CTX
-{
- HANDLE m_hFile; // Open file handle
- HANDLE m_hMap; // Mapping file handle
- BYTE *m_pbBase; // Base address of mapped file
- DWORD m_dwLength; // Length of file in bytes
- IMAGE_NT_HEADERS32 *m_pNtHeaders; // Address of NT headers
- IMAGE_COR20_HEADER *m_pCorHeader; // Address of COM+ 2.0 header
- BYTE *m_pbSignature; // Address of signature blob
- DWORD m_cbSignature; // Size of signature blob
- BOOLEAN m_fReadOnly; // File mapped for read-only access
- BOOLEAN m_fPreMapped; // File was already mapped for us
- PEDecoder *m_pedecoder; // PEDecoder corresponding to this file
- SN_LOAD_CTX() { ZeroMemory(this, sizeof(*this)); }
-};
-
-BOOLEAN LoadAssembly(SN_LOAD_CTX *pLoadCtx, LPCWSTR szFilePath, DWORD inFlags = 0, BOOLEAN fRequireSignature = TRUE);
-BOOLEAN UnloadAssembly(SN_LOAD_CTX *pLoadCtx);
-
-// Holder for loading an assembly into an SN_LOAD_CTX
-class StrongNameAssemblyLoadHolder
-{
-private:
- SN_LOAD_CTX m_snLoadCtx;
- bool m_fLoaded;
-
-public:
- StrongNameAssemblyLoadHolder(LPCWSTR wszAssembly, bool fReadOnly)
- {
- m_snLoadCtx.m_fReadOnly = !!fReadOnly;
- m_fLoaded = !!LoadAssembly(&m_snLoadCtx, wszAssembly);
- }
-
- ~StrongNameAssemblyLoadHolder()
- {
- if (m_fLoaded)
- {
- UnloadAssembly(&m_snLoadCtx);
- }
- }
-
-public:
- SN_LOAD_CTX *GetLoadContext()
- {
- return &m_snLoadCtx;
- }
-
- bool IsLoaded()
- {
- return m_fLoaded;
- }
-};
-
-#endif // SNAPI_INTERNAL
-
-#endif // !__STRONGNAME_HOLDERS_H__
gcinfo_crossgen
corzap_crossgen
mscorlib_crossgen
- strongname_crossgen
utilcode_crossgen
v3binder_crossgen
)
"../../src/pal/prebuilt/inc",
"../../../../artifacts/obj",
"../../src/inc",
- "../../src/strongname/inc",
"../../src/inc/winrt",
"../../src/debug/inc",
"../../src/debug/inc/amd64",
#include "sha1.h"
#include "eeconfig.h"
-#include "strongname.h"
#include "ceefilegenwriter.h"
#include "assemblynative.hpp"
#include "assemblyname.hpp"
#include "field.h"
-#include "strongname.h"
+#include "strongnameinternal.h"
#include "eeconfig.h"
#ifndef URL_ESCAPE_AS_UTF8
{
GCX_PREEMP();
- if (!StrongNameTokenFromPublicKey(pbKey, cb, &pbToken, &cb))
- COMPlusThrowHR(StrongNameErrorInfo());
+ IfFailThrow(StrongNameTokenFromPublicKey(pbKey, cb, &pbToken, &cb));
}
}
#include "field.h"
#include "assemblyname.hpp"
#include "eeconfig.h"
-#include "strongname.h"
#include "interoputil.h"
#include "frames.h"
#include "typeparse.h"
BinderTracing::PathProbed(filePath, BinderTracing::PathSource::SatelliteSubdirectory, hr);
END_QCALL;
-}
\ No newline at end of file
+}
#include "assemblyspec.hpp"
#include "eeconfig.h"
-#include "strongname.h"
+#include "strongnameinternal.h"
#include "strongnameholders.h"
#include "eventtrace.h"
StrongNameBufferHolder<BYTE> pbStrongNameToken;
DWORD cbStrongNameToken;
- if (!StrongNameTokenFromPublicKey((BYTE*) pbPublicKey,
- cbPublicKey,
- &pbStrongNameToken,
- &cbStrongNameToken))
- ThrowHR(StrongNameErrorInfo());
+ IfFailThrow(StrongNameTokenFromPublicKey((BYTE*)pbPublicKey,
+ cbPublicKey,
+ &pbStrongNameToken,
+ &cbStrongNameToken));
if ((m_cbPublicKeyOrToken != cbStrongNameToken) ||
memcmp(m_pbPublicKeyOrToken, pbStrongNameToken, cbStrongNameToken))
if (m_cbPublicKeyOrToken && fUsePublicKeyToken && IsAfPublicKey(m_dwFlags)) {
StrongNameBufferHolder<BYTE> pbPublicKeyToken;
DWORD cbPublicKeyToken;
- if (!StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
- m_cbPublicKeyOrToken,
- &pbPublicKeyToken,
- &cbPublicKeyToken)) {
- IfFailGo(StrongNameErrorInfo());
- }
+ IfFailThrow(StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
+ m_cbPublicKeyOrToken,
+ &pbPublicKeyToken,
+ &cbPublicKeyToken));
hr = pEmit->DefineAssemblyRef(pbPublicKeyToken,
cbPublicKeyToken,
#include "../binder/inc/fusionassemblyname.hpp"
+#include "strongnameinternal.h"
+#include "strongnameholders.h"
+
VOID BaseAssemblySpec::CloneFieldsToStackingAllocator( StackingAllocator* alloc)
{
CONTRACTL
StrongNameBufferHolder<BYTE> pbPublicKeyToken;
DWORD cbPublicKeyToken;
- if (!StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
- m_cbPublicKeyOrToken,
- &pbPublicKeyToken,
- &cbPublicKeyToken))
- ThrowHR(StrongNameErrorInfo());
+ IfFailThrow(StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
+ m_cbPublicKeyOrToken,
+ &pbPublicKeyToken,
+ &cbPublicKeyToken));
BYTE *temp = new BYTE [cbPublicKeyToken];
memcpy(temp, pbPublicKeyToken, cbPublicKeyToken);
#include "reflectclasswriter.h"
#include "corerror.h"
#include "iceefilegen.h"
-#include "strongname.h"
#include "ceefilegenwriter.h"
#include "typekey.h"
//-----------------------------------------------------------------------------------------------------------
-#include "strongname.h"
#include "stdmacros.h"
#define POISONC ((UINT_PTR)((sizeof(int *) == 4)?0xCCCCCCCCL:I64(0xCCCCCCCCCCCCCCCC)))
return (CORINFO_ASSEMBLY_HANDLE) GetModule(module)->GetAssembly();
}
-
-#ifdef CROSSGEN_COMPILE
-//
-// Small wrapper to avoid having too many crossgen ifdefs
-//
-class AssemblyForLoadHint
-{
- IMDInternalImport * m_pMDImport;
-public:
- AssemblyForLoadHint(IMDInternalImport * pMDImport)
- : m_pMDImport(pMDImport)
- {
- }
-
- IMDInternalImport * GetManifestImport()
- {
- return m_pMDImport;
- }
-
- LPCSTR GetSimpleName()
- {
- LPCSTR name = "";
- IfFailThrow(m_pMDImport->GetAssemblyProps(TokenFromRid(1, mdtAssembly), NULL, NULL, NULL, &name, NULL, NULL));
- return name;
- }
-
- void GetDisplayName(SString &result, DWORD flags = 0)
- {
- PEAssembly::GetFullyQualifiedAssemblyName(m_pMDImport, TokenFromRid(1, mdtAssembly), result, flags);
- }
-
- BOOL IsSystem()
- {
- return FALSE;
- }
-};
-#endif
-
//-----------------------------------------------------------------------------
// For an assembly with a full name of "Foo, Version=2.0.0.0, Culture=neutral",
// we want any of these attributes specifications to match:
#include "holder.h"
#include "../binder/inc/assemblybinder.hpp"
+#include "strongnameinternal.h"
+#include "strongnameholders.h"
+
#ifdef FEATURE_PREJIT
#include "compile.h"
#endif
StrongNameBufferHolder<BYTE> pbToken;
// Try to get the strong name
- if (!StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
- m_cbPublicKeyOrToken,
- &pbToken,
- &cbToken))
- {
- // Throw an exception with details on what went wrong
- COMPlusThrowHR(StrongNameErrorInfo());
- }
+ IfFailThrow(StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken,
+ m_cbPublicKeyOrToken,
+ &pbToken,
+ &cbToken));
assemblyIdentity.m_publicKeyOrTokenBLOB.Set(pbToken, cbToken);
}
pThread->AddRef();
}
-#ifndef __GNUC__
-__declspec(thread)
-#else // !__GNUC__
-thread_local
-#endif // !__GNUC__
-EventPipeThreadHolder EventPipeThread::gCurrentEventPipeThreadHolder;
+thread_local EventPipeThreadHolder EventPipeThread::gCurrentEventPipeThreadHolder;
EventPipeThread::EventPipeThread()
{
void IncrementSequenceNumber();
};
-#ifndef __GNUC__
-#define EVENTPIPE_THREAD_LOCAL __declspec(thread)
-#else // !__GNUC__
-#define EVENTPIPE_THREAD_LOCAL thread_local
-#endif // !__GNUC__
-
class EventPipeThread
{
- static EVENTPIPE_THREAD_LOCAL EventPipeThreadHolder gCurrentEventPipeThreadHolder;
+ static thread_local EventPipeThreadHolder gCurrentEventPipeThreadHolder;
~EventPipeThread();
#include "gdbjit.h"
#include "gdbjithelpers.h"
-#ifndef __GNUC__
-__declspec(thread) bool tls_isSymReaderInProgress = false;
-#else // !__GNUC__
thread_local bool tls_isSymReaderInProgress = false;
-#endif // !__GNUC__
#ifdef _DEBUG
static void DumpElf(const char* methodName, const char *addr, size_t size)
#include "common.h"
#include "pefile.h"
-#include "strongname.h"
#include "eecontract.h"
#include "apithreadstress.h"
#include "eeconfig.h"
GetCodeBaseOrName(m_debugName);
m_debugName.Normalize();
m_pDebugName = m_debugName;
-
- AssemblySpec spec;
- spec.InitializeSpec(this);
-
- spec.GetFileOrDisplayName(ASM_DISPLAYF_VERSION |
- ASM_DISPLAYF_CULTURE |
- ASM_DISPLAYF_PUBLIC_KEY_TOKEN,
- m_sTextualIdentity);
#endif
}
//
// fCopiedName means to get the "shadow copied" path rather than the original path, if applicable
void GetCodeBase(SString &result, BOOL fCopiedName = FALSE);
- // Get the fully qualified assembly name from its metadata token
- static void GetFullyQualifiedAssemblyName(IMDInternalImport* pImport, mdAssembly mda, SString &result, DWORD flags = 0);
// Display name is the fusion binding name for an assembly
void GetDisplayName(SString &result, DWORD flags = 0);
// ------------------------------------------------------------
PTR_PEFile m_creator;
- // Using a separate entry and not m_pHostAssembly because otherwise
- // HasHostAssembly becomes true that trips various other code paths resulting in bad
- // things
- SString m_sTextualIdentity;
public:
PTR_PEFile GetCreator()
#ifndef PEFILE_INL_
#define PEFILE_INL_
-#include "strongname.h"
-#include "strongnameholders.h"
#include "check.h"
#include "simplerwlock.hpp"
#include "eventtrace.h"
}
#endif
- // Function to get the fully qualified name of an assembly
- inline void PEAssembly::GetFullyQualifiedAssemblyName(IMDInternalImport* pImport, mdAssembly mda, SString &result, DWORD flags)
-{
- CONTRACTL
- {
- PRECONDITION(CheckValue(result));
-#ifndef DACCESS_COMPILE
- THROWS;
-#else
- NOTHROW;
- #endif // !DACCESS_COMPILE
- GC_TRIGGERS;
- MODE_ANY;
- }
- CONTRACTL_END;
-
- if(pImport != NULL)
- {
- // This is for DAC, ONLY for the binding tool. Don't use for other
- // purposes, since this is not canonicalized through Fusion.
- LPCSTR name;
- AssemblyMetaDataInternal context;
- DWORD dwFlags;
- PBYTE pbPublicKey;
- DWORD cbPublicKey;
- if (FAILED(pImport->GetAssemblyProps(
- mda,
- (const void **) &pbPublicKey,
- &cbPublicKey,
- NULL,
- &name,
- &context,
- &dwFlags)))
- {
- _ASSERTE(!"If this fires, then we have to throw for corrupted images");
- result.SetUTF8("");
- return;
- }
-
- result.SetUTF8(name);
-
- result.AppendPrintf(W(", Version=%u.%u.%u.%u"),
- context.usMajorVersion, context.usMinorVersion,
- context.usBuildNumber, context.usRevisionNumber);
-
- result.Append(W(", Culture="));
- if (!*context.szLocale)
- {
- result.Append(W("neutral"));
- }
- else
- {
- result.AppendUTF8(context.szLocale);
- }
-
- if (cbPublicKey != 0)
- {
-#ifndef DACCESS_COMPILE
-
- StrongNameBufferHolder<BYTE> pbToken;
- DWORD cbToken;
- CQuickBytes qb;
-
- if (StrongNameTokenFromPublicKey(pbPublicKey, cbPublicKey,
- &pbToken, &cbToken))
- {
- // two hex digits per byte
- WCHAR* szToken = (WCHAR*) qb.AllocNoThrow(sizeof(WCHAR) * (cbToken*2+1));
- if (szToken)
- {
-#define TOHEX(a) ((a)>=10 ? L'a'+(a)-10 : L'0'+(a))
- UINT x;
- UINT y;
- for ( x = 0, y = 0; x < cbToken; ++x )
- {
- WCHAR v = static_cast<WCHAR>(pbToken[x] >> 4);
- szToken[y++] = TOHEX( v );
- v = static_cast<WCHAR>(pbToken[x] & 0x0F);
- szToken[y++] = TOHEX( v );
- }
- szToken[y] = L'\0';
-
- result.Append(W(", PublicKeyToken="));
- result.Append(szToken);
-#undef TOHEX
- }
- }
-#endif
-
- }
- else
- {
- result.Append(W(", PublicKeyToken=null"));
- }
-
- if (dwFlags & afPA_Mask)
- {
- result.Append(W(", ProcessorArchitecture="));
-
- if (dwFlags & afPA_MSIL)
- result.Append(W("MSIL"));
- else if (dwFlags & afPA_x86)
- result.Append(W("x86"));
- else if (dwFlags & afPA_IA64)
- result.Append(W("IA64"));
- else if (dwFlags & afPA_AMD64)
- result.Append(W("AMD64"));
- else if (dwFlags & afPA_ARM)
- result.Append(W("ARM"));
- }
- }
-}
-
// ------------------------------------------------------------
// Descriptive strings
CONTRACTL
{
PRECONDITION(CheckValue(result));
-#ifndef DACCESS_COMPILE
THROWS;
-#else
- NOTHROW;
-#endif // DACCESS_COMPILE
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;
#ifndef DACCESS_COMPILE
-
- if ((flags == (ASM_DISPLAYF_VERSION | ASM_DISPLAYF_CULTURE | ASM_DISPLAYF_PUBLIC_KEY_TOKEN)) &&
- !m_sTextualIdentity.IsEmpty())
- {
- result.Set(m_sTextualIdentity);
- }
- else
- {
- AssemblySpec spec;
- spec.InitializeSpec(this);
- spec.GetFileOrDisplayName(flags, result);
- }
-
+ AssemblySpec spec;
+ spec.InitializeSpec(this);
+ spec.GetFileOrDisplayName(flags, result);
#else
- IMDInternalImport *pImport = GetMDImport();
- GetFullyQualifiedAssemblyName(pImport, TokenFromRid(1, mdtAssembly), result, flags);
+ DacNotImpl();
#endif //DACCESS_COMPILE
}
#include "gcinfotypes.h"
#include "holder.h"
-#include "strongname.h"
#include "ex.h"
#include "corbbtprof.h"
#include "clrnt.h"