Beispiel #1
0
        static private void PerformSecurityCheck(Type owner, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            unsafe {
                if (owner == null || ((owner = owner.UnderlyingSystemType as RuntimeType) == null))
                {
                    throw new ArgumentNullException("owner");
                }

                // ask for ReflectionEmit permission always
                new ReflectionPermission(ReflectionPermissionFlag.ReflectionEmit).Demand();

                // get the type the call is coming from
                RuntimeTypeHandle callingType = ModuleHandle.GetCallerType(ref stackMark);

                // ask for member access if skip visibility
                if (skipVisibility)
                {
                    new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
                }
                else
                {
                    // if the call is not coming from the same class ask for member access
                    if (!callingType.Equals(owner.TypeHandle))
                    {
                        new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
                    }
                }

                // ask for control evidence if outside of the caller module
                if (!owner.Assembly.AssemblyHandle.Equals(callingType.GetAssemblyHandle()))
                {
                    new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
                }
            }
        }
Beispiel #2
0
        static private void PerformSecurityCheck(Module m, ref StackCrawlMark stackMark, bool skipVisibility)
        {
            unsafe {
                if (m == null)
                {
                    throw new ArgumentNullException("m");
                }

                // ask for ReflectionEmit permission always
                new ReflectionPermission(ReflectionPermissionFlag.ReflectionEmit).Demand();
                // ask for member access if skip visibility
                if (skipVisibility)
                {
                    new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();
                }

                // ask for control evidence if outside of the caller assembly
                RuntimeTypeHandle callingType = ModuleHandle.GetCallerType(ref stackMark);
                if (!m.Assembly.AssemblyHandle.Equals(callingType.GetAssemblyHandle()))
                {
                    new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
                }
            }
        }