/********************************************** * Use this function if client decides to form the custom attribute blob themselves **********************************************/ /// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.SetCustomAttribute"]/*' /> public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); if (con == null) { throw new ArgumentNullException("con"); } if (binaryAttribute == null) { throw new ArgumentNullException("binaryAttribute"); } ModuleBuilder inMemoryAssemblyModule; inMemoryAssemblyModule = m_assemblyData.GetInMemoryAssemblyModule(); TypeBuilder.InternalCreateCustomAttribute( AssemblyBuilderData.m_tkAssembly, // This is the AssemblyDef token inMemoryAssemblyModule.GetConstructorToken(con).Token, binaryAttribute, inMemoryAssemblyModule, // pass in the in-memory assembly module false); // Track the CA for persistence if (m_assemblyData.m_access == AssemblyBuilderAccess.Run) { return; } // tracking the CAs for persistence m_assemblyData.AddCustomAttribute(con, binaryAttribute); }
/// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.SetEntryPoint1"]/*' /> public void SetEntryPoint( MethodInfo entryMethod, // entry method for the assembly. We use this to determine the entry module PEFileKinds fileKind) // file kind for the assembly. { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); try { Enter(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.SetEntryPoint"); if (entryMethod == null) { throw new ArgumentNullException("entryMethod"); } // Module tmpModule = entryMethod.InternalReflectedClass(true).Module; if (!(tmpModule is ModuleBuilder && this.Equals(tmpModule.Assembly))) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EntryMethodNotDefinedInAssembly")); } m_assemblyData.m_entryPointModule = (ModuleBuilder)tmpModule; m_assemblyData.m_entryPointMethod = entryMethod; m_assemblyData.m_peFileKind = fileKind; m_assemblyData.m_entryPointModule.SetEntryPoint(entryMethod); } finally { Exit(); } }
internal static void DemandForUnsafeAssemblyNameAssignments(string originalAssemblyName, string newAssemblyName) { if (!IsAssemblyNameAssignmentSafe(originalAssemblyName, newAssemblyName)) { CodeAccessPermission.DemandInternal(PermissionType.SecuritySerialization); } }
/********************************************** * * Defines a named dynamic module. It is an error to define multiple * modules within an Assembly with the same name. This dynamic module is * a transient module. * **********************************************/ /// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.DefineDynamicModule"]/*' /> public ModuleBuilder DefineDynamicModule( String name) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(DefineDynamicModuleInternal(name, false, ref stackMark)); }
private IResourceWriter DefineResourceNoLock( String name, String description, String fileName, ResourceAttributes attribute) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.DefineResource( " + name + ", " + fileName + ")"); if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName"); } if (!String.Equals(fileName, Path.GetFileName(fileName))) { throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName"); } m_assemblyData.CheckResNameConflict(name); m_assemblyData.CheckFileNameConflict(fileName); ResourceWriter resWriter; String fullFileName; if (m_assemblyData.m_strDir == null) { // If assembly directory is null, use current directory fullFileName = Path.Combine(Environment.CurrentDirectory, fileName); resWriter = new ResourceWriter(fullFileName); } else { // Form the full path given the directory provided by user fullFileName = Path.Combine(m_assemblyData.m_strDir, fileName); resWriter = new ResourceWriter(fullFileName); } // get the full path fullFileName = Path.GetFullPath(fullFileName); // retrieve just the file name fileName = Path.GetFileName(fullFileName); m_assemblyData.AddResWriter(new ResWriterData(resWriter, null, name, fileName, fullFileName, attribute)); return(resWriter); }
/// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.DefineDynamicModule1"]/*' /> public ModuleBuilder DefineDynamicModule( String name, bool emitSymbolInfo) // specify if emit symbol info or not { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(DefineDynamicModuleInternal(name, emitSymbolInfo, ref stackMark)); }
internal ObjectManager(ISurrogateSelector selector, StreamingContext context, bool checkSecurity, bool isCrossAppDomain) { if (checkSecurity) { CodeAccessPermission.DemandInternal(PermissionType.SecuritySerialization); } this.m_objects = new ObjectHolder[0x10]; this.m_selector = selector; this.m_context = context; this.m_isCrossAppDomain = isCrossAppDomain; }
internal object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture, bool skipVisibilityChecks) { int length = this.Signature.Arguments.Length; int num2 = (parameters != null) ? parameters.Length : 0; if ((this.m_invocationFlags & 1) == 0) { this.m_invocationFlags = this.GetOneTimeFlags(); } if ((this.m_invocationFlags & 2) != 0) { this.ThrowNoInvokeException(); } this.CheckConsistency(obj); if (length != num2) { throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); } if (num2 > 0xffff) { throw new TargetParameterCountException(Environment.GetResourceString("NotSupported_TooManyArgs")); } if (!skipVisibilityChecks && ((this.m_invocationFlags & 0x24) != 0)) { if ((this.m_invocationFlags & 0x20) != 0) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionMemberAccess); } if ((this.m_invocationFlags & 4) != 0) { MethodBase.PerformSecurityCheck(obj, this.m_handle, this.m_declaringType.TypeHandle.Value, this.m_invocationFlags); } } RuntimeTypeHandle emptyHandle = RuntimeTypeHandle.EmptyHandle; if (!this.m_reflectedTypeCache.IsGlobal) { emptyHandle = this.m_declaringType.TypeHandle; } if (num2 == 0) { return(this.m_handle.InvokeMethodFast(obj, null, this.Signature, this.m_methodAttributes, emptyHandle)); } object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature); object obj2 = this.m_handle.InvokeMethodFast(obj, arguments, this.Signature, this.m_methodAttributes, emptyHandle); for (int i = 0; i < num2; i++) { parameters[i] = arguments[i]; } return(obj2); }
public override object Invoke(System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { RuntimeTypeHandle typeHandle = this.m_declaringType.TypeHandle; if (this.m_invocationFlags == 0) { this.m_invocationFlags = this.GetOneTimeFlags(); } if ((this.m_invocationFlags & 0x10a) != 0) { this.ThrowNoInvokeException(); } if ((this.m_invocationFlags & 0xa4) != 0) { if ((this.m_invocationFlags & 0x20) != 0) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionMemberAccess); } if ((this.m_invocationFlags & 4) != 0) { MethodBase.PerformSecurityCheck(null, this.m_handle, this.m_declaringType.TypeHandle.Value, this.m_invocationFlags & 0x10000000); } if ((this.m_invocationFlags & 0x80) != 0) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); } } int length = this.Signature.Arguments.Length; int num2 = (parameters != null) ? parameters.Length : 0; if (length != num2) { throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); } RuntimeHelpers.RunClassConstructor(typeHandle); if (num2 <= 0) { return(this.m_handle.InvokeConstructor(null, (SignatureStruct)this.Signature, typeHandle)); } object[] args = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature); object obj2 = this.m_handle.InvokeConstructor(args, (SignatureStruct)this.Signature, typeHandle); for (int i = 0; i < num2; i++) { parameters[i] = args[i]; } return(obj2); }
public override object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { if (this.m_invocationFlags == 0) { this.m_invocationFlags = this.GetOneTimeFlags(); } if ((this.m_invocationFlags & 2) != 0) { this.ThrowNoInvokeException(); } this.CheckConsistency(obj); if (obj != null) { new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand(); } if ((this.m_invocationFlags & 0x24) != 0) { if ((this.m_invocationFlags & 0x20) != 0) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionMemberAccess); } if ((this.m_invocationFlags & 4) != 0) { MethodBase.PerformSecurityCheck(obj, this.m_handle, this.m_declaringType.TypeHandle.Value, this.m_invocationFlags); } } int length = this.Signature.Arguments.Length; int num2 = (parameters != null) ? parameters.Length : 0; if (length != num2) { throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); } if (num2 <= 0) { return(this.m_handle.InvokeMethodFast(obj, null, this.Signature, this.m_methodAttributes, (this.DeclaringType != null) ? this.DeclaringType.TypeHandle : RuntimeTypeHandle.EmptyHandle)); } object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature); object obj2 = this.m_handle.InvokeMethodFast(obj, arguments, this.Signature, this.m_methodAttributes, (this.ReflectedType != null) ? this.ReflectedType.TypeHandle : RuntimeTypeHandle.EmptyHandle); for (int i = 0; i < num2; i++) { parameters[i] = arguments[i]; } return(obj2); }
public void SetEntryPoint( MethodInfo entryMethod, // entry method for the assembly. We use this to determine the entry module PEFileKinds fileKind) // file kind for the assembly. { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); if (m_assemblyData.m_isSynchronized) { lock (m_assemblyData) { SetEntryPointNoLock(entryMethod, fileKind); } } else { SetEntryPointNoLock(entryMethod, fileKind); } }
public void AddResourceFile( String name, String fileName, ResourceAttributes attribute) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); if (m_assemblyData.m_isSynchronized) { lock (m_assemblyData) { AddResourceFileNoLock(name, fileName, attribute); } } else { AddResourceFileNoLock(name, fileName, attribute); } }
/********************************************** * Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder **********************************************/ /// <include file='doc\AssemblyBuilder.uex' path='docs/doc[@for="AssemblyBuilder.SetCustomAttribute1"]/*' /> public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit); if (customBuilder == null) { throw new ArgumentNullException("customBuilder"); } ModuleBuilder inMemoryAssemblyModule; inMemoryAssemblyModule = m_assemblyData.GetInMemoryAssemblyModule(); customBuilder.CreateCustomAttribute( inMemoryAssemblyModule, AssemblyBuilderData.m_tkAssembly); // This is the AssemblyDef token // Track the CA for persistence if (m_assemblyData.m_access == AssemblyBuilderAccess.Run) { return; } m_assemblyData.AddCustomAttribute(customBuilder); }