コード例 #1
0
        private static bool TryProcessPermissionSetAttribute(SecurityDeclaration declaration, out PermissionSet set)
        {
            set = null;
            if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
            {
                return(false);
            }
            Mono.Cecil.SecurityAttribute item = declaration.SecurityAttributes[0];
            if (!item.AttributeType.IsTypeOf("System.Security.Permissions", "PermissionSetAttribute"))
            {
                return(false);
            }
            PermissionSetAttribute permissionSetAttribute = new PermissionSetAttribute((System.Security.Permissions.SecurityAction)declaration.Action);

            Mono.Cecil.CustomAttributeNamedArgument customAttributeNamedArgument = item.Properties[0];
            string value = (string)customAttributeNamedArgument.Argument.Value;
            string name  = customAttributeNamedArgument.Name;

            if (name == "XML")
            {
                permissionSetAttribute.XML = value;
            }
            else
            {
                if (name != "Name")
                {
                    throw new NotImplementedException(customAttributeNamedArgument.Name);
                }
                permissionSetAttribute.Name = value;
            }
            set = permissionSetAttribute.CreatePermissionSet();
            return(true);
        }
コード例 #2
0
ファイル: all.cs プロジェクト: pmq20/mono_forked
 static public int Main(string[] args)
 {
     object[] attrs = Assembly.GetExecutingAssembly().GetCustomAttributes(false);
     for (int i = 0; i < attrs.Length; i++)
     {
         if (attrs [i] is PermissionSetAttribute)
         {
             PermissionSetAttribute psa = (attrs [i] as PermissionSetAttribute);
             Console.WriteLine("{0} - {1}", psa.Action, psa.CreatePermissionSet());
         }
         else if (attrs [i] is SecurityAttribute)
         {
             SecurityAttribute sa = (attrs [i] as SecurityAttribute);
             IPermission       p  = sa.CreatePermission();
             PermissionSet     ps = new PermissionSet(PermissionState.None);
             ps.AddPermission(p);
             Console.WriteLine("{0} - {1}", sa.Action, ps);
         }
         else
         {
             Console.WriteLine(attrs [i]);
         }
     }
     return(0);
 }
コード例 #3
0
        public static PermissionSet PermissionSetFromStandardSet(StandardPermissionSet standardSet)
        {
            PermissionSetAttribute attribute = new PermissionSetAttribute(SecurityAction.Demand);

            attribute.Name = standardSet.ToString();
            return(attribute.CreatePermissionSet());
        }
コード例 #4
0
        public static PermissionSet PermissionSetFromFile(string fileName)
        {
            PermissionSetAttribute attribute = new PermissionSetAttribute(SecurityAction.Demand);

            attribute.File = fileName;
            return(attribute.CreatePermissionSet());
        }
コード例 #5
0
ファイル: sandbox.cs プロジェクト: nobled/mono
	// note: you cannot load a file directly into a PermissionSet
	// but we can hack around this by using PermissionSetAttribute ;-)
	static PermissionSet LoadFromFile (string filename)
	{
		// the SecurityAction is meaningless here
		PermissionSetAttribute psa = new PermissionSetAttribute (SecurityAction.Demand);
		psa.File = filename;
		return psa.CreatePermissionSet ();
	}
コード例 #6
0
        public void Hex_Bad()
        {
            PermissionSetAttribute a = new PermissionSetAttribute(SecurityAction.Assert);

            a.Hex = "g";
            Assert.AreEqual("g", a.Hex, "Bad Hex");
            a.CreatePermissionSet();
        }
コード例 #7
0
ファイル: sandbox.cs プロジェクト: xia13520/dnSpy-Unity-mono
    // note: you cannot load a file directly into a PermissionSet
    // but we can hack around this by using PermissionSetAttribute ;-)
    static PermissionSet LoadFromFile(string filename)
    {
        // the SecurityAction is meaningless here
        PermissionSetAttribute psa = new PermissionSetAttribute(SecurityAction.Demand);

        psa.File = filename;
        return(psa.CreatePermissionSet());
    }
コード例 #8
0
        private void Unification(string xml)
        {
            PermissionSetAttribute psa = new PermissionSetAttribute(SecurityAction.Assert);

            psa.XML = xml;
            string pset           = psa.CreatePermissionSet().ToString();
            string currentVersion = typeof(string).Assembly.GetName().Version.ToString();

            Assert.IsTrue((pset.IndexOf(currentVersion) > 0), currentVersion);
        }
コード例 #9
0
        public void Hex_ASCII_Permission()
        {
            SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.Assertion);
            PermissionSet      ps = new PermissionSet(PermissionState.None);

            ps.AddPermission(sp);

            PermissionSetAttribute a = new PermissionSetAttribute(SecurityAction.Assert);

            a.Hex = "3C5065726D697373696F6E53657420636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E536574220D0A76657273696F6E3D2231223E0D0A3C495065726D697373696F6E20636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E732E53656375726974795065726D697373696F6E2C206D73636F726C69622C2056657273696F6E3D322E302E333630302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D62373761356335363139333465303839220D0A76657273696F6E3D2231220D0A466C6167733D22417373657274696F6E222F3E0D0A3C2F5065726D697373696F6E5365743E0D0A";
            PermissionSet psa = a.CreatePermissionSet();

            Assert.IsTrue(ps.Equals(psa), "HEX-ASCII");
        }
コード例 #10
0
        public void Unrestricted()
        {
            PermissionSetAttribute a = new PermissionSetAttribute(SecurityAction.Assert);

            a.Unrestricted = true;
            Assert.IsNull(a.File, "File");
            Assert.IsNull(a.Hex, "Hex");
            Assert.IsNull(a.Name, "Name");
            Assert.IsNull(a.XML, "XML");

            PermissionSet ps = a.CreatePermissionSet();

            Assert.IsTrue(ps.IsUnrestricted(), "CreatePermissionSet.IsUnrestricted");
        }
コード例 #11
0
        public void Hex_BigEndianUnicode_Permission()
        {
            SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.Assertion);
            PermissionSet      ps = new PermissionSet(PermissionState.None);

            ps.AddPermission(sp);

            PermissionSetAttribute a = new PermissionSetAttribute(SecurityAction.Assert);

            a.UnicodeEncoded = true;
            a.Hex            = "003C005000650072006D0069007300730069006F006E00530065007400200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0053006500740022000D000A00760065007200730069006F006E003D002200310022003E000D000A003C0049005000650072006D0069007300730069006F006E00200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0073002E00530065006300750072006900740079005000650072006D0069007300730069006F006E002C0020006D00730063006F0072006C00690062002C002000560065007200730069006F006E003D0032002E0030002E0033003600300030002E0030002C002000430075006C0074007500720065003D006E00650075007400720061006C002C0020005000750062006C00690063004B006500790054006F006B0065006E003D00620037003700610035006300350036003100390033003400650030003800390022000D000A00760065007200730069006F006E003D002200310022000D000A0046006C006100670073003D00220041007300730065007200740069006F006E0022002F003E000D000A003C002F005000650072006D0069007300730069006F006E005300650074003E000D000";
            PermissionSet psbeu = a.CreatePermissionSet();

            Assert.IsTrue(ps.Equals(psbeu), "HEX-BIGENDIAN-UNICODE");
        }
コード例 #12
0
        public void Default()
        {
            PermissionSetAttribute a = new PermissionSetAttribute(SecurityAction.Assert);

            Assert.IsNull(a.File, "File");
#if NET_2_0
            Assert.IsNull(a.Hex, "Hex");
#endif
            Assert.IsNull(a.Name, "Name");
            Assert.IsNull(a.XML, "XML");
            Assert.IsFalse(a.UnicodeEncoded, "UnicodeEncoded");
            Assert.AreEqual(a.ToString(), a.TypeId.ToString(), "TypeId");
            Assert.IsFalse(a.Unrestricted, "Unrestricted");

            IPermission perm = a.CreatePermission();
            Assert.IsNull(perm, "CreatePermission");

            PermissionSet ps = a.CreatePermissionSet();
            Assert.AreEqual(0, ps.Count, "CreatePermissionSet");
        }
コード例 #13
0
 public static void PermissionSetAttributeCallMethods()
 {
     PermissionSetAttribute psa = new PermissionSetAttribute(new Permissions.SecurityAction());
     IPermission            ip  = psa.CreatePermission();
     PermissionSet          ps  = psa.CreatePermissionSet();
 }
コード例 #14
0
 public static void PermissionSetAttributeCallMethods()
 {
     PermissionSetAttribute psa = new PermissionSetAttribute(new Permissions.SecurityAction());
     IPermission ip = psa.CreatePermission();
     PermissionSet ps = psa.CreatePermissionSet();
 }