2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
6 // asmman.hpp - header file for manifest-related ILASM functions
12 #include "strongname.h"
13 #ifndef FEATURE_CORECLR
14 #include "LegacyActivationShim.h"
16 #include "specstrings.h"
25 CustomDescrList m_CustomDescrList;
34 if(szName) delete szName;
35 if(pHash) delete pHash;
37 int ComparedTo(AsmManFile* pX){ return strcmp(szName,pX->szName); }
39 //typedef SORTEDARRAY<AsmManFile> AsmManFileList;
40 typedef FIFO<AsmManFile> AsmManFileList;
52 BinStr* pPublicKeyToken;
53 ULONG ulHashAlgorithm;
57 // Security attributes
58 PermissionDecl* m_pPermissions;
59 PermissionSetDecl* m_pPermissionSets;
60 CustomDescrList m_CustomDescrList;
68 usVerMajor = usVerMinor = usBuild = usRevision = 0xFFFF;
69 szName = szAlias = NULL;
72 pPublicKey = pPublicKeyToken =pHashBlob = pLocale = NULL;
75 isAutodetect = isRef = FALSE;
80 if(szAlias && (szAlias != szName)) delete [] szAlias;
81 if(szName) delete [] szName;
82 if(pPublicKey) delete pPublicKey;
83 if(pPublicKeyToken) delete pPublicKeyToken;
84 if(pHashBlob) delete pHashBlob;
85 if(pLocale) delete pLocale;
87 int ComparedTo(AsmManAssembly* pX){ return strcmp(szAlias,pX->szAlias); }
89 //typedef SORTEDARRAY<AsmManAssembly> AsmManAssemblyList;
90 typedef FIFO<AsmManAssembly> AsmManAssemblyList;
103 CustomDescrList m_CustomDescrList;
106 szName = szFileName = szAsmRefName = szComTypeName = NULL;
112 if(szName) delete szName;
113 if(szFileName) delete szFileName;
115 int ComparedTo(AsmManComType* pX){ return strcmp(szName,pX->szName); };
117 //typedef SORTEDARRAY<AsmManComType> AsmManComTypeList;
118 typedef FIFO<AsmManComType> AsmManComTypeList;
130 CustomDescrList m_CustomDescrList;
132 AsmManRes() { szName = szAlias = szAsmRefName = szFileName = NULL; ulOffset = 0; tkTok = 0; dwAttr = 0; m_fNew = TRUE; };
135 if(szAlias && (szAlias != szName)) delete szAlias;
136 if(szName) delete szName;
137 if(szFileName) delete szFileName;
138 if(szAsmRefName) delete szAsmRefName;
141 typedef FIFO<AsmManRes> AsmManResList;
148 AsmManModRef() {szName = NULL; tkTok = 0; m_fNew = TRUE; };
149 ~AsmManModRef() { if(szName) delete szName; };
151 typedef FIFO<AsmManModRef> AsmManModRefList;
153 struct AsmManStrongName
162 BYTE *m_pbSignatureKey;
163 DWORD m_cbSignatureKey;
166 BYTE *m_pbPrivateKey;
167 DWORD m_cbPrivateKey;
168 WCHAR *m_wzKeyContainer;
171 // Where has the memory pointed to by m_pbPublicKey been taken from:
172 AllocationState m_dwPublicKeyAllocated;
174 AsmManStrongName() { ZeroMemory(this, sizeof(*this)); }
177 #ifndef FEATURE_CORECLR
178 if (m_dwPublicKeyAllocated == AllocatedBySNApi)
180 LegacyActivationShim::StrongNameFreeBuffer(m_pbPublicKey);
184 if (m_dwPublicKeyAllocated == AllocatedByNew)
185 delete [] m_pbPublicKey;
188 delete [] m_pbPrivateKey;
190 if (m_pbSignatureKey)
191 delete [] m_pbSignatureKey;
199 AsmManFileList m_FileLst;
200 AsmManComTypeList m_ComTypeLst;
201 AsmManResList m_ManResLst;
202 AsmManModRefList m_ModRefLst;
204 AsmManComType* m_pCurComType;
205 AsmManRes* m_pCurManRes;
206 ErrorReporter* report;
209 AsmManFile* GetFileByName(__in __nullterminated char* szFileName);
210 AsmManAssembly* GetAsmRefByName(__in __nullterminated const char* szAsmRefName);
211 AsmManComType* GetComTypeByName(__in_opt __nullterminated char* szComTypeName,
212 __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
213 mdToken GetComTypeTokByName(__in_opt __nullterminated char* szComTypeName,
214 __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
216 IMetaDataEmit* m_pEmitter;
219 IMetaDataAssemblyEmit* m_pAsmEmitter;
220 AsmManAssemblyList m_AsmRefLst;
221 AsmManAssembly* m_pAssembly;
222 AsmManAssembly* m_pCurAsmRef;
225 AsmManStrongName m_sStrongName;
226 // Embedded manifest resources paraphernalia:
227 WCHAR* m_wzMResName[MAX_MANIFEST_RESOURCES];
228 DWORD m_dwMResSize[MAX_MANIFEST_RESOURCES];
229 BOOL m_fMResNew[MAX_MANIFEST_RESOURCES];
231 DWORD m_dwMResSizeTotal;
232 AsmMan() { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAsmEmitter = NULL;
233 memset(m_wzMResName,0,sizeof(m_wzMResName));
234 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
235 m_dwMResNum = m_dwMResSizeTotal = 0; };
236 AsmMan(void* pAsm) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAssembler = pAsm; m_pAsmEmitter = NULL;
237 memset(m_wzMResName,0,sizeof(m_wzMResName));
238 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
239 m_dwMResNum = m_dwMResSizeTotal = 0; };
240 AsmMan(ErrorReporter* rpt) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; report = rpt; m_pAsmEmitter = NULL;
241 memset(m_wzMResName,0,sizeof(m_wzMResName));
242 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
243 m_dwMResNum = m_dwMResSizeTotal = 0; };
246 if(m_pAssembly) delete m_pAssembly;
247 if(m_szScopeName) delete m_szScopeName;
248 if(m_pGUID) delete m_pGUID;
250 void SetErrorReporter(ErrorReporter* rpt) { report = rpt; };
251 HRESULT EmitManifest(void);
253 void SetEmitter( IMetaDataEmit* pEmitter) { m_pEmitter = pEmitter; };
255 void SetModuleName(__inout_opt __nullterminated char* szName);
257 void AddFile(__in __nullterminated char* szName, DWORD dwAttr, BinStr* pHashBlob);
259 void EmitDebuggableAttribute(mdToken tkOwner);
261 void StartAssembly(__in __nullterminated char* szName, __in_opt __nullterminated char* szAlias, DWORD dwAttr, BOOL isRef);
263 void EmitAssemblyRefs();
265 void SetAssemblyPublicKey(BinStr* pPublicKey);
266 void SetAssemblyPublicKeyToken(BinStr* pPublicKeyToken);
267 void SetAssemblyHashAlg(ULONG ulAlgID);
268 void SetAssemblyVer(USHORT usMajor, USHORT usMinor, USHORT usBuild, USHORT usRevision);
269 void SetAssemblyLocale(BinStr* pLocale, BOOL bConvertToUnicode);
270 void SetAssemblyHashBlob(BinStr* pHashBlob);
271 void SetAssemblyAutodetect();
273 void StartComType(__in __nullterminated char* szName, DWORD dwAttr);
275 void SetComTypeFile(__in __nullterminated char* szFileName);
276 void SetComTypeAsmRef(__in __nullterminated char* szAsmRefName);
277 void SetComTypeComType(__in __nullterminated char* szComTypeName);
278 BOOL SetComTypeImplementationTok(mdToken tk);
279 BOOL SetComTypeClassTok(mdToken tkClass);
281 void StartManifestRes(__in __nullterminated char* szName, __in __nullterminated char* szAlias, DWORD dwAttr);
282 void EndManifestRes();
283 void SetManifestResFile(__in __nullterminated char* szFileName, ULONG ulOffset);
284 void SetManifestResAsmRef(__in __nullterminated char* szAsmRefName);
286 mdToken GetFileTokByName(__in __nullterminated char* szFileName);
287 mdToken GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName);
288 mdToken GetAsmTokByName(__in __nullterminated const char* szAsmName)
289 { return (m_pAssembly && (strcmp(m_pAssembly->szName,szAsmName)==0)) ? m_pAssembly->tkTok : 0; };
291 mdToken GetModuleRefTokByName(__in __nullterminated char* szName)
293 if(szName && *szName)
296 for(unsigned i=0; (pMR=m_ModRefLst.PEEK(i)); i++)
298 if(!strcmp(szName, pMR->szName)) return pMR->tkTok;