23 private class AssemblyBuilderLock
27 internal AssemblyBuilderData m_assemblyData;
29 private InternalAssemblyBuilder m_internalAssemblyBuilder;
33 private bool m_fManifestModuleUsedAsDefinedModule;
35 internal const string MANIFEST_MODULE_NAME =
"RefEmit_InMemoryManifestModule";
39 private bool m_profileAPICheck;
41 internal object SyncRoot => InternalAssembly.SyncRoot;
43 internal InternalAssemblyBuilder InternalAssembly => m_internalAssemblyBuilder;
45 internal bool ProfileAPICheck => m_profileAPICheck;
51 public override string Location => InternalAssembly.Location;
62 public override string CodeBase => InternalAssembly.CodeBase;
71 public override string FullName => InternalAssembly.FullName;
84 return InternalAssembly.PermissionSet;
115 private static extern RuntimeModule GetInMemoryAssemblyModule(RuntimeAssembly assembly);
118 private Module nGetInMemoryAssemblyModule()
120 return GetInMemoryAssemblyModule(GetNativeHandle());
125 private static extern RuntimeModule GetOnDiskAssemblyModule(RuntimeAssembly assembly);
130 if (m_onDiskAssemblyModuleBuilder ==
null)
132 Module onDiskAssemblyModule = GetOnDiskAssemblyModule(InternalAssembly.GetNativeHandle());
134 moduleBuilder.Init(
"RefEmit_OnDiskManifestModule",
null, 0);
135 m_onDiskAssemblyModuleBuilder = moduleBuilder;
137 return m_onDiskAssemblyModuleBuilder;
140 internal ModuleBuilder GetModuleBuilder(InternalModuleBuilder module)
144 foreach (ModuleBuilder moduleBuilder
in m_assemblyData.m_moduleBuilderList)
146 if (moduleBuilder.InternalModule == module)
148 return moduleBuilder;
151 if (m_onDiskAssemblyModuleBuilder !=
null && m_onDiskAssemblyModuleBuilder.InternalModule == module)
153 return m_onDiskAssemblyModuleBuilder;
155 if (!(m_manifestModuleBuilder.InternalModule == module))
157 throw new ArgumentException(
"module");
159 return m_manifestModuleBuilder;
163 internal RuntimeAssembly GetNativeHandle()
165 return InternalAssembly.GetNativeHandle();
169 internal Version GetVersion()
171 return InternalAssembly.GetVersion();
175 internal AssemblyBuilder(AppDomain domain, AssemblyName name,
AssemblyBuilderAccess access,
string dir,
Evidence evidence,
PermissionSet requiredPermissions,
PermissionSet optionalPermissions,
PermissionSet refusedPermissions, ref StackCrawlMark stackMark,
IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes,
SecurityContextSource securityContextSource)
179 throw new ArgumentNullException(
"name");
183 throw new ArgumentException(Environment.GetResourceString(
"Arg_EnumIllegalVal", (
int)access),
"access");
185 if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource >
SecurityContextSource.CurrentAssembly)
187 throw new ArgumentOutOfRangeException(
"securityContextSource");
189 name = (AssemblyName)name.Clone();
190 if (name.KeyPair !=
null)
192 name.SetPublicKey(name.KeyPair.PublicKey);
194 if (evidence !=
null)
203 DynamicAssemblyFlags dynamicAssemblyFlags = DynamicAssemblyFlags.None;
205 byte[] array2 =
null;
206 if (unsafeAssemblyAttributes !=
null)
209 foreach (CustomAttributeBuilder item
in list)
213 dynamicAssemblyFlags |= DynamicAssemblyFlags.Transparent;
218 if (item.m_constructorArgs !=
null && item.m_constructorArgs.Length == 1 && item.m_constructorArgs[0] is
SecurityCriticalScope)
222 dynamicAssemblyFlags |= DynamicAssemblyFlags.Critical;
225 dynamicAssemblyFlags |= DynamicAssemblyFlags.AllCritical;
230 array =
new byte[item.m_blob.Length];
231 Array.Copy(item.m_blob, array, array.Length);
235 dynamicAssemblyFlags |= DynamicAssemblyFlags.TreatAsSafe;
239 dynamicAssemblyFlags |= DynamicAssemblyFlags.Aptca;
240 array2 =
new byte[item.m_blob.Length];
241 Array.Copy(item.m_blob, array2, array2.Length);
245 m_internalAssemblyBuilder = (InternalAssemblyBuilder)nCreateDynamicAssembly(domain, name, evidence, ref stackMark, requiredPermissions, optionalPermissions, refusedPermissions, array, array2, access, dynamicAssemblyFlags, securityContextSource);
246 m_assemblyData =
new AssemblyBuilderData(m_internalAssemblyBuilder, name.Name, access, dir);
247 m_assemblyData.AddPermissionRequests(requiredPermissions, optionalPermissions, refusedPermissions);
250 RuntimeAssembly executingAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
251 if (executingAssembly !=
null && !executingAssembly.IsFrameworkAssembly())
253 m_profileAPICheck =
true;
256 InitManifestModule();
259 foreach (CustomAttributeBuilder item2
in list)
267 private void InitManifestModule()
269 InternalModuleBuilder internalModuleBuilder = (InternalModuleBuilder)nGetInMemoryAssemblyModule();
270 m_manifestModuleBuilder =
new ModuleBuilder(
this, internalModuleBuilder);
271 m_manifestModuleBuilder.Init(
"RefEmit_InMemoryManifestModule",
null, 0);
272 m_fManifestModuleUsedAsDefinedModule =
false;
280 [SecuritySafeCritical]
283 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
284 return InternalDefineDynamicAssembly(name, access,
null,
null,
null,
null,
null, ref stackMark,
null,
SecurityContextSource.CurrentAssembly);
293 [SecuritySafeCritical]
296 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
297 return InternalDefineDynamicAssembly(name, access,
null,
null,
null,
null,
null, ref stackMark, assemblyAttributes,
SecurityContextSource.CurrentAssembly);
302 private static extern Assembly nCreateDynamicAssembly(
AppDomain domain,
AssemblyName name,
Evidence identity, ref StackCrawlMark stackMark,
PermissionSet requiredPermissions,
PermissionSet optionalPermissions,
PermissionSet refusedPermissions,
byte[] securityRulesBlob,
byte[] aptcaBlob,
AssemblyBuilderAccess access, DynamicAssemblyFlags flags,
SecurityContextSource securityContextSource);
311 lock (typeof(AssemblyBuilderLock))
313 return new AssemblyBuilder(
AppDomain.
CurrentDomain, name, access, dir, evidence, requiredPermissions, optionalPermissions, refusedPermissions, ref stackMark, unsafeAssemblyAttributes, securityContextSource);
327 [SecuritySafeCritical]
330 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
331 return DefineDynamicModuleInternal(name, emitSymbolInfo:
false, ref stackMark);
346 [SecuritySafeCritical]
349 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
350 return DefineDynamicModuleInternal(name, emitSymbolInfo, ref stackMark);
354 private ModuleBuilder DefineDynamicModuleInternal(
string name,
bool emitSymbolInfo, ref StackCrawlMark stackMark)
358 return DefineDynamicModuleInternalNoLock(name, emitSymbolInfo, ref stackMark);
363 private ModuleBuilder DefineDynamicModuleInternalNoLock(
string name,
bool emitSymbolInfo, ref StackCrawlMark stackMark)
369 if (name.Length == 0)
371 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyName"),
"name");
375 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidName"),
"name");
378 IntPtr pInternalSymWriter =
default(IntPtr);
379 m_assemblyData.CheckNameConflict(name);
380 ModuleBuilder moduleBuilder;
381 if (m_fManifestModuleUsedAsDefinedModule)
384 InternalModuleBuilder internalModuleBuilder = (InternalModuleBuilder)
DefineDynamicModule(InternalAssembly, emitSymbolInfo, name, name, ref stackMark, ref pInternalSymWriter, fIsTransient:
true, out tkFile);
385 moduleBuilder =
new ModuleBuilder(
this, internalModuleBuilder);
386 moduleBuilder.Init(name,
null, tkFile);
390 m_manifestModuleBuilder.ModifyModuleName(name);
391 moduleBuilder = m_manifestModuleBuilder;
394 pInternalSymWriter = ModuleBuilder.nCreateISymWriterForDynamicModule(moduleBuilder.InternalModule, name);
399 Assembly assembly = LoadISymWrapper();
400 Type type = assembly.GetType(
"System.Diagnostics.SymbolStore.SymWriter", throwOnError:
true, ignoreCase:
false);
401 if (type !=
null && !type.IsVisible)
407 throw new TypeLoadException(Environment.GetResourceString(
"MissingType",
"SymWriter"));
413 symbolWriter = (
ISymbolWriter)Activator.CreateInstance(type);
421 moduleBuilder.SetSymWriter(symbolWriter);
422 m_assemblyData.AddModule(moduleBuilder);
423 if (moduleBuilder == m_manifestModuleBuilder)
425 m_fManifestModuleUsedAsDefinedModule =
true;
427 return moduleBuilder;
443 [SecuritySafeCritical]
446 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
447 return DefineDynamicModuleInternal(name, fileName, emitSymbolInfo:
false, ref stackMark);
464 [SecuritySafeCritical]
467 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
468 return DefineDynamicModuleInternal(name, fileName, emitSymbolInfo, ref stackMark);
472 private ModuleBuilder DefineDynamicModuleInternal(
string name,
string fileName,
bool emitSymbolInfo, ref StackCrawlMark stackMark)
476 return DefineDynamicModuleInternalNoLock(name, fileName, emitSymbolInfo, ref stackMark);
481 private ModuleBuilder DefineDynamicModuleInternalNoLock(
string name,
string fileName,
bool emitSymbolInfo, ref StackCrawlMark stackMark)
487 if (name.Length == 0)
489 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyName"),
"name");
493 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidName"),
"name");
495 if (fileName ==
null)
497 throw new ArgumentNullException(
"fileName");
499 if (fileName.Length == 0)
501 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"fileName");
505 throw new ArgumentException(Environment.GetResourceString(
"Argument_NotSimpleFileName"),
"fileName");
509 throw new NotSupportedException(Environment.GetResourceString(
"Argument_BadPersistableModuleInTransientAssembly"));
511 if (m_assemblyData.m_isSaved)
513 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_CannotAlterAssembly"));
516 IntPtr pInternalSymWriter =
default(IntPtr);
517 m_assemblyData.CheckNameConflict(name);
518 m_assemblyData.CheckFileNameConflict(fileName);
520 InternalModuleBuilder internalModuleBuilder = (InternalModuleBuilder)
DefineDynamicModule(InternalAssembly, emitSymbolInfo, name, fileName, ref stackMark, ref pInternalSymWriter, fIsTransient:
false, out tkFile);
521 ModuleBuilder moduleBuilder =
new ModuleBuilder(
this, internalModuleBuilder);
522 moduleBuilder.Init(name, fileName, tkFile);
525 Assembly assembly = LoadISymWrapper();
526 Type type = assembly.GetType(
"System.Diagnostics.SymbolStore.SymWriter", throwOnError:
true, ignoreCase:
false);
527 if (type !=
null && !type.IsVisible)
533 throw new TypeLoadException(Environment.GetResourceString(
"MissingType",
"SymWriter"));
538 symbolWriter = (
ISymbolWriter)Activator.CreateInstance(type);
546 moduleBuilder.SetSymWriter(symbolWriter);
547 m_assemblyData.AddModule(moduleBuilder);
548 return moduleBuilder;
553 if (m_assemblyData.m_ISymWrapperAssembly !=
null)
555 return m_assemblyData.m_ISymWrapperAssembly;
557 Assembly assembly =
Assembly.Load(
"ISymWrapper, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
558 m_assemblyData.m_ISymWrapperAssembly = assembly;
562 internal void CheckContext(params Type[][] typess)
568 foreach (Type[] array
in typess)
577 internal void CheckContext(params Type[] types)
587 if (num >= types.Length)
594 if (type.Module ==
null || type.Module.Assembly ==
null)
596 throw new ArgumentException(Environment.GetResourceString(
"Argument_TypeNotValid"));
598 if (!(type.Module.Assembly == typeof(
object).
Module.Assembly))
602 throw new InvalidOperationException(Environment.GetResourceString(
"Arugment_EmitMixedContext1", type.AssemblyQualifiedName));
612 throw new InvalidOperationException(Environment.GetResourceString(
"Arugment_EmitMixedContext2", type.AssemblyQualifiedName));
647 return DefineResourceNoLock(name, description, fileName, attribute);
657 if (name.Length == 0)
661 if (fileName ==
null)
665 if (fileName.Length == 0)
667 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"),
"fileName");
671 throw new ArgumentException(Environment.GetResourceString(
"Argument_NotSimpleFileName"),
"fileName");
673 m_assemblyData.CheckResNameConflict(name);
674 m_assemblyData.CheckFileNameConflict(fileName);
677 if (m_assemblyData.m_strDir ==
null)
679 text =
Path.
Combine(Environment.CurrentDirectory, fileName);
684 text =
Path.
Combine(m_assemblyData.m_strDir, fileName);
689 m_assemblyData.AddResWriter(
new ResWriterData(resourceWriter,
null, name, fileName, text, attribute));
690 return resourceWriter;
722 AddResourceFileNoLock(name, fileName, attribute);
726 [SecuritySafeCritical]
727 private void AddResourceFileNoLock(
string name,
string fileName,
ResourceAttributes attribute)
733 if (name.Length == 0)
737 if (fileName ==
null)
741 if (fileName.Length == 0)
743 throw new ArgumentException(Environment.GetResourceString(
"Argument_EmptyFileName"), fileName);
747 throw new ArgumentException(Environment.GetResourceString(
"Argument_NotSimpleFileName"),
"fileName");
749 m_assemblyData.CheckResNameConflict(name);
750 m_assemblyData.CheckFileNameConflict(fileName);
751 string path = (m_assemblyData.m_strDir !=
null) ?
Path.
Combine(m_assemblyData.m_strDir, fileName) :
Path.
Combine(Environment.CurrentDirectory, fileName);
752 path =
Path.UnsafeGetFullPath(path);
754 if (!
File.UnsafeExists(path))
756 throw new FileNotFoundException(Environment.GetResourceString(
"IO.FileNotFound_FileName", fileName), fileName);
758 m_assemblyData.AddResWriter(
new ResWriterData(
null,
null, name, fileName, path, attribute));
767 return InternalAssembly.Equals(obj);
774 return InternalAssembly.GetHashCode();
782 return InternalAssembly.GetCustomAttributes(inherit);
795 return InternalAssembly.GetCustomAttributes(attributeType, inherit);
805 return InternalAssembly.IsDefined(attributeType, inherit);
812 return InternalAssembly.GetCustomAttributesData();
821 return InternalAssembly.GetManifestResourceNames();
831 return InternalAssembly.GetFile(name);
842 return InternalAssembly.GetFiles(getResourceModules);
853 return InternalAssembly.GetManifestResourceStream(type, name);
863 return InternalAssembly.GetManifestResourceStream(name);
874 return InternalAssembly.GetManifestResourceInfo(resourceName);
883 return InternalAssembly.GetExportedTypes();
892 return InternalAssembly.GetName(copiedName);
902 public override Type GetType(
string name,
bool throwOnError,
bool ignoreCase)
904 return InternalAssembly.
GetType(name, throwOnError, ignoreCase);
912 return InternalAssembly.GetModule(name);
919 return InternalAssembly.GetReferencedAssemblies();
928 return InternalAssembly.GetModules(getResourceModules);
937 return InternalAssembly.GetLoadedModules(getResourceModules);
951 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
952 return InternalAssembly.InternalGetSatelliteAssembly(culture,
null, ref stackMark);
967 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
968 return InternalAssembly.InternalGetSatelliteAssembly(culture, version, ref stackMark);
983 DefineVersionInfoResourceNoLock(product, productVersion, company, copyright, trademark);
987 private void DefineVersionInfoResourceNoLock(
string product,
string productVersion,
string company,
string copyright,
string trademark)
989 if (m_assemblyData.m_strResourceFileName !=
null || m_assemblyData.m_resourceBytes !=
null || m_assemblyData.m_nativeVersion !=
null)
993 m_assemblyData.m_nativeVersion =
new NativeVersionInfo();
994 m_assemblyData.m_nativeVersion.m_strCopyright = copyright;
995 m_assemblyData.m_nativeVersion.m_strTrademark = trademark;
996 m_assemblyData.m_nativeVersion.m_strCompany = company;
997 m_assemblyData.m_nativeVersion.m_strProduct = product;
998 m_assemblyData.m_nativeVersion.m_strProductVersion = productVersion;
999 m_assemblyData.m_hasUnmanagedVersionInfo =
true;
1000 m_assemblyData.m_OverrideUnmanagedVersionInfo =
true;
1010 DefineVersionInfoResourceNoLock();
1014 private void DefineVersionInfoResourceNoLock()
1016 if (m_assemblyData.m_strResourceFileName !=
null || m_assemblyData.m_resourceBytes !=
null || m_assemblyData.m_nativeVersion !=
null)
1020 m_assemblyData.m_hasUnmanagedVersionInfo =
true;
1021 m_assemblyData.m_nativeVersion =
new NativeVersionInfo();
1032 if (resource ==
null)
1038 DefineUnmanagedResourceNoLock(resource);
1042 private void DefineUnmanagedResourceNoLock(
byte[] resource)
1044 if (m_assemblyData.m_strResourceFileName !=
null || m_assemblyData.m_resourceBytes !=
null || m_assemblyData.m_nativeVersion !=
null)
1048 m_assemblyData.m_resourceBytes =
new byte[resource.Length];
1049 Array.
Copy(resource, m_assemblyData.m_resourceBytes, resource.Length);
1062 [SecuritySafeCritical]
1065 if (resourceFileName ==
null)
1071 DefineUnmanagedResourceNoLock(resourceFileName);
1076 private void DefineUnmanagedResourceNoLock(
string resourceFileName)
1078 if (m_assemblyData.m_strResourceFileName !=
null || m_assemblyData.m_resourceBytes !=
null || m_assemblyData.m_nativeVersion !=
null)
1083 if (m_assemblyData.m_strDir ==
null)
1089 text =
Path.
Combine(m_assemblyData.m_strDir, resourceFileName);
1095 throw new FileNotFoundException(Environment.GetResourceString(
"IO.FileNotFound_FileName", resourceFileName), resourceFileName);
1097 m_assemblyData.m_strResourceFileName = text;
1111 return GetDynamicModuleNoLock(name);
1121 if (name.Length == 0)
1125 int count = m_assemblyData.m_moduleBuilderList.Count;
1126 for (
int i = 0; i < count; i++)
1128 ModuleBuilder moduleBuilder = m_assemblyData.m_moduleBuilderList[i];
1129 if (moduleBuilder.m_moduleData.m_strModuleName.Equals(name))
1131 return moduleBuilder;
1161 SetEntryPointNoLock(entryMethod, fileKind);
1167 if (entryMethod ==
null)
1172 if (module ==
null || !InternalAssembly.Equals(module.
Assembly))
1176 m_assemblyData.m_entryPointMethod = entryMethod;
1177 m_assemblyData.m_peFileKind = fileKind;
1178 ModuleBuilder moduleBuilder = module as ModuleBuilder;
1179 if (moduleBuilder !=
null)
1181 m_assemblyData.m_entryPointModule = moduleBuilder;
1185 m_assemblyData.m_entryPointModule = GetModuleBuilder((InternalModuleBuilder)module);
1187 MethodToken methodToken = m_assemblyData.m_entryPointModule.GetMethodToken(entryMethod);
1188 m_assemblyData.m_entryPointModule.SetEntryPoint(methodToken);
1199 [SecuritySafeCritical]
1207 if (binaryAttribute ==
null)
1213 SetCustomAttributeNoLock(con, binaryAttribute);
1218 private void SetCustomAttributeNoLock(
ConstructorInfo con,
byte[] binaryAttribute)
1223 m_assemblyData.AddCustomAttribute(con, binaryAttribute);
1232 [SecuritySafeCritical]
1235 if (customBuilder ==
null)
1241 SetCustomAttributeNoLock(customBuilder);
1248 customBuilder.CreateCustomAttribute(m_manifestModuleBuilder, 536870913);
1251 m_assemblyData.AddCustomAttribute(customBuilder);
1265 public void Save(
string assemblyFileName)
1282 [SecuritySafeCritical]
1287 SaveNoLock(assemblyFileName, portableExecutableKind, imageFileMachine);
1294 if (assemblyFileName ==
null)
1298 if (assemblyFileName.Length == 0)
1307 int[] array2 =
null;
1311 if (m_assemblyData.m_iCABuilder != 0)
1313 array =
new int[m_assemblyData.m_iCABuilder];
1315 if (m_assemblyData.m_iCAs != 0)
1317 array2 =
new int[m_assemblyData.m_iCAs];
1319 if (m_assemblyData.m_isSaved)
1321 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_AssemblyHasBeenSaved", InternalAssembly.GetSimpleName()));
1325 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_CantSaveTransientAssembly"));
1327 ModuleBuilder moduleBuilder = m_assemblyData.FindModuleWithFileName(assemblyFileName);
1328 if (moduleBuilder !=
null)
1330 m_onDiskAssemblyModuleBuilder = moduleBuilder;
1331 moduleBuilder.m_moduleData.FileToken = 0;
1335 m_assemblyData.CheckFileNameConflict(assemblyFileName);
1337 if (m_assemblyData.m_strDir ==
null)
1339 m_assemblyData.m_strDir = Environment.CurrentDirectory;
1343 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidDirectory", m_assemblyData.m_strDir));
1345 assemblyFileName =
Path.
Combine(m_assemblyData.m_strDir, assemblyFileName);
1348 if (moduleBuilder !=
null)
1350 for (
int i = 0; i < m_assemblyData.m_iCABuilder; i++)
1352 array[i] = m_assemblyData.m_CABuilders[i].PrepareCreateCustomAttributeToDisk(moduleBuilder);
1354 for (
int i = 0; i < m_assemblyData.m_iCAs; i++)
1356 array2[i] = moduleBuilder.InternalGetConstructorToken(m_assemblyData.m_CACons[i], usingRef:
true).Token;
1358 moduleBuilder.PreSave(assemblyFileName, portableExecutableKind, imageFileMachine);
1360 RuntimeModule assemblyModule = (moduleBuilder !=
null) ? moduleBuilder.ModuleHandle.GetRuntimeModule() :
null;
1361 PrepareForSavingManifestToDisk(GetNativeHandle(), assemblyModule);
1362 ModuleBuilder onDiskAssemblyModuleBuilder = GetOnDiskAssemblyModuleBuilder();
1363 if (m_assemblyData.m_strResourceFileName !=
null)
1365 onDiskAssemblyModuleBuilder.DefineUnmanagedResourceFileInternalNoLock(m_assemblyData.m_strResourceFileName);
1367 else if (m_assemblyData.m_resourceBytes !=
null)
1369 onDiskAssemblyModuleBuilder.DefineUnmanagedResourceInternalNoLock(m_assemblyData.m_resourceBytes);
1371 else if (m_assemblyData.m_hasUnmanagedVersionInfo)
1373 m_assemblyData.FillUnmanagedVersionInfo();
1374 string text = m_assemblyData.m_nativeVersion.m_strFileVersion;
1379 CreateVersionInfoResource(assemblyFileName, m_assemblyData.m_nativeVersion.m_strTitle,
null, m_assemblyData.m_nativeVersion.m_strDescription, m_assemblyData.m_nativeVersion.m_strCopyright, m_assemblyData.m_nativeVersion.m_strTrademark, m_assemblyData.m_nativeVersion.m_strCompany, m_assemblyData.m_nativeVersion.m_strProduct, m_assemblyData.m_nativeVersion.m_strProductVersion, text, m_assemblyData.m_nativeVersion.m_lcid, m_assemblyData.m_peFileKind ==
PEFileKinds.Dll, JitHelpers.GetStringHandleOnStack(ref s));
1380 onDiskAssemblyModuleBuilder.DefineUnmanagedResourceFileInternalNoLock(s);
1382 if (moduleBuilder ==
null)
1384 for (
int i = 0; i < m_assemblyData.m_iCABuilder; i++)
1386 array[i] = m_assemblyData.m_CABuilders[i].PrepareCreateCustomAttributeToDisk(onDiskAssemblyModuleBuilder);
1388 for (
int i = 0; i < m_assemblyData.m_iCAs; i++)
1390 array2[i] = onDiskAssemblyModuleBuilder.InternalGetConstructorToken(m_assemblyData.m_CACons[i], usingRef:
true).Token;
1393 int count = m_assemblyData.m_moduleBuilderList.Count;
1394 for (
int i = 0; i < count; i++)
1396 ModuleBuilder moduleBuilder2 = m_assemblyData.m_moduleBuilderList[i];
1397 if (!moduleBuilder2.IsTransient() && moduleBuilder2 != moduleBuilder)
1399 string text2 = moduleBuilder2.m_moduleData.m_strFileName;
1400 if (m_assemblyData.m_strDir !=
null)
1402 text2 =
Path.
Combine(m_assemblyData.m_strDir, text2);
1406 moduleBuilder2.m_moduleData.FileToken = AddFile(GetNativeHandle(), moduleBuilder2.m_moduleData.m_strFileName);
1407 moduleBuilder2.PreSave(text2, portableExecutableKind, imageFileMachine);
1408 moduleBuilder2.Save(text2, isAssemblyFile:
false, portableExecutableKind, imageFileMachine);
1409 SetFileHashValue(GetNativeHandle(), moduleBuilder2.m_moduleData.FileToken, text2);
1412 for (
int i = 0; i < m_assemblyData.m_iPublicComTypeCount; i++)
1414 Type type = m_assemblyData.m_publicComTypeList[i];
1415 if (type is RuntimeType)
1417 InternalModuleBuilder module = (InternalModuleBuilder)type.Module;
1418 ModuleBuilder moduleBuilder3 = GetModuleBuilder(module);
1419 if (moduleBuilder3 != moduleBuilder)
1421 DefineNestedComType(type, moduleBuilder3.m_moduleData.FileToken, type.MetadataToken);
1426 TypeBuilder typeBuilder = (TypeBuilder)type;
1427 ModuleBuilder moduleBuilder3 = typeBuilder.GetModuleBuilder();
1428 if (moduleBuilder3 != moduleBuilder)
1430 DefineNestedComType(type, moduleBuilder3.m_moduleData.FileToken, typeBuilder.MetadataTokenInternal);
1434 if (onDiskAssemblyModuleBuilder != m_manifestModuleBuilder)
1436 for (
int i = 0; i < m_assemblyData.m_iCABuilder; i++)
1438 m_assemblyData.m_CABuilders[i].CreateCustomAttribute(onDiskAssemblyModuleBuilder, 536870913, array[i], toDisk:
true);
1440 for (
int i = 0; i < m_assemblyData.m_iCAs; i++)
1442 TypeBuilder.DefineCustomAttribute(onDiskAssemblyModuleBuilder, 536870913, array2[i], m_assemblyData.m_CABytes[i], toDisk:
true, updateCompilerFlags:
false);
1445 if (m_assemblyData.m_RequiredPset !=
null)
1447 AddDeclarativeSecurity(m_assemblyData.m_RequiredPset,
SecurityAction.RequestMinimum);
1449 if (m_assemblyData.m_RefusedPset !=
null)
1451 AddDeclarativeSecurity(m_assemblyData.m_RefusedPset,
SecurityAction.RequestRefuse);
1453 if (m_assemblyData.m_OptionalPset !=
null)
1455 AddDeclarativeSecurity(m_assemblyData.m_OptionalPset,
SecurityAction.RequestOptional);
1457 count = m_assemblyData.m_resWriterList.Count;
1458 for (
int i = 0; i < count; i++)
1460 ResWriterData resWriterData =
null;
1463 resWriterData = m_assemblyData.m_resWriterList[i];
1464 if (resWriterData.m_resWriter !=
null)
1471 if (resWriterData !=
null && resWriterData.m_resWriter !=
null)
1473 resWriterData.m_resWriter.Close();
1476 AddStandAloneResource(GetNativeHandle(), resWriterData.m_strName, resWriterData.m_strFileName, resWriterData.m_strFullFileName, (
int)resWriterData.m_attribute);
1478 if (moduleBuilder ==
null)
1480 onDiskAssemblyModuleBuilder.DefineNativeResource(portableExecutableKind, imageFileMachine);
1481 int entryPoint = (m_assemblyData.m_entryPointModule !=
null) ? m_assemblyData.m_entryPointModule.m_moduleData.FileToken : 0;
1482 SaveManifestToDisk(GetNativeHandle(), assemblyFileName, entryPoint, (int)m_assemblyData.m_peFileKind, (
int)portableExecutableKind, (int)imageFileMachine);
1486 if (m_assemblyData.m_entryPointModule !=
null && m_assemblyData.m_entryPointModule != moduleBuilder)
1488 moduleBuilder.SetEntryPoint(
new MethodToken(m_assemblyData.m_entryPointModule.m_moduleData.FileToken));
1490 moduleBuilder.Save(assemblyFileName, isAssemblyFile:
true, portableExecutableKind, imageFileMachine);
1492 m_assemblyData.m_isSaved =
true;
1506 byte[] array = pset.EncodeXml();
1507 AddDeclarativeSecurity(GetNativeHandle(), action, array, array.Length);
1510 internal bool IsPersistable()
1520 private int DefineNestedComType(Type type,
int tkResolutionScope,
int tkTypeDef)
1522 Type declaringType = type.DeclaringType;
1523 if (declaringType ==
null)
1525 return AddExportedTypeOnDisk(GetNativeHandle(), type.FullName, tkResolutionScope, tkTypeDef, type.Attributes);
1527 tkResolutionScope = DefineNestedComType(declaringType, tkResolutionScope, tkTypeDef);
1528 return AddExportedTypeOnDisk(GetNativeHandle(), type.Name, tkResolutionScope, tkTypeDef, type.Attributes);
1532 internal int DefineExportedTypeInMemory(Type type,
int tkResolutionScope,
int tkTypeDef)
1534 Type declaringType = type.DeclaringType;
1535 if (declaringType ==
null)
1537 return AddExportedTypeInMemory(GetNativeHandle(), type.FullName, tkResolutionScope, tkTypeDef, type.Attributes);
1539 tkResolutionScope = DefineExportedTypeInMemory(declaringType, tkResolutionScope, tkTypeDef);
1540 return AddExportedTypeInMemory(GetNativeHandle(), type.Name, tkResolutionScope, tkTypeDef, type.Attributes);
1543 private AssemblyBuilder()
1552 throw new NotImplementedException();
1562 throw new NotImplementedException();
1574 throw new NotImplementedException();
1587 void _AssemblyBuilder.
Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid,
short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1589 throw new NotImplementedException();
1594 [SuppressUnmanagedCodeSecurity]
1595 private static extern void DefineDynamicModule(RuntimeAssembly containingAssembly,
bool emitSymbolInfo,
string name,
string filename, StackCrawlMarkHandle stackMark, ref IntPtr pInternalSymWriter, ObjectHandleOnStack retModule,
bool fIsTransient, out
int tkFile);
1598 private static Module DefineDynamicModule(RuntimeAssembly containingAssembly,
bool emitSymbolInfo,
string name,
string filename, ref StackCrawlMark stackMark, ref IntPtr pInternalSymWriter,
bool fIsTransient, out
int tkFile)
1600 RuntimeModule o =
null;
1601 DefineDynamicModule(containingAssembly.GetNativeHandle(), emitSymbolInfo, name, filename, JitHelpers.GetStackCrawlMarkHandle(ref stackMark), ref pInternalSymWriter, JitHelpers.GetObjectHandleOnStack(ref o), fIsTransient, out tkFile);
1607 [SuppressUnmanagedCodeSecurity]
1608 private static extern void PrepareForSavingManifestToDisk(RuntimeAssembly assembly, RuntimeModule assemblyModule);
1612 [SuppressUnmanagedCodeSecurity]
1613 private static extern void SaveManifestToDisk(RuntimeAssembly assembly,
string strFileName,
int entryPoint,
int fileKind,
int portableExecutableKind,
int ImageFileMachine);
1617 [SuppressUnmanagedCodeSecurity]
1618 private static extern int AddFile(RuntimeAssembly assembly,
string strFileName);
1622 [SuppressUnmanagedCodeSecurity]
1623 private static extern void SetFileHashValue(RuntimeAssembly assembly,
int tkFile,
string strFullFileName);
1627 [SuppressUnmanagedCodeSecurity]
1628 private static extern int AddExportedTypeInMemory(RuntimeAssembly assembly,
string strComTypeName,
int tkAssemblyRef,
int tkTypeDef,
TypeAttributes flags);
1632 [SuppressUnmanagedCodeSecurity]
1633 private static extern int AddExportedTypeOnDisk(RuntimeAssembly assembly,
string strComTypeName,
int tkAssemblyRef,
int tkTypeDef,
TypeAttributes flags);
1637 [SuppressUnmanagedCodeSecurity]
1638 private static extern void AddStandAloneResource(RuntimeAssembly assembly,
string strName,
string strFileName,
string strFullFileName,
int attribute);
1642 [SuppressUnmanagedCodeSecurity]
1643 private static extern void AddDeclarativeSecurity(RuntimeAssembly assembly,
SecurityAction action,
byte[] blob,
int length);
1647 [SuppressUnmanagedCodeSecurity]
1648 private static extern void CreateVersionInfoResource(
string filename,
string title,
string iconFilename,
string description,
string copyright,
string trademark,
string company,
string product,
string productVersion,
string fileVersion,
int lcid,
bool isDll, StringHandleOnStack retFileName);
Performs reflection on a module.
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
virtual Assembly Assembly
Gets the appropriate T:System.Reflection.Assembly for this instance of T:System.Reflection....
override Stream GetManifestResourceStream(Type type, string name)
Loads the specified manifest resource, scoped by the namespace of the specified type,...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
override object [] GetCustomAttributes(Type attributeType, bool inherit)
Returns all the custom attributes that have been applied to the current T:System.Reflection....
void Save(string assemblyFileName)
Saves this dynamic assembly to disk.
override string [] GetManifestResourceNames()
Loads the specified manifest resource from this assembly.
Provides the base functionality for writing resources to an output file or stream.
static bool Exists(string path)
Determines whether the specified file exists.
static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
Defines a dynamic assembly that has the specified name and access rights.
override Type GetType(string name, bool throwOnError, bool ignoreCase)
Gets the specified type from the types that have been defined and created in the current T:System....
static string Combine(string path1, string path2)
Combines two strings into a path.
void DefineUnmanagedResource(byte[] resource)
Defines an unmanaged resource for this assembly as an opaque blob of bytes.
Discovers the attributes of a method and provides access to method metadata.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Specifies that an assembly cannot cause an elevation of privilege.
void SetUnderlyingWriter(IntPtr underlyingWriter)
Sets the underlying ISymUnmanagedWriter (the corresponding unmanaged interface) that a managed T:Syst...
Exposes the T:System.Reflection.Emit.AssemblyBuilder class to unmanaged code.
override AssemblyName [] GetReferencedAssemblies()
Gets an incomplete list of T:System.Reflection.AssemblyName objects for the assemblies that are refer...
void AddResourceFile(string name, string fileName)
Adds an existing resource file to this assembly.
Discovers the attributes of a class constructor and provides access to constructor metadata.
override string FullName
Gets the display name of the current dynamic assembly.
override Assembly GetSatelliteAssembly(CultureInfo culture, Version version)
Gets the specified version of the satellite assembly for the specified culture.
ImageFileMachine
Identifies the platform targeted by an executable.
override FileStream GetFile(string name)
Gets a T:System.IO.FileStream for the specified file in the file table of the manifest of this assemb...
SecurityContextSource
Identifies the source for the security context.
ModuleBuilder GetDynamicModule(string name)
Returns the dynamic module with the specified name.
ModuleBuilder DefineDynamicModule(string name)
Defines a named transient dynamic module in this assembly.
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
override Module [] GetModules(bool getResourceModules)
Gets all the modules that are part of this assembly, and optionally includes resource modules.
Defines and represents a dynamic assembly.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Set a custom attribute on this assembly using a custom attribute builder.
static string GetFileName(string path)
Returns the file name and extension of the specified path string.
void DefineVersionInfoResource()
Defines an unmanaged version information resource using the information specified in the assembly's A...
AssemblyBuilderAccess
Defines the access modes for a dynamic assembly.
Allows an assembly to be called by partially trusted code. Without this declaration,...
override AssemblyName GetName(bool copiedName)
Gets the T:System.Reflection.AssemblyName that was specified when the current dynamic assembly was cr...
Evidence()
Initializes a new empty instance of the T:System.Security.Policy.Evidence class.
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Helps build custom attributes.
Represents an application domain, which is an isolated environment where applications execute....
void SetEntryPoint(MethodInfo entryMethod, PEFileKinds fileKind)
Sets the entry point for this assembly and defines the type of the portable executable (PE file) bein...
void DefineVersionInfoResource(string product, string productVersion, string company, string copyright, string trademark)
Defines an unmanaged version information resource for this assembly with the given specifications.
MethodToken GetConstructorToken(ConstructorInfo constructor, IEnumerable< Type > optionalParameterTypes)
Returns the token used to identify the constructor that has the specified attributes and parameter ty...
override string ToString()
Converts the value of the current T:System.Version object to its equivalent T:System....
Modifies code generation for runtime just-in-time (JIT) debugging. This class cannot be inherited.
SecurityAction
Specifies the security actions that can be performed using declarative security.
override MethodInfo EntryPoint
Returns the entry point of this assembly.
Indicates the set of security rules the common language runtime should enforce for an assembly.
Provides information about, and means to manipulate, the current environment and platform....
override Module [] GetLoadedModules(bool getResourceModules)
Returns all the loaded modules that are part of this assembly, and optionally includes resource modul...
override FileStream [] GetFiles(bool getResourceModules)
Gets the files in the file table of an assembly manifest, specifying whether to include resource modu...
Finds or creates a T:System.AppDomain.
Represents a collection that can contain many different types of permissions.
override IList< CustomAttributeData > GetCustomAttributesData()
Returns T:System.Reflection.CustomAttributeData objects that contain information about the attributes...
Defines and creates new instances of classes during run time.
override Stream GetManifestResourceStream(string name)
Loads the specified manifest resource from this assembly.
Exposes static methods for creating, moving, and enumerating through directories and subdirectories....
override string ImageRuntimeVersion
Gets the version of the common language runtime that will be saved in the file containing the manifes...
Defines and represents a module in a dynamic assembly.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
override Module GetModule(string name)
Gets the specified module in this assembly.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Defines the underlying structure of all code access permissions.
Specifies that code or an assembly performs security-critical operations.
void AddResourceFile(string name, string fileName, ResourceAttributes attribute)
Adds an existing resource file to this assembly.
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
static bool Exists(string path)
Determines whether the given path refers to an existing directory on disk.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents type declarations: class types, interface types, array types, value types,...
Represents the version number of an assembly, operating system, or the common language runtime....
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
Provides access to manifest resources, which are XML files that describe application dependencies.
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
MethodImplOptions
Defines the details of how a method is implemented.
ModuleBuilder DefineDynamicModule(string name, string fileName)
Defines a persistable dynamic module with the given name that will be saved to the specified file....
IResourceWriter DefineResource(string name, string description, string fileName, ResourceAttributes attribute)
Defines a standalone managed resource for this assembly. Attributes can be specified for the managed ...
CharSet
Dictates which character set marshaled strings should use.
void SetEntryPoint(MethodInfo entryMethod)
Sets the entry point for this dynamic assembly, assuming that a console application is being built.
override bool GlobalAssemblyCache
Gets a value that indicates whether the assembly was loaded from the global assembly cache.
override Module ManifestModule
Gets the module in the current T:System.Reflection.Emit.AssemblyBuilder that contains the assembly ma...
TypeAttributes
Specifies type attributes.
override long HostContext
Gets the host context where the dynamic assembly is being created.
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
Describes an assembly's unique identity in full.
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
Represents a collection of objects that can be individually accessed by index.
SecurityRuleSet
Identifies the set of security rules the common language runtime should enforce for an assembly.
Attribute can be applied to an assembly.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
override bool IsDynamic
Gets a value that indicates that the current assembly is a dynamic assembly.
override PermissionSet PermissionSet
Gets the grant set of the current dynamic assembly.
Attribute can be applied to a module.
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
override bool ReflectionOnly
Gets a value indicating whether the dynamic assembly is in the reflection-only context.
ResourceAttributes
Specifies the attributes for a manifest resource.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Writes resources in the system-default format to an output file or an output stream....
static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable< CustomAttributeBuilder > assemblyAttributes)
Defines a new assembly that has the specified name, access rights, and attributes.
IResourceWriter DefineResource(string name, string description, string fileName)
Defines a standalone managed resource for this assembly with the default public resource attribute.
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
Set a custom attribute on this assembly using a specified custom attribute blob.
Represents a symbol writer for managed code.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Identifies which of the nonpublic T:System.Security.SecurityCriticalAttribute members are accessible ...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
int Token
Returns the metadata token for this method.
override Assembly GetSatelliteAssembly(CultureInfo culture)
Gets the satellite assembly for the specified culture.
override Type [] GetExportedTypes()
Gets the exported types defined in this assembly.
virtual Module Module
Gets the module in which the type that declares the member represented by the current T:System....
Defines the set of information that constitutes input to security policy decisions....
PortableExecutableKinds
Identifies the nature of the code in an executable file.
ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo)
Defines a named transient dynamic module in this assembly and specifies whether symbol information sh...
override object [] GetCustomAttributes(bool inherit)
Returns all the custom attributes that have been applied to the current T:System.Reflection....
void DefineUnmanagedResource(string resourceFileName)
Defines an unmanaged resource file for this assembly given the name of the resource file.
override bool IsDefined(Type attributeType, bool inherit)
Returns a value that indicates whether one or more instances of the specified attribute type is appli...
The exception that is thrown when a method call is invalid for the object's current state.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
override int GetHashCode()
Returns the hash code for this instance.
override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
Returns information about how the given resource has been persisted.
static void Delete(string path)
Deletes the specified file.
Provides information about a specific culture (called a locale for unmanaged code development)....
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Controls the ability to access files and folders. This class cannot be inherited.
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to the specified object.
SecurityPermissionFlag
Specifies access flags for the security permission object.
override string CodeBase
Gets the location of the assembly, as specified originally (such as in an T:System....
static string CurrentDirectory
Gets or sets the fully qualified path of the current working directory.
void Save(string assemblyFileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
Saves this dynamic assembly to disk, specifying the nature of code in the assembly's executables and ...
SecurityCriticalScope
Specifies the scope of a T:System.Security.SecurityCriticalAttribute.
ModuleBuilder DefineDynamicModule(string name, string fileName, bool emitSymbolInfo)
Defines a persistable dynamic module, specifying the module name, the name of the file to which the m...
Performs operations on T:System.String instances that contain file or directory path information....
override string Location
Gets the location, in codebase format, of the loaded file that contains the manifest if it is not sha...
PEFileKinds
Specifies the type of the portable executable (PE) file.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....