diff options
author | Michelle McDaniel <adiaaida@gmail.com> | 2017-02-13 11:00:58 -0800 |
---|---|---|
committer | Michelle McDaniel <adiaaida@gmail.com> | 2017-02-15 09:56:30 -0800 |
commit | 51f460f2e24765bf78ab9edac55895be6487cf18 (patch) | |
tree | 4e7bc886f69f16e9963dc1d14685155578d92d3b /src/ilasm/writer.cpp | |
parent | 6185a8801d3d4402b3afb728856aa62b86dadb4a (diff) | |
download | coreclr-51f460f2e24765bf78ab9edac55895be6487cf18.tar.gz coreclr-51f460f2e24765bf78ab9edac55895be6487cf18.tar.bz2 coreclr-51f460f2e24765bf78ab9edac55895be6487cf18.zip |
Enable delay signing in ilasm
Corefx needs the .Net Core version of ilasm to create delay signable
assemblies. This change brings back AllocateStrongNameSignature that was
deleted in 2efbb92 and modifies it to use similar logic from Roslyn to
determine the size of the signature that we need to allocate space for.
Fixes #9292.
Diffstat (limited to 'src/ilasm/writer.cpp')
-rw-r--r-- | src/ilasm/writer.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp index 85f29af5e7..624c474bde 100644 --- a/src/ilasm/writer.cpp +++ b/src/ilasm/writer.cpp @@ -982,6 +982,62 @@ BOOL Assembler::EmitEventsProps(Class* pClass) return ret; } +HRESULT Assembler::AllocateStrongNameSignature() +{ + HRESULT hr = S_OK; + HCEESECTION hSection; + DWORD dwDataLength; + DWORD dwDataOffset; + DWORD dwDataRVA; + VOID *pvBuffer; + AsmManStrongName *pSN = &m_pManifest->m_sStrongName; + + // pSN->m_cbPublicKey is the length of the m_pbPublicKey + dwDataLength = ((int)pSN->m_cbPublicKey < 128 + 32) ? 128 : (int)pSN->m_cbPublicKey - 32; + + // Grab memory in the section for our stuff. + if (FAILED(hr = m_pCeeFileGen->GetIlSection(m_pCeeFile, + &hSection))) + { + return hr; + } + + if (FAILED(hr = m_pCeeFileGen->GetSectionBlock(hSection, + dwDataLength, + 4, + &pvBuffer))) + { + return hr; + } + + // Where did we get that memory? + if (FAILED(hr = m_pCeeFileGen->GetSectionDataLen(hSection, + &dwDataOffset))) + { + return hr; + } + + dwDataOffset -= dwDataLength; + + // Convert to an RVA. + if (FAILED(hr = m_pCeeFileGen->GetMethodRVA(m_pCeeFile, + dwDataOffset, + &dwDataRVA))) + { + return hr; + } + + // Emit the directory entry. + if (FAILED(hr = m_pCeeFileGen->SetStrongNameEntry(m_pCeeFile, + dwDataLength, + dwDataRVA))) + { + return hr; + } + + return S_OK; +} + #ifdef _PREFAST_ #pragma warning(push) #pragma warning(disable:21000) // Suppress PREFast warning about overly large function @@ -1008,6 +1064,15 @@ HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename) if(bClock) bClock->cMDEmit1 = GetTickCount(); + // Allocate space for a strong name signature if we're delay or full + // signing the assembly. + if (m_pManifest->m_sStrongName.m_pbPublicKey) + { + if (FAILED(hr = AllocateStrongNameSignature())) + { + goto exit; + } + } if(bClock) bClock->cMDEmit2 = GetTickCount(); |