internal RuntimeMethodInfo( RuntimeMethodHandleInternal handle, RuntimeType declaringType, RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, BindingFlags bindingFlags, object keepalive) { Contract.Ensures(!m_handle.IsNull()); Debug.Assert(!handle.IsNullHandle()); Debug.Assert(methodAttributes == RuntimeMethodHandle.GetAttributes(handle)); m_bindingFlags = bindingFlags; m_declaringType = declaringType; m_keepalive = keepalive; m_handle = handle.Value; m_reflectedTypeCache = reflectedTypeCache; m_methodAttributes = methodAttributes; }
[System.Security.SecurityCritical] // auto-generated #endif #pragma warning disable 618 internal static void CheckHelper(Object notUsed, #pragma warning restore 618 PermissionSet grantedSet, PermissionSet refusedSet, CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) { // To reduce the amount of ifdef-code-churn, a dummy arg is used for the first parameter - instead of a CompressedStack object, // we use a System.Object that should always be null. If we tried to change the signature of the function, there will need to be // corresponding changes in VM (metasig.h, mscorlib.h, securitystackwalk.cpp, number of elements in the arg array, etc.) Contract.Assert(notUsed == null, "Should not reach here with a non-null first arg which is the CompressedStack"); CheckHelper(grantedSet, refusedSet, demand, permToken, rmh, (Object)asm, action, true); }
[System.Security.SecurityCritical] // auto-generated internal static void CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) { if (cs != null) { cs.CheckSetDemand(demands, rmh); } else { CheckSetHelper(grants, refused, demands, rmh, (Object)asm, action, true); } }
public int GetTokenFor(RuntimeMethodHandle method) { IRuntimeMethodInfo methodInfo = method.GetMethodInfo(); RuntimeMethodHandleInternal internal2 = methodInfo.Value; if ((methodInfo != null) && !RuntimeMethodHandle.IsDynamicMethod(internal2)) { RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(internal2); if ((declaringType != null) && RuntimeTypeHandle.IsGenericType(declaringType)) { MethodBase methodBase = RuntimeType.GetMethodBase(methodInfo); Type genericTypeDefinition = methodBase.DeclaringType.GetGenericTypeDefinition(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), new object[] { methodBase, genericTypeDefinition })); } } this.m_tokens.Add(method); return((this.m_tokens.Count - 1) | 0x6000000); }
public int GetTokenFor(RuntimeMethodHandle method) { IRuntimeMethodInfo methodInfo = method.GetMethodInfo(); RuntimeMethodHandleInternal value = methodInfo.Value; if (methodInfo != null && !RuntimeMethodHandle.IsDynamicMethod(value)) { RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(value); if (declaringType != null && RuntimeTypeHandle.HasInstantiation(declaringType)) { MethodBase methodBase = RuntimeType.GetMethodBase(methodInfo); Type genericTypeDefinition = methodBase.DeclaringType.GetGenericTypeDefinition(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), methodBase, genericTypeDefinition)); } } this.m_tokens.Add(method); return(this.m_tokens.Count - 1 | 100663296); }
private static bool CheckDynamicMethodHelper(System.Reflection.Emit.DynamicResolver dynamicResolver, IPermission demandIn, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { System.Threading.CompressedStack creationStack = dynamicResolver.GetSecurityContext(); bool result; try { result = creationStack.CheckDemandNoHalt((CodeAccessPermission)demandIn, permToken, rmh); } catch (SecurityException ex) { throw new SecurityException(Environment.GetResourceString("Security_AnonymouslyHostedDynamicMethodCheckFailed"), ex); } return(result); }
[System.Security.SecurityCritical] // auto-generated internal static void CheckHelper(CompressedStack cs, PermissionSet grantedSet, PermissionSet refusedSet, CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) { if (cs != null) { cs.CheckDemand(demand, permToken, rmh); } else { CheckHelper(grantedSet, refusedSet, demand, permToken, rmh, (Object)asm, action, true); } }
private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } bool flag = declaredType != reflectedType; IntPtr[] typeInstantiationContext = null; int typeInstCount = 0; RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (instantiationInternal != null) { typeInstCount = instantiationInternal.Length; typeInstantiationContext = new IntPtr[instantiationInternal.Length]; for (int i = 0; i < instantiationInternal.Length; i++) { typeInstantiationContext[i] = instantiationInternal[i].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal method = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, null, 0); if (flag) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(method); if ((attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } if (((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass)) { int slot = RuntimeMethodHandle.GetSlot(method); method = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } RuntimeMethodInfo methodBase = RuntimeType.GetMethodBase(reflectedType, method) as RuntimeMethodInfo; if (methodBase == null) { methodBase = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo; } return(methodBase); }
private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return((RuntimeMethodInfo)null); } bool flag = declaredType != reflectedType; IntPtr[] typeInstantiationContext = (IntPtr[])null; int typeInstCount = 0; RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (instantiationInternal != null) { typeInstCount = instantiationInternal.Length; typeInstantiationContext = new IntPtr[instantiationInternal.Length]; for (int index = 0; index < instantiationInternal.Length; ++index) { typeInstantiationContext[index] = instantiationInternal[index].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal methodHandleInternal = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, (IntPtr[])null, 0); if (flag) { MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(methodHandleInternal); if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return((RuntimeMethodInfo)null); } if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope && (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.NotPublic) { int slot = RuntimeMethodHandle.GetSlot(methodHandleInternal); methodHandleInternal = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } RuntimeMethodInfo runtimeMethodInfo = RuntimeType.GetMethodBase(reflectedType, methodHandleInternal) as RuntimeMethodInfo; if ((MethodInfo)runtimeMethodInfo == (MethodInfo)null) { runtimeMethodInfo = reflectedType.Module.ResolveMethod(tkMethod, (Type[])null, (Type[])null) as RuntimeMethodInfo; } return(runtimeMethodInfo); }
private static bool CheckDynamicMethodSetHelper(System.Reflection.Emit.DynamicResolver dynamicResolver, PermissionSet demandSet, out PermissionSet alteredDemandSet, RuntimeMethodHandleInternal rmh) { System.Threading.CompressedStack creationStack = dynamicResolver.GetSecurityContext(); bool result; try { result = creationStack.CheckSetDemandWithModificationNoHalt(demandSet, out alteredDemandSet, rmh); } catch (SecurityException ex) { throw new SecurityException(Environment.GetResourceString("Security_AnonymouslyHostedDynamicMethodCheckFailed"), ex); } return(result); }
public int GetTokenFor(RuntimeMethodHandle method) { IRuntimeMethodInfo methodReal = method.GetMethodInfo(); RuntimeMethodHandleInternal rmhi = methodReal.Value; if (methodReal != null && !RuntimeMethodHandle.IsDynamicMethod(rmhi)) { RuntimeType type = RuntimeMethodHandle.GetDeclaringType(rmhi); if ((type != null) && RuntimeTypeHandle.HasInstantiation(type)) { // Do we really need to retrieve this much info just to throw an exception? MethodBase m = RuntimeType.GetMethodBase(methodReal); Type t = m.DeclaringType.GetGenericTypeDefinition(); throw new ArgumentException(SR.Format(SR.Argument_MethodDeclaringTypeGenericLcg, m, t)); } } m_tokens.Add(method); return(m_tokens.Count - 1 | (int)MetadataTokenType.MethodDef); }
internal bool CheckSetDemand(PermissionSet pset, RuntimeMethodHandleInternal rmh) { PermissionSet set2; bool flag = true; PermissionSet demandSet = pset; if (this.m_permSetTriples != null) { for (int i = 0; (i < this.m_permSetTriples.Count) && flag; i++) { flag = ((PermissionSetTriple)this.m_permSetTriples[i]).CheckSetDemand(demandSet, out set2, rmh); if (set2 != null) { demandSet = set2; } } } else if (this.m_firstPermSetTriple != null) { flag = this.m_firstPermSetTriple.CheckSetDemand(demandSet, out set2, rmh); } return(false); }
public override MethodInfo GetBaseDefinition() { if (!this.IsVirtual || this.IsStatic || (this.m_declaringType == (RuntimeType)null || this.m_declaringType.IsInterface)) { return((MethodInfo)this); } int slot = RuntimeMethodHandle.GetSlot((IRuntimeMethodInfo)this); RuntimeType type = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = type; RuntimeMethodHandleInternal methodHandle = new RuntimeMethodHandleInternal(); while (RuntimeTypeHandle.GetNumVirtuals(type) > slot) { methodHandle = RuntimeTypeHandle.GetMethodAt(type, slot); reflectedType = type; type = (RuntimeType)type.BaseType; if (!(type != (RuntimeType)null)) { break; } } return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
public override MethodInfo GetBaseDefinition() { if ((!base.IsVirtual || base.IsStatic) || ((this.m_declaringType == null) || this.m_declaringType.IsInterface)) { return(this); } int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType declaringType = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = declaringType; RuntimeMethodHandleInternal methodHandle = new RuntimeMethodHandleInternal(); do { if (RuntimeTypeHandle.GetNumVirtuals(declaringType) <= slot) { break; } methodHandle = RuntimeTypeHandle.GetMethodAt(declaringType, slot); reflectedType = declaringType; declaringType = (RuntimeType)declaringType.BaseType; }while (declaringType != null); return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand(PermissionSet demandSet, out PermissionSet alteredDemandSet, RuntimeMethodHandleInternal rmh) { // imperative security PermissionSet altPset1 = null, altPset2 = null; bool fContinue = CheckSetDemand2(demandSet, out altPset1, rmh, false); if (altPset1 != null) { demandSet = altPset1; } if (fContinue == SecurityRuntime.StackContinue) { // declarative security fContinue = CheckSetDemand2(demandSet, out altPset2, rmh, true); } // Return the most recent altered set // If both declarative and imperative asserts modified the demand set: return altPset2 // Else if imperative asserts modified the demand set: return altPset1 // else no alteration: return null if (altPset2 != null) { alteredDemandSet = altPset2; } else if (altPset1 != null) { alteredDemandSet = altPset1; } else { alteredDemandSet = null; } return(fContinue); }
public override MethodInfo GetBaseDefinition() { if (!base.IsVirtual || base.IsStatic || this.m_declaringType == null || this.m_declaringType.IsInterface) { return(this); } int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType runtimeType = (RuntimeType)this.DeclaringType; RuntimeType reflectedType = runtimeType; RuntimeMethodHandleInternal methodHandle = default(RuntimeMethodHandleInternal); do { int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(runtimeType); if (numVirtuals <= slot) { break; } methodHandle = RuntimeTypeHandle.GetMethodAt(runtimeType, slot); reflectedType = runtimeType; runtimeType = (RuntimeType)runtimeType.BaseType; }while (runtimeType != null); return((MethodInfo)RuntimeType.GetMethodBase(reflectedType, methodHandle)); }
[System.Security.SecuritySafeCritical] // auto-generated public override MethodInfo GetBaseDefinition() { if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface) return this; int slot = RuntimeMethodHandle.GetSlot(this); RuntimeType declaringType = (RuntimeType)DeclaringType; RuntimeType baseDeclaringType = declaringType; RuntimeMethodHandleInternal baseMethodHandle = new RuntimeMethodHandleInternal(); do { int cVtblSlots = RuntimeTypeHandle.GetNumVirtuals(declaringType); if (cVtblSlots <= slot) break; baseMethodHandle = RuntimeTypeHandle.GetMethodAt(declaringType, slot); baseDeclaringType = declaringType; declaringType = (RuntimeType)declaringType.BaseType; } while (declaringType != null); return(MethodInfo)RuntimeType.GetMethodBase(baseDeclaringType, baseMethodHandle); }
[System.Security.SecurityCritical] // auto-generated internal static MethodInfo GetMethodInfo(RuntimeMethodHandleInternal rmh) { if (rmh.IsNullHandle()) { return(null); } #if _DEBUG try { #endif // Assert here because reflection will check grants and if we fail the check, // there will be an infinite recursion that overflows the stack. PermissionSet.s_fullTrust.Assert(); return(System.RuntimeType.GetMethodBase(RuntimeMethodHandle.GetDeclaringType(rmh), rmh) as MethodInfo); #if _DEBUG } catch (Exception) { return(null); } #endif }
internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { if (!PermissionSetTriple.CheckAssert(this.AssertSet, demand, permToken)) { return(false); } CodeAccessSecurityEngine.CheckHelper(this.GrantSet, this.RefusedSet, demand, permToken, rmh, (object)null, SecurityAction.Demand, true); return(true); }
internal static extern void _CompileMethod(RuntimeMethodHandleInternal method);
private static extern unsafe void PrepareMethod( RuntimeMethodHandleInternal method, IntPtr *pInstantiation, int cInstantiation );
internal static partial void CompileMethod(RuntimeMethodHandleInternal method);
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand(PermissionSet pset , RuntimeMethodHandleInternal rmh) { bool bRet = SecurityRuntime.StackContinue; PermissionSet demandSet = pset; PermissionSet alteredDemandSet; if (m_permSetTriples != null) { for (int i=0; (i < m_permSetTriples.Count && bRet != SecurityRuntime.StackHalt) ; i++) { PermissionSetTriple psTriple = (PermissionSetTriple)m_permSetTriples[i]; bRet = psTriple.CheckSetDemand(demandSet, out alteredDemandSet, rmh); if (alteredDemandSet != null) demandSet = alteredDemandSet; } } else if (m_firstPermSetTriple != null) { bRet = m_firstPermSetTriple.CheckSetDemand(demandSet, out alteredDemandSet, rmh); } return SecurityRuntime.StackHalt; // CS demand check always terminates the stackwalk }
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemandNoHalt(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { CompleteConstruction(null); if (PLS == null) return SecurityRuntime.StackContinue; else { return PLS.CheckDemand(demand, permToken, rmh); } }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand(PermissionSet pset , RuntimeMethodHandleInternal rmh) { CompleteConstruction(null); if (PLS == null) return SecurityRuntime.StackHalt; else return PLS.CheckSetDemand(pset, rmh); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { if (CheckAssert(AssertSet, demand, permToken) == SecurityRuntime.StackHalt) return SecurityRuntime.StackHalt; #pragma warning disable 618 CodeAccessSecurityEngine.CheckHelper(GrantSet, RefusedSet, demand, permToken, rmh, null, SecurityAction.Demand, true); #pragma warning restore 618 return SecurityRuntime.StackContinue; }
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemand2(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh, bool fDeclarative) { PermissionSet permSet; // If the demand is null, there is no need to continue Contract.Assert(demand != null && !demand.CheckDemand(null), "Empty demands should have been filtered out by this point"); // decode imperative if (GetPermitOnly(fDeclarative) != null) { GetPermitOnly(fDeclarative).CheckDecoded(demand, permToken); } if (GetDenials(fDeclarative) != null) { GetDenials(fDeclarative).CheckDecoded(demand, permToken); } if (GetAssertions(fDeclarative) != null) { GetAssertions(fDeclarative).CheckDecoded(demand, permToken); } // NOTE: See notes about exceptions and exception handling in FrameDescSetHelper bool bThreadSecurity = SecurityManager._SetThreadSecurity(false); // Check Reduction try { permSet = GetPermitOnly(fDeclarative); if (permSet != null) { CodeAccessPermission perm = (CodeAccessPermission)permSet.GetPermission(demand); // If the permit only set does not contain the demanded permission, throw a security exception if (perm == null) { if (!permSet.IsUnrestricted()) { throw new SecurityException(String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), null, permSet, SecurityRuntime.GetMethodInfo(rmh), demand, demand); } } else { bool bNeedToThrow = true; try { bNeedToThrow = !demand.CheckPermitOnly(perm); } catch (ArgumentException) { } if (bNeedToThrow) { throw new SecurityException(String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), null, permSet, SecurityRuntime.GetMethodInfo(rmh), demand, demand); } } } // Check Denials permSet = GetDenials(fDeclarative); if (permSet != null) { CodeAccessPermission perm = (CodeAccessPermission)permSet.GetPermission(demand); // If an unrestricted set was denied and the demand implements IUnrestricted if (permSet.IsUnrestricted()) { throw new SecurityException(String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), permSet, null, SecurityRuntime.GetMethodInfo(rmh), demand, demand); } // If the deny set does contain the demanded permission, throw a security exception bool bNeedToThrow = true; try { bNeedToThrow = !demand.CheckDeny(perm); } catch (ArgumentException) { } if (bNeedToThrow) { throw new SecurityException(String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("Security_Generic"), demand.GetType().AssemblyQualifiedName), permSet, null, SecurityRuntime.GetMethodInfo(rmh), demand, demand); } } if (GetAssertAllPossible()) { return(SecurityRuntime.StackHalt); } permSet = GetAssertions(fDeclarative); // Check Assertions if (permSet != null) { CodeAccessPermission perm = (CodeAccessPermission)permSet.GetPermission(demand); // If the assert set does contain the demanded permission, halt the stackwalk try { if (permSet.IsUnrestricted() || demand.CheckAssert(perm)) { return(SecurityRuntime.StackHalt); } } catch (ArgumentException) { } } } finally { if (bThreadSecurity) { SecurityManager._SetThreadSecurity(true); } } return(SecurityRuntime.StackContinue); }
internal bool CheckSetDemandWithModification(PermissionSet pset, out PermissionSet alteredDemandSet, RuntimeMethodHandleInternal rmh) { bool bRet = SecurityRuntime.StackContinue; PermissionSet demandSet = pset; alteredDemandSet = null; if (m_permSetTriples != null) { for (int i=0; (i < m_permSetTriples.Count && bRet != SecurityRuntime.StackHalt) ; i++) { PermissionSetTriple psTriple = (PermissionSetTriple)m_permSetTriples[i]; bRet = psTriple.CheckSetDemand(demandSet, out alteredDemandSet, rmh); if (alteredDemandSet != null) demandSet = alteredDemandSet; } } else if (m_firstPermSetTriple != null) { bRet = m_firstPermSetTriple.CheckSetDemand(demandSet, out alteredDemandSet, rmh); } return bRet; }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand(PermissionSet pset , RuntimeMethodHandleInternal rmh) { PermissionSet unused; CheckSetDemandWithModification(pset, out unused, rmh); return SecurityRuntime.StackHalt; // CS demand check always terminates the stackwalk }
internal bool CheckSetDemand(PermissionSet demandSet, out PermissionSet alteredDemandset, RuntimeMethodHandleInternal rmh) { alteredDemandset = (PermissionSet)null; if (!PermissionSetTriple.CheckAssert(this.AssertSet, demandSet, out alteredDemandset)) { return(false); } if (alteredDemandset != null) { demandSet = alteredDemandset; } CodeAccessSecurityEngine.CheckSetHelper(this.GrantSet, this.RefusedSet, demandSet, rmh, (object)null, SecurityAction.Demand, true); return(true); }
private static extern void InternalPrelink(RuntimeMethodHandleInternal m);
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { CompleteConstruction(null); if (PLS == null) return SecurityRuntime.StackHalt; else { PLS.CheckDemand(demand, permToken, rmh); return SecurityRuntime.StackHalt; // CS demand check always terminates the stackwalk } }
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { bool bRet = SecurityRuntime.StackContinue; if (m_permSetTriples != null) { for (int i=0; (i < m_permSetTriples.Count && bRet != SecurityRuntime.StackHalt) ; i++) { PermissionSetTriple psTriple = (PermissionSetTriple)m_permSetTriples[i]; bRet = psTriple.CheckDemand(demand, permToken, rmh); } } else if (m_firstPermSetTriple != null) { bRet = m_firstPermSetTriple.CheckDemand(demand, permToken, rmh); } return SecurityRuntime.StackHalt; // CS demand check always terminates the stackwalk }
[System.Security.SecurityCritical] // auto-generated private static unsafe RuntimeMethodInfo AssignAssociates( int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } Contract.Assert(declaredType != null); Contract.Assert(reflectedType != null); bool isInherited = declaredType != reflectedType; IntPtr[] genericArgumentHandles = null; int genericArgumentCount = 0; RuntimeType [] genericArguments = declaredType.GetTypeHandleInternal().GetInstantiationInternal(); if (genericArguments != null) { genericArgumentCount = genericArguments.Length; genericArgumentHandles = new IntPtr[genericArguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { genericArgumentHandles[i] = genericArguments[i].GetTypeHandleInternal().Value; } } RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, genericArgumentCount, null, 0); Contract.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token"); if (isInherited) { MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle); // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility //(ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled [CLS]" // Consequently, a property may be composed of public and private methods. If the declared type != // the reflected type, the private methods should not be exposed. Note that this implies that the // identity of a property includes it's reflected type. // NetCF actually includes private methods from parent classes in Reflection results // We will mimic that in Mango Compat mode. if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) { if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } } // Note this is the first time the property was encountered walking from the most derived class // towards the base class. It would seem to follow that any associated methods would not // be overriden -- but this is not necessarily true. A more derived class may have overriden a // virtual method associated with a property in a base class without associating the override with // the same or any property in the derived class. if ((methAttr & MethodAttributes.Virtual) != 0) { bool declaringTypeIsClass = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class; // It makes no sense to search for a virtual override of a method declared on an interface. if (declaringTypeIsClass) { int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle); // Find the override visible from the reflected type associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } } RuntimeMethodInfo associateMethod = RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo; // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle if (associateMethod == null) { associateMethod = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo; } return(associateMethod); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { // imperative security bool fContinue = CheckDemand2(demand, permToken, rmh, false); if (fContinue == SecurityRuntime.StackContinue) { // declarative security fContinue = CheckDemand2(demand, permToken, rmh, true); } return(fContinue); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemandWithModificationNoHalt(PermissionSet pset, out PermissionSet alteredDemandSet, RuntimeMethodHandleInternal rmh) { alteredDemandSet = null; CompleteConstruction(null); if (PLS == null) return SecurityRuntime.StackContinue; else return PLS.CheckSetDemandWithModification(pset, out alteredDemandSet, rmh); }
private static RuntimeMethodInfo?AssignAssociates( int tkMethod, RuntimeType declaredType, RuntimeType reflectedType) { if (MetadataToken.IsNullToken(tkMethod)) { return(null); } Debug.Assert(declaredType != null); Debug.Assert(reflectedType != null); bool isInherited = declaredType != reflectedType; Span <IntPtr> genericArgumentHandles = stackalloc IntPtr[0]; RuntimeType[] genericArguments = declaredType.TypeHandle.GetInstantiationInternal(); if (genericArguments != null) { genericArgumentHandles = genericArguments.Length <= 16 ? // arbitrary stackalloc limit stackalloc IntPtr[genericArguments.Length] : new IntPtr[genericArguments.Length]; for (int i = 0; i < genericArguments.Length; i++) { genericArgumentHandles[i] = genericArguments[i].TypeHandle.Value; } } RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternal(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, default); Debug.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token"); if (isInherited) { MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle); // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility // (ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled [CLS]" // Consequently, a property may be composed of public and private methods. If the declared type != // the reflected type, the private methods should not be exposed. Note that this implies that the // identity of a property includes it's reflected type. if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) { return(null); } // Note this is the first time the property was encountered walking from the most derived class // towards the base class. It would seem to follow that any associated methods would not // be overriden -- but this is not necessarily true. A more derived class may have overriden a // virtual method associated with a property in a base class without associating the override with // the same or any property in the derived class. if ((methAttr & MethodAttributes.Virtual) != 0) { bool declaringTypeIsClass = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class; // It makes no sense to search for a virtual override of a method declared on an interface. if (declaringTypeIsClass) { int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle); // Find the override visible from the reflected type associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot); } } } RuntimeMethodInfo?associateMethod = RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo; // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle return(associateMethod ?? reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand2(PermissionSet demandSet, out PermissionSet alteredDemandSet, RuntimeMethodHandleInternal rmh, bool fDeclarative) { PermissionSet permSet; // In the common case we are not going to alter the demand set, so just to // be safe we'll set it to null up front. alteredDemandSet = null; // There's some oddness in here to deal with exceptions. The general idea behind // this is that we need some way of dealing with custom permissions that may not // handle all possible scenarios of Union(), Intersect(), and IsSubsetOf() properly // (they don't support it, throw null reference exceptions, etc.). // An empty demand always succeeds. if (demandSet == null || demandSet.IsEmpty()) { return(SecurityRuntime.StackHalt); } if (GetPermitOnly(fDeclarative) != null) { GetPermitOnly(fDeclarative).CheckDecoded(demandSet); } if (GetDenials(fDeclarative) != null) { GetDenials(fDeclarative).CheckDecoded(demandSet); } if (GetAssertions(fDeclarative) != null) { GetAssertions(fDeclarative).CheckDecoded(demandSet); } bool bThreadSecurity = SecurityManager._SetThreadSecurity(false); try { // In the case of permit only, we define an exception to be failure of the check // and therefore we throw a security exception. permSet = GetPermitOnly(fDeclarative); if (permSet != null) { IPermission permFailed = null; bool bNeedToThrow = true; try { bNeedToThrow = !demandSet.CheckPermitOnly(permSet, out permFailed); } catch (ArgumentException) { } if (bNeedToThrow) { throw new SecurityException(Environment.GetResourceString("Security_GenericNoType"), null, permSet, SecurityRuntime.GetMethodInfo(rmh), demandSet, permFailed); } } // In the case of denial, we define an exception to be failure of the check // and therefore we throw a security exception. permSet = GetDenials(fDeclarative); if (permSet != null) { IPermission permFailed = null; bool bNeedToThrow = true; try { bNeedToThrow = !demandSet.CheckDeny(permSet, out permFailed); } catch (ArgumentException) { } if (bNeedToThrow) { throw new SecurityException(Environment.GetResourceString("Security_GenericNoType"), permSet, null, SecurityRuntime.GetMethodInfo(rmh), demandSet, permFailed); } } // The assert case is more complex. Since asserts have the ability to "bleed through" // (where part of a demand is handled by an assertion, but the rest is passed on to // continue the stackwalk), we need to be more careful in handling the "failure" case. // Therefore, if an exception is thrown in performing any operation, we make sure to keep // that permission in the demand set thereby continuing the demand for that permission // walking down the stack. if (GetAssertAllPossible()) { return(SecurityRuntime.StackHalt); } permSet = GetAssertions(fDeclarative); if (permSet != null) { // If this frame asserts a superset of the demand set we're done if (demandSet.CheckAssertion(permSet)) { return(SecurityRuntime.StackHalt); } // Determine whether any of the demand set asserted. We do this by // copying the demand set and removing anything in it that is asserted. if (!permSet.IsUnrestricted()) { PermissionSet.RemoveAssertedPermissionSet(demandSet, permSet, out alteredDemandSet); } } } finally { if (bThreadSecurity) { SecurityManager._SetThreadSecurity(true); } } return(SecurityRuntime.StackContinue); }
[System.Security.SecurityCritical] // auto-generated internal bool CheckSetDemand(PermissionSet demandSet , out PermissionSet alteredDemandset, RuntimeMethodHandleInternal rmh) { alteredDemandset = null; if (CheckAssert(AssertSet, demandSet, out alteredDemandset) == SecurityRuntime.StackHalt) return SecurityRuntime.StackHalt; if (alteredDemandset != null) demandSet = alteredDemandset; // note that this does not modify demandSet external to this function. #pragma warning disable 618 CodeAccessSecurityEngine.CheckSetHelper(GrantSet, RefusedSet, demandSet, rmh, null, SecurityAction.Demand, true); #pragma warning restore 618 return SecurityRuntime.StackContinue; }
private static bool CheckDynamicMethodHelper(DynamicResolver dynamicResolver, IPermission demandIn, PermissionToken permToken, RuntimeMethodHandleInternal rmh) { CompressedStack securityContext = dynamicResolver.GetSecurityContext(); try { return(securityContext.CheckDemandNoHalt((CodeAccessPermission)demandIn, permToken, rmh)); } catch (SecurityException ex) { throw new SecurityException(Environment.GetResourceString("Security_AnonymouslyHostedDynamicMethodCheckFailed"), (Exception)ex); } }