1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 // asmman.hpp - header file for manifest-related ILASM functions
11 #include "strongname.h"
12 #include "specstrings.h"
21 CustomDescrList m_CustomDescrList;
30 if(szName) delete szName;
31 if(pHash) delete pHash;
33 int ComparedTo(AsmManFile* pX){ return strcmp(szName,pX->szName); }
35 //typedef SORTEDARRAY<AsmManFile> AsmManFileList;
36 typedef FIFO<AsmManFile> AsmManFileList;
48 BinStr* pPublicKeyToken;
49 ULONG ulHashAlgorithm;
53 // Security attributes
54 PermissionDecl* m_pPermissions;
55 PermissionSetDecl* m_pPermissionSets;
56 CustomDescrList m_CustomDescrList;
64 usVerMajor = usVerMinor = usBuild = usRevision = 0xFFFF;
65 szName = szAlias = NULL;
68 pPublicKey = pPublicKeyToken =pHashBlob = pLocale = NULL;
71 isAutodetect = isRef = FALSE;
76 if(szAlias && (szAlias != szName)) delete [] szAlias;
77 if(szName) delete [] szName;
78 if(pPublicKey) delete pPublicKey;
79 if(pPublicKeyToken) delete pPublicKeyToken;
80 if(pHashBlob) delete pHashBlob;
81 if(pLocale) delete pLocale;
83 int ComparedTo(AsmManAssembly* pX){ return strcmp(szAlias,pX->szAlias); }
85 //typedef SORTEDARRAY<AsmManAssembly> AsmManAssemblyList;
86 typedef FIFO<AsmManAssembly> AsmManAssemblyList;
99 CustomDescrList m_CustomDescrList;
102 szName = szFileName = szAsmRefName = szComTypeName = NULL;
108 if(szName) delete szName;
109 if(szFileName) delete szFileName;
111 int ComparedTo(AsmManComType* pX){ return strcmp(szName,pX->szName); };
113 //typedef SORTEDARRAY<AsmManComType> AsmManComTypeList;
114 typedef FIFO<AsmManComType> AsmManComTypeList;
126 CustomDescrList m_CustomDescrList;
128 AsmManRes() { szName = szAlias = szAsmRefName = szFileName = NULL; ulOffset = 0; tkTok = 0; dwAttr = 0; m_fNew = TRUE; };
131 if(szAlias && (szAlias != szName)) delete szAlias;
132 if(szName) delete szName;
133 if(szFileName) delete szFileName;
134 if(szAsmRefName) delete szAsmRefName;
137 typedef FIFO<AsmManRes> AsmManResList;
144 AsmManModRef() {szName = NULL; tkTok = 0; m_fNew = TRUE; };
145 ~AsmManModRef() { if(szName) delete szName; };
147 typedef FIFO<AsmManModRef> AsmManModRefList;
149 struct AsmManStrongName
158 BYTE *m_pbSignatureKey;
159 DWORD m_cbSignatureKey;
162 BYTE *m_pbPrivateKey;
163 DWORD m_cbPrivateKey;
164 WCHAR *m_wzKeyContainer;
167 // Where has the memory pointed to by m_pbPublicKey been taken from:
168 AllocationState m_dwPublicKeyAllocated;
170 AsmManStrongName() { ZeroMemory(this, sizeof(*this)); }
173 if (m_dwPublicKeyAllocated == AllocatedByNew)
174 delete [] m_pbPublicKey;
177 delete [] m_pbPrivateKey;
179 if (m_pbSignatureKey)
180 delete [] m_pbSignatureKey;
188 AsmManFileList m_FileLst;
189 AsmManComTypeList m_ComTypeLst;
190 AsmManResList m_ManResLst;
191 AsmManModRefList m_ModRefLst;
193 AsmManComType* m_pCurComType;
194 AsmManRes* m_pCurManRes;
195 ErrorReporter* report;
198 AsmManFile* GetFileByName(__in __nullterminated char* szFileName);
199 AsmManAssembly* GetAsmRefByName(__in __nullterminated const char* szAsmRefName);
200 AsmManComType* GetComTypeByName(__in_opt __nullterminated char* szComTypeName,
201 __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
202 mdToken GetComTypeTokByName(__in_opt __nullterminated char* szComTypeName,
203 __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
205 IMetaDataEmit* m_pEmitter;
208 IMetaDataAssemblyEmit* m_pAsmEmitter;
209 AsmManAssemblyList m_AsmRefLst;
210 AsmManAssembly* m_pAssembly;
211 AsmManAssembly* m_pCurAsmRef;
214 AsmManStrongName m_sStrongName;
215 // Embedded manifest resources paraphernalia:
216 WCHAR* m_wzMResName[MAX_MANIFEST_RESOURCES];
217 DWORD m_dwMResSize[MAX_MANIFEST_RESOURCES];
218 BOOL m_fMResNew[MAX_MANIFEST_RESOURCES];
220 DWORD m_dwMResSizeTotal;
221 AsmMan() { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAsmEmitter = NULL;
222 memset(m_wzMResName,0,sizeof(m_wzMResName));
223 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
224 m_dwMResNum = m_dwMResSizeTotal = 0; };
225 AsmMan(void* pAsm) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAssembler = pAsm; m_pAsmEmitter = NULL;
226 memset(m_wzMResName,0,sizeof(m_wzMResName));
227 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
228 m_dwMResNum = m_dwMResSizeTotal = 0; };
229 AsmMan(ErrorReporter* rpt) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; report = rpt; m_pAsmEmitter = NULL;
230 memset(m_wzMResName,0,sizeof(m_wzMResName));
231 memset(m_dwMResSize,0,sizeof(m_dwMResSize));
232 m_dwMResNum = m_dwMResSizeTotal = 0; };
235 if(m_pAssembly) delete m_pAssembly;
236 if(m_szScopeName) delete m_szScopeName;
237 if(m_pGUID) delete m_pGUID;
239 void SetErrorReporter(ErrorReporter* rpt) { report = rpt; };
240 HRESULT EmitManifest(void);
242 void SetEmitter( IMetaDataEmit* pEmitter) { m_pEmitter = pEmitter; };
244 void SetModuleName(__inout_opt __nullterminated char* szName);
246 void AddFile(__in __nullterminated char* szName, DWORD dwAttr, BinStr* pHashBlob);
248 void EmitDebuggableAttribute(mdToken tkOwner);
250 void StartAssembly(__in __nullterminated char* szName, __in_opt __nullterminated char* szAlias, DWORD dwAttr, BOOL isRef);
252 void EmitAssemblyRefs();
254 void SetAssemblyPublicKey(BinStr* pPublicKey);
255 void SetAssemblyPublicKeyToken(BinStr* pPublicKeyToken);
256 void SetAssemblyHashAlg(ULONG ulAlgID);
257 void SetAssemblyVer(USHORT usMajor, USHORT usMinor, USHORT usBuild, USHORT usRevision);
258 void SetAssemblyLocale(BinStr* pLocale, BOOL bConvertToUnicode);
259 void SetAssemblyHashBlob(BinStr* pHashBlob);
260 void SetAssemblyAutodetect();
262 void StartComType(__in __nullterminated char* szName, DWORD dwAttr);
264 void SetComTypeFile(__in __nullterminated char* szFileName);
265 void SetComTypeAsmRef(__in __nullterminated char* szAsmRefName);
266 void SetComTypeComType(__in __nullterminated char* szComTypeName);
267 BOOL SetComTypeImplementationTok(mdToken tk);
268 BOOL SetComTypeClassTok(mdToken tkClass);
270 void StartManifestRes(__in __nullterminated char* szName, __in __nullterminated char* szAlias, DWORD dwAttr);
271 void EndManifestRes();
272 void SetManifestResFile(__in __nullterminated char* szFileName, ULONG ulOffset);
273 void SetManifestResAsmRef(__in __nullterminated char* szAsmRefName);
275 AsmManAssembly* GetAsmRefByAsmName(__in __nullterminated const char* szAsmName);
277 mdToken GetFileTokByName(__in __nullterminated char* szFileName);
278 mdToken GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName);
279 mdToken GetAsmTokByName(__in __nullterminated const char* szAsmName)
280 { return (m_pAssembly && (strcmp(m_pAssembly->szName,szAsmName)==0)) ? m_pAssembly->tkTok : 0; };
282 mdToken GetModuleRefTokByName(__in __nullterminated char* szName)
284 if(szName && *szName)
287 for(unsigned i=0; (pMR=m_ModRefLst.PEEK(i)); i++)
289 if(!strcmp(szName, pMR->szName)) return pMR->tkTok;