Exemple #1
0
        public void OnStartElement(string name, SmallXmlParser.IAttrList attrs)
        {
            SecurityElement newel = new SecurityElement(name);

            if (root == null)
            {
                root = newel;
                current = newel;

            }
            else
            {
                SecurityElement parent = (SecurityElement)stack.Peek();
                parent.AddChild(newel);
            }

            stack.Push(newel);
            current = newel;
            // attributes
            int n = attrs.Length;

            for (int i = 0; i < n; i++)
            {
                string attrName = SecurityElement.Escape(attrs.GetName(i));
                string attrValue = SecurityElement.Escape(attrs.GetValue(i));
                current.AddAttribute(attrName, attrValue);
            }
        }
 private static SecurityElement CreateDefaultApplicationTrustManagerElement()
 {
     SecurityElement element = new SecurityElement("IApplicationTrustManager");
     element.AddAttribute("class", "System.Security.Policy.TrustManager, System.Windows.Forms, Version=" + ((RuntimeAssembly) Assembly.GetExecutingAssembly()).GetVersion() + ", Culture=neutral, PublicKeyToken=b77a5c561934e089");
     element.AddAttribute("version", "1");
     return element;
 }
 public void ConvertElement(SecurityElement elCurrent, ref int position)
 {
     this.AddToken(1, ref position);
     this.AddString(elCurrent.m_strTag, ref position);
     if (elCurrent.m_lAttributes != null)
     {
         for (int i = 0; i < elCurrent.m_lAttributes.Count; i += 2)
         {
             this.AddToken(2, ref position);
             this.AddString((string) elCurrent.m_lAttributes[i], ref position);
             this.AddString((string) elCurrent.m_lAttributes[i + 1], ref position);
         }
     }
     if (elCurrent.m_strText != null)
     {
         this.AddToken(3, ref position);
         this.AddString(elCurrent.m_strText, ref position);
     }
     if (elCurrent.InternalChildren != null)
     {
         for (int j = 0; j < elCurrent.InternalChildren.Count; j++)
         {
             this.ConvertElement((SecurityElement) elCurrent.Children[j], ref position);
         }
     }
     this.AddToken(4, ref position);
 }
Exemple #4
0
		// snippet moved from FileIOPermission (nickd) to be reused in all derived classes
		internal static SecurityElement Element (Type type, int version) 
		{
			SecurityElement se = new SecurityElement ("IPermission");
			se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\''));
			se.AddAttribute ("version", version.ToString ());
			return se;
		}
Exemple #5
0
		public void FromXml(System.Security.SecurityElement e)
		{
			// FIXME: falta ter em conta mClassName

			if (e.Attribute(ClassAttr) != this.GetType().AssemblyQualifiedName)
			{
				throw new ArgumentException("SecurityElement class is incorrect.");
			}
			if (e.Attribute(VersionAttr) != Version)
			{
				throw new ArgumentException("SecurityElement version is incorrect.");
			}
			ArrayList fo = new ArrayList();
			foreach (SecurityElement c in e.Children)
			{
				if (c.Tag != InternalTag)
				{
					throw new ArgumentException("SecurityElement child is incorrect.");
				}
				if (c.Attribute(ClassAttr) != typeof(string).AssemblyQualifiedName)
				{
					throw new ArgumentException("SecurityElement child class is incorrect.");
				}
				if (c.Attribute(VersionAttr) != Version)
				{
					throw new ArgumentException("SecurityElement child version is incorrect.");
				}
				fo.Add(c.Attribute(ValueAttr));
			}
			this.mOperations = new string[fo.Count];
			fo.CopyTo(this.mOperations);
		}
	public void Constructor_SecurityElement_Empty () 
	{
		// (empty) SecurityElement constructor
		SecurityElement se = new SecurityElement ("xml");
		SignatureDescription sig = new SignatureDescription (se);
		AssertNotNull ("SignatureDescription(SecurityElement)", sig);
	}
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(S._("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				value = esd.Attribute("Level");
				if(value != null)
				{
					level = (PrintingPermissionLevel)
						Enum.Parse(typeof(PrintingPermissionLevel), value);
				}
				else
				{
					level = PrintingPermissionLevel.NoPrinting;
				}
			}
Exemple #8
0
    //removePath将要删除的路径
    static public string GetFileListXMLString(List <string> fileList, string removePath)
    {
        var root = new System.Security.SecurityElement("root");

        foreach (var item in fileList)
        {
            string fileName = Path.GetFileName(item);
            string ext      = Path.GetExtension(item);
            if (string.Compare(ext, ".meta", true) == 0)
            {
                continue;
            }

            string filePath = null;
            if (IsUseAssetBundle)
            {
                filePath = item.Replace(removePath, "");
                root.AddChild(new System.Security.SecurityElement("k", fileName.ToLower()));
                root.AddChild(new System.Security.SecurityElement("v", filePath.ToLower()));
            }
            else
            {
                filePath = item.Replace(removePath, "");
                root.AddChild(new System.Security.SecurityElement("k", fileName));
                root.AddChild(new System.Security.SecurityElement("v", filePath));
            }
        }

        return(root.ToString());
    }
		public PrincipalInfo(SecurityElement elem)
				{
					name = elem.Attribute("ID");
					role = elem.Attribute("Role");
					String value = elem.Attribute("Authenticated");
					isAuthenticated = (value != null && Boolean.Parse(value));
				}
 public override void FromXml(SecurityElement esd)
 {
     if (esd == null)
     {
         throw new ArgumentNullException("esd");
     }
     string str = esd.Attribute("class");
     if ((str == null) || (str.IndexOf(base.GetType().FullName) == -1))
     {
         throw new ArgumentException(System.Drawing.SR.GetString("InvalidClassName"));
     }
     string a = esd.Attribute("Unrestricted");
     if ((a != null) && string.Equals(a, "true", StringComparison.OrdinalIgnoreCase))
     {
         this.printingLevel = PrintingPermissionLevel.AllPrinting;
     }
     else
     {
         this.printingLevel = PrintingPermissionLevel.NoPrinting;
         string str3 = esd.Attribute("Level");
         if (str3 != null)
         {
             this.printingLevel = (PrintingPermissionLevel) Enum.Parse(typeof(PrintingPermissionLevel), str3);
         }
     }
 }
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(_("Arg_PermissionVersion"));
				}
				name = esd.Attribute("Name");
				String value = esd.Attribute("Version");
				if(value != null)
				{
					version = new Version(value);
				}
				else
				{
					version = null;
				}
				value = esd.Attribute("PublicKeyBlob");
				if(value != null)
				{
					blob = new StrongNamePublicKeyBlob(value);
				}
				else
				{
					blob = null;
				}
			}
Exemple #12
0
 public virtual void FromXml(SecurityElement e)
 {
     if (e == null)
         throw new ArgumentNullException("e");
     if (e.Tag != "BzurePermission")
     {
         throw new ArgumentException("invalid tag type");
     }
     if (!(e.Attributes["class"] as string).StartsWith("Bzure.Security.Permissions.CAS.BzurePermission"))
     {
         throw new ArgumentException("invalid type");
     }
     if ((e.Attributes["version"] as string) != "1")
     {
         throw new ArgumentException("invalid version");
     }
     IDroit droit = new Droit(e.Attributes["guid"] as string);
     if (e.Children != null)
     {
         foreach (SecurityElement se in e.Children)
         {
             switch (se.Tag)
             {
                 case "accessType":
                     droit.AddAccessCode(new AccessCode(Convert.ToInt32(se.Text)));
                     break;
                 default:
                     break;
             }
         }
     }
     this._droit = droit;
 }
 internal void FromXml(SecurityElement e)
 {
     string strA = e.Attribute("Authenticated");
     if (strA != null)
     {
         this.m_authenticated = string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0;
     }
     else
     {
         this.m_authenticated = false;
     }
     string str2 = e.Attribute("ID");
     if (str2 != null)
     {
         this.m_id = str2;
     }
     else
     {
         this.m_id = null;
     }
     string str3 = e.Attribute("Role");
     if (str3 != null)
     {
         this.m_role = str3;
     }
     else
     {
         this.m_role = null;
     }
 }
 public SecurityElement ToXml(PolicyLevel level)
 {
     SecurityElement element = new SecurityElement("IMembershipCondition");
     XMLUtil.AddClassAttribute(element, base.GetType(), "System.Security.Policy.AllMembershipCondition");
     element.AddAttribute("version", "1");
     return element;
 }
Exemple #15
0
        public override ArrayList getXmlNodeList(SecurityElement config, string itemNode)
        {
            ArrayList itemNodeList = new ArrayList();
            UtilXml.getXmlChildList(config, itemNode, ref itemNodeList);

            return itemNodeList;
        }
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(_("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				value = esd.Attribute("Access");
				if(value != null)
				{
					flags = (FileDialogPermissionAccess)
						Enum.Parse(typeof(FileDialogPermissionAccess), value);
				}
				else
				{
					flags = FileDialogPermissionAccess.None;
				}
			}
Exemple #17
0
 private object ChangeType(PropertyInfo propertyInfo, SecurityElement e)
 {
     var typePropertyEditorIsUsed = propertyInfo.PropertyType==typeof (Type);
     if (!typePropertyEditorIsUsed)
         return ReflectorHelper.ChangeType(e.Attributes[propertyInfo.Name].ToString().XMLDecode(), propertyInfo.PropertyType);
     return string.IsNullOrEmpty(e.Attributes[propertyInfo.Name].ToString())? null: XafTypesInfo.Instance.FindTypeInfo(e.Attributes[propertyInfo.Name].ToString()).Type;
 }
 public override void FromXml(SecurityElement esd)
 {
     CodeAccessPermission.ValidateElement(esd, this);
     this.m_allowed = IsolatedStorageContainment.None;
     if (XMLUtil.IsUnrestricted(esd))
     {
         this.m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
     }
     else
     {
         string str = esd.Attribute("Allowed");
         if (str != null)
         {
             this.m_allowed = (IsolatedStorageContainment) Enum.Parse(typeof(IsolatedStorageContainment), str);
         }
     }
     if (this.m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage)
     {
         this.m_userQuota = 0x7fffffffffffffffL;
         this.m_machineQuota = 0x7fffffffffffffffL;
         this.m_expirationDays = 0x7fffffffffffffffL;
         this.m_permanentData = true;
     }
     else
     {
         string s = esd.Attribute("UserQuota");
         this.m_userQuota = (s != null) ? long.Parse(s, CultureInfo.InvariantCulture) : 0L;
         s = esd.Attribute("MachineQuota");
         this.m_machineQuota = (s != null) ? long.Parse(s, CultureInfo.InvariantCulture) : 0L;
         s = esd.Attribute("Expiry");
         this.m_expirationDays = (s != null) ? long.Parse(s, CultureInfo.InvariantCulture) : 0L;
         s = esd.Attribute("Permanent");
         this.m_permanentData = (s != null) ? bool.Parse(s) : false;
     }
 }
Exemple #19
0
    //在生成资源包时使用
    static public string SerializeInEditor(List <ResInfo> listResInfo)
    {
        string      innerText        = MyFileUtil.ReadConfigDataInStreamingAssets(VersionManager.VersionInfoFilePath);
        VersionInfo innerVersionInfo = VersionInfo.ParseData(innerText);

        var root = new System.Security.SecurityElement("root");

        root.AddChild(new System.Security.SecurityElement("ProgramVersion", innerVersionInfo.ProgramVersion.ToString()));
        root.AddChild(new System.Security.SecurityElement("ApkUrl", innerVersionInfo.ApkUrl));
        root.AddChild(new System.Security.SecurityElement("ApkMd5"));
        root.AddChild(new System.Security.SecurityElement("IOSAppUrl", innerVersionInfo.IOSAppUrl));
        root.AddChild(new System.Security.SecurityElement("IOSAppStoreUrl", innerVersionInfo.IOSAppStoreUrl));
        root.AddChild(new System.Security.SecurityElement("IsAppleAppStore", innerVersionInfo.IsAppleAppStore.ToString()));
        root.AddChild(new System.Security.SecurityElement("IsOpenAutoUpdateInAppStore", innerVersionInfo.IsOpenAutoUpdateInAppStore.ToString()));
        root.AddChild(new System.Security.SecurityElement("IsForceToUpdate", innerVersionInfo.IsForceToUpdate.ToString()));
        var resInfoNode = new System.Security.SecurityElement("ResInfo");

        root.AddChild(resInfoNode);

        foreach (var item in listResInfo)
        {
            var recordNode = new System.Security.SecurityElement("Record");
            resInfoNode.AddChild(recordNode);

            recordNode.AddChild(new System.Security.SecurityElement("ResName", item.resName));
            recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.resMD5));
            recordNode.AddChild(new System.Security.SecurityElement("ResURL", item.resURL));
            recordNode.AddChild(new System.Security.SecurityElement("ResSize", item.resSize.ToString()));
            recordNode.AddChild(new System.Security.SecurityElement("ResRequire", "true"));
            recordNode.AddChild(new System.Security.SecurityElement("resRequireID", item.resRequireID.ToString()));
        }

        return(root.ToString());
    }
Exemple #20
0
 private SecurityElement ToXml()
 {
     SecurityElement root = new SecurityElement("System.Xml.XmlSecureResolver");
     root.AddAttribute("version", "1");
     root.AddChild(new SecurityElement("UncDirectory", _uncDir));
     return root;
 }
Exemple #21
0
        public override void FromXml(SecurityElement esd)
        {
            CodeAccessPermission.ValidateElement(esd, this);

            String et;

            if (XMLUtil.IsUnrestricted(esd))
            {
                m_unrestricted = true;
                return;
            }

            m_unrestricted = false;
            m_read         = null;
            m_write        = null;

            et = esd.Attribute("Read");
            if (et != null)
            {
                m_read = new EnvironmentStringExpressionSet(et);
            }

            et = esd.Attribute("Write");
            if (et != null)
            {
                m_write = new EnvironmentStringExpressionSet(et);
            }
        }
	// Convert an XML element into a permission object.
	public override void FromXml(SecurityElement securityElement)
			{
				String value;
				if(securityElement == null)
				{
					throw new ArgumentNullException("securityElement");
				}
				if(securityElement.Attribute("version") != "1")
				{
					throw new ArgumentException
						(S._("Arg_PermissionVersion"));
				}
				value = securityElement.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					level = AspNetHostingPermissionLevel.Unrestricted;
				}
				else
				{
					value = securityElement.Attribute("Level");
					if(value != null)
					{
						level = (AspNetHostingPermissionLevel)
							Enum.Parse(typeof(AspNetHostingPermissionLevel),
							           value);
					}
					else
					{
						level = AspNetHostingPermissionLevel.None;
					}
				}
			}
	// Convert an XML value into a permissions value.
	public override void FromXml(SecurityElement esd)
			{
				String value;
				if(esd == null)
				{
					throw new ArgumentNullException("esd");
				}
				if(esd.Attribute("version") != "1")
				{
					throw new ArgumentException(_("Arg_PermissionVersion"));
				}
				value = esd.Attribute("Unrestricted");
				if(value != null && Boolean.Parse(value))
				{
					state = PermissionState.Unrestricted;
				}
				else
				{
					state = PermissionState.None;
				}
				if(state != PermissionState.Unrestricted)
				{
					readList = EnvironmentPermission.SplitPath
						(esd.Attribute("Read"), ';');
					writeList = EnvironmentPermission.SplitPath
						(esd.Attribute("Write"), ';');
					createList = EnvironmentPermission.SplitPath
						(esd.Attribute("Create"), ';');
				}
			}
 internal static SecurityElement CreatePermissionElement(IPermission perm, string permname)
 {
     SecurityElement element = new SecurityElement("IPermission");
     XMLUtil.AddClassAttribute(element, perm.GetType(), permname);
     element.AddAttribute("version", "1");
     return element;
 }
 internal SecurityElement ToXml()
 {
     SecurityElement element2;
     SecurityElement element = new SecurityElement("System.Security.Policy.PermissionRequestEvidence");
     element.AddAttribute("version", "1");
     if (this.m_request != null)
     {
         element2 = new SecurityElement("Request");
         element2.AddChild(this.m_request.ToXml());
         element.AddChild(element2);
     }
     if (this.m_optional != null)
     {
         element2 = new SecurityElement("Optional");
         element2.AddChild(this.m_optional.ToXml());
         element.AddChild(element2);
     }
     if (this.m_denied != null)
     {
         element2 = new SecurityElement("Denied");
         element2.AddChild(this.m_denied.ToXml());
         element.AddChild(element2);
     }
     return element;
 }
 public override void FromXml(SecurityElement securityElement)
 {
     if (securityElement == null)
     {
         throw new ArgumentNullException("securityElement");
     }
     string str = securityElement.Attribute("class");
     if ((str == null) || (str.IndexOf(base.GetType().FullName, StringComparison.Ordinal) == -1))
     {
         throw new ArgumentException(SecurityResources.GetResourceString("Argument_InvalidClassAttribute"), "securityElement");
     }
     string strA = securityElement.Attribute("Unrestricted");
     if ((strA != null) && (string.Compare(strA, "true", StringComparison.OrdinalIgnoreCase) == 0))
     {
         this.m_flags = DataProtectionPermissionFlags.AllFlags;
     }
     else
     {
         this.m_flags = DataProtectionPermissionFlags.NoFlags;
         string str3 = securityElement.Attribute("Flags");
         if (str3 != null)
         {
             DataProtectionPermissionFlags flags = (DataProtectionPermissionFlags) Enum.Parse(typeof(DataProtectionPermissionFlags), str3);
             VerifyFlags(flags);
             this.m_flags = flags;
         }
     }
 }
Exemple #27
0
		public SecurityElement ToXml ()
		{
			SecurityElement se = new SecurityElement (tag);
			se.AddAttribute ("class", typeof (MonoTrustManager).AssemblyQualifiedName);
			se.AddAttribute ("version", "1");
			return se;
		}
 public override void FromXml(SecurityElement securityElement)
 {
     if (securityElement == null)
     {
         throw new ArgumentNullException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (!securityElement.Tag.Equals("IPermission"))
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     string str = securityElement.Attribute("class");
     if (str == null)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (str.IndexOf(base.GetType().FullName, StringComparison.Ordinal) < 0)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (string.Compare(securityElement.Attribute("version"), "1", StringComparison.OrdinalIgnoreCase) != 0)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "version" }));
     }
     string str3 = securityElement.Attribute("Level");
     if (str3 == null)
     {
         this._level = AspNetHostingPermissionLevel.None;
     }
     else
     {
         this._level = (AspNetHostingPermissionLevel) Enum.Parse(typeof(AspNetHostingPermissionLevel), str3);
     }
 }
		public override void FromXml (SecurityElement securityElement)
		{
			PermissionHelper.CheckSecurityElement (securityElement, "securityElement", version, version);
			if (securityElement.Tag != "IPermission") {
				string msg = Locale.GetText ("Invalid tag '{0}' for permission.");
				throw new ArgumentException (String.Format (msg, securityElement.Tag), "securityElement");
			}
			if (securityElement.Attribute ("version") == null) {
				string msg = Locale.GetText ("Missing version attribute.");
				throw new ArgumentException (msg, "securityElement");
			}

			if (PermissionHelper.IsUnrestricted (securityElement)) {
				// in case it's get fixed later...
				_level = AspNetHostingPermissionLevel.Unrestricted;
			}
			else {
				string level = securityElement.Attribute ("Level");
				if (level != null) {
					_level = (AspNetHostingPermissionLevel) Enum.Parse (
						typeof (AspNetHostingPermissionLevel), level);
				}
				else
					_level = AspNetHostingPermissionLevel.None;
			}
		}
Exemple #30
0
 private byte[] GetNamedParam(SecurityElement se, string param)
 {
     SecurityElement sep = se.SearchForChildByTag(param);
     if (sep == null)
         return null;
     return Convert.FromBase64String(sep.Text);
 }
Exemple #31
0
		internal static int CheckSecurityElement (SecurityElement se, string parameterName, int minimumVersion, int maximumVersion) 
		{
			if (se == null)
				throw new ArgumentNullException (parameterName);

			if (se.Tag != "IPermission") {
				string msg = Locale.GetText ("Invalid tag '{0}' expected 'IPermission'.");
				throw new ArgumentException (String.Format (msg, se.Tag), parameterName);
			}

			// we assume minimum version if no version number is supplied
			int version = minimumVersion;
			string v = se.Attribute ("version");
			if (v != null) {
				try {
					version = Int32.Parse (v);
				}
				catch (Exception e) {
					string msg = Locale.GetText ("Couldn't parse version from '{0}'.");
					msg = String.Format (msg, v);
					throw new ArgumentException (msg, parameterName, e);
				}
			}

			if ((version < minimumVersion) || (version > maximumVersion)) {
				string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}'].");
				msg = String.Format (msg, version, minimumVersion, maximumVersion);
				throw new ArgumentException (msg, parameterName);
			}
			return version;
		}
        public SecurityDocument( SecurityElement elRoot )
        {
            m_data = new byte[c_growthSize];

            int position = 0;
            ConvertElement( elRoot, ref position );
        }
		public void LoadXml (string xml) 
		{
			root = null;
			xmldoc = xml;
			pos = 0;
			stack.Clear ();
			Parse (this, this);
		}
        public ReadOnlyPermissionSet(SecurityElement permissionSetXml)
        {
            if (permissionSetXml == null)
                throw new ArgumentNullException("permissionSetXml"); 

            m_originXml = permissionSetXml.Copy(); 
            base.FromXml(m_originXml); 
        }
    private void SaveVersion(VersionManagerInfo version)
    {
        var props = typeof(VersionManagerInfo).GetProperties();
        var root  = new System.Security.SecurityElement("root");

        foreach (var item in props)
        {
            root.AddChild(new System.Security.SecurityElement(item.Name, item.GetGetMethod().Invoke(version, null) as String));
        }
        XMLParser.SaveText(SystemConfig.VersionPath, root.ToString());
    }
Exemple #36
0
 public override void FromXml(System.Security.SecurityElement element)
 {
     items.Clear();
     if (element.Children != null)
     {
         if (element.Children.Count != 1)
         {
             throw new InvalidOperationException();
         }
         SecurityElement childElement = (SecurityElement)element.Children[0];
         ObjectType = ReflectionHelper.FindType(childElement.Attributes["ObjectType"].ToString());
         Operation  = (MemberOperation)Enum.Parse(typeof(MemberOperation), childElement.Attributes["Operation"].ToString());
         Modifier   = (ObjectAccessModifier)Enum.Parse(typeof(ObjectAccessModifier), childElement.Attributes["Modifier"].ToString());
         MemberName = childElement.Attributes["MemberName"].ToString();
     }
 }
Exemple #37
0
    //序列化为字符串
    static public string Serialize(VersionInfo versionInfo)
    {
        var root = new System.Security.SecurityElement("root");

        root.AddChild(new System.Security.SecurityElement("ProgramVersion", versionInfo.ProgramVersion.ToString()));
        var resInfoNode = new System.Security.SecurityElement("ResInfo");

        root.AddChild(resInfoNode);

        foreach (var item in versionInfo.dictRes)
        {
            var recordNode = new System.Security.SecurityElement("Record");
            resInfoNode.AddChild(recordNode);

            recordNode.AddChild(new System.Security.SecurityElement("ResName", item.Value.resName));
            recordNode.AddChild(new System.Security.SecurityElement("ResMD5", item.Value.resMD5));
        }

        return(root.ToString());
    }
Exemple #38
0
        public override SecurityElement ToXml()
        {
            SecurityElement esd = CodeAccessPermission.CreatePermissionElement(this, "System.Security.Permissions.EnvironmentPermission");

            if (!IsUnrestricted())
            {
                if (this.m_read != null && !this.m_read.IsEmpty())
                {
                    esd.AddAttribute("Read", SecurityElement.Escape(m_read.ToString()));
                }
                if (this.m_write != null && !this.m_write.IsEmpty())
                {
                    esd.AddAttribute("Write", SecurityElement.Escape(m_write.ToString()));
                }
            }
            else
            {
                esd.AddAttribute("Unrestricted", "true");
            }
            return(esd);
        }
    /// <summary>
    /// 返回线上连上的5个点
    /// </summary>
    /// <returns>The points.</returns>
    /// <param name="index">Index.</param>
    protected int[] LinePoints(int index)
    {
        int[] iconIndex = new int[5];
        //返回线上连上的5个点
        SecurityParser sp      = new SecurityParser();
        string         xmlPath = "XMLData/GameSlot";

        Object xml = Resources.Load(xmlPath);

        sp.LoadXml(xml.ToString());
        System.Security.SecurityElement se = sp.ToXml();
        foreach (System.Security.SecurityElement child in se.Children)
        {
            if (int.Parse(child.Attribute("id")) == index)
            {
                iconIndex[0] = int.Parse(child.Attribute("offset1")) - 1;
                iconIndex[1] = int.Parse(child.Attribute("offset2")) - 1;
                iconIndex[2] = int.Parse(child.Attribute("offset3")) - 1;
                iconIndex[3] = int.Parse(child.Attribute("offset4")) - 1;
                iconIndex[4] = int.Parse(child.Attribute("offset5")) - 1;
            }
        }
        return(iconIndex);
    }
Exemple #40
0
    public static int[] AnimationConversion(int index, int form)
    {
        int[] iconIndex = new int[5];
        //返回线上连上的5个点
        SecurityParser sp      = new SecurityParser();
        string         xmlPath = "XMLData/GameSlot";

        Object xml = Resources.Load(xmlPath);

        sp.LoadXml(xml.ToString());
        System.Security.SecurityElement se = sp.ToXml();
        foreach (System.Security.SecurityElement child in se.Children)
        {
            if (int.Parse(child.Attribute("id")) == index)
            {
                iconIndex [0] = int.Parse(child.Attribute("offset1")) - 1;
                iconIndex [1] = int.Parse(child.Attribute("offset2")) - 1;
                iconIndex [2] = int.Parse(child.Attribute("offset3")) - 1;
                iconIndex [3] = int.Parse(child.Attribute("offset4")) - 1;
                iconIndex [4] = int.Parse(child.Attribute("offset5")) - 1;
            }
        }
        //根据form来返回需要播放特效的点
        //左 3,左4,右3,右4,全部
        switch (form)
        {
        case 1:
            showIconEffectIcon = new int[3];
            for (int i = 0; i < 3; i++)
            {
                showIconEffectIcon [i] = iconIndex [i];
            }
            break;

        case 2:
            showIconEffectIcon = new int[3];
            for (int i = 0; i < 3; i++)
            {
                showIconEffectIcon [i] = iconIndex [i + 2];
            }
            break;

        case 3:
            showIconEffectIcon = new int[4];
            for (int i = 0; i < 4; i++)
            {
                showIconEffectIcon [i] = iconIndex [i];
            }
            break;

        case 4:
            showIconEffectIcon = new int[4];
            for (int i = 0; i < 4; i++)
            {
                showIconEffectIcon [i] = iconIndex [i + 1];
            }
            break;

        case 5:
            showIconEffectIcon = new int[5];
            for (int i = 0; i < 5; i++)
            {
                showIconEffectIcon [i] = iconIndex [i];
            }
            break;

        default:
            break;
        }

        return(showIconEffectIcon);
    }
Exemple #41
0
    public static string GetXMLListContent <T>(string path, List <T> data, string attrName = "record")
    {
        try
        {
            var root  = new System.Security.SecurityElement("root");
            var props = typeof(T).GetProperties();
            foreach (var item in data)
            {
                if (item == null)
                {
                    LoggerHelper.Error("null item: " + path);
                    continue;
                }
                var xml = new System.Security.SecurityElement(attrName);
                foreach (var prop in props)
                {
                    var    type   = prop.PropertyType;
                    String result = String.Empty;
                    object obj    = prop.GetGetMethod().Invoke(item, null);
                    if (obj == null)
                    {
                        LoggerHelper.Error("null obj: " + prop.Name);
                        continue;
                    }
                    //var obj = prop.GetValue(item, null);
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                    {
                        var o = typeof(Utils).GetMethod("PackMap")
                                .MakeGenericMethod(type.GetGenericArguments())
                                .Invoke(null, new object[] { obj, ':', ',' });
                        if (o != null)
                        {
                            result = o.ToString();
                        }
                        else
                        {
                            LoggerHelper.Error("null obj: " + prop.Name);
                        }
                    }
                    else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                    {
                        var o = typeof(Utils).GetMethod("PackList")
                                .MakeGenericMethod(type.GetGenericArguments())
                                .Invoke(null, new object[] { obj, ',' });

                        if (o != null)
                        {
                            result = o.ToString();
                        }
                        else
                        {
                            LoggerHelper.Error("null obj: " + prop.Name);
                        }
                    }
                    else
                    {
                        result = obj.ToString();
                    }
                    xml.AddChild(new System.Security.SecurityElement(prop.Name, result));
                }
                root.AddChild(xml);
            }
            return(root.ToString());
        }
        catch (Exception ex)
        {
            LoggerHelper.Except(ex);
            return("");
        }
    }
Exemple #42
0
        // FIXME little documentation in Fx 2.0 beta 1
        public static byte[] ConvertPermissionSet(string inFormat, byte[] inData, string outFormat)
        {
            if (inFormat == null)
            {
                throw new ArgumentNullException("inFormat");
            }
            if (outFormat == null)
            {
                throw new ArgumentNullException("outFormat");
            }
            if (inData == null)
            {
                return(null);
            }

            if (inFormat == outFormat)
            {
                return(inData);
            }

            PermissionSet ps = null;

            if (inFormat == "BINARY")
            {
                if (outFormat.StartsWith("XML"))
                {
                    using (MemoryStream ms = new MemoryStream(inData)) {
                        BinaryFormatter formatter = new BinaryFormatter();
                        ps = (PermissionSet)formatter.Deserialize(ms);
                        ms.Close();
                    }
                    string xml = ps.ToString();
                    switch (outFormat)
                    {
                    case "XML":
                    case "XMLASCII":
                        return(Encoding.ASCII.GetBytes(xml));

                    case "XMLUNICODE":
                        return(Encoding.Unicode.GetBytes(xml));
                    }
                }
            }
            else if (inFormat.StartsWith("XML"))
            {
                if (outFormat == "BINARY")
                {
                    string xml = null;
                    switch (inFormat)
                    {
                    case "XML":
                    case "XMLASCII":
                        xml = Encoding.ASCII.GetString(inData);
                        break;

                    case "XMLUNICODE":
                        xml = Encoding.Unicode.GetString(inData);
                        break;
                    }
                    if (xml != null)
                    {
                        ps = new PermissionSet(PermissionState.None);
                        ps.FromXml(SecurityElement.FromString(xml));

                        MemoryStream    ms        = new MemoryStream();
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(ms, ps);
                        ms.Close();
                        return(ms.ToArray());
                    }
                }
                else if (outFormat.StartsWith("XML"))
                {
                    string msg = String.Format(Locale.GetText("Can't convert from {0} to {1}"), inFormat, outFormat);
                    throw new XmlSyntaxException(msg);
                }
            }
            else
            {
                // unknown inFormat, returns null
                return(null);
            }
            // unknown outFormat, throw
            throw new SerializationException(String.Format(Locale.GetText("Unknown output format {0}."), outFormat));
        }
Exemple #43
0
        /// <include file='doc\SecurityElement.uex' path='docs/doc[@for="SecurityElement.Equal"]/*' />
        public bool Equal(SecurityElement other)
        {
            if (other == null)
            {
                return(false);
            }

            // Check if the tags are the same
            if (!String.Equals(m_strTag, other.m_strTag))
            {
                return(false);
            }

            // Check if the text is the same
            if (!String.Equals(m_strText, other.m_strText))
            {
                return(false);
            }

            // Check if the attributes are the same and appear in the same
            // order.

            // Maybe we can get away by only checking the number of attributes
            if (m_lAttributes == null || other.m_lAttributes == null)
            {
                if (m_lAttributes != other.m_lAttributes)
                {
                    return(false);
                }
            }
            else
            {
                if (m_lAttributes.Count != other.m_lAttributes.Count)
                {
                    return(false);
                }

                // Okay, we'll need to go through each one of them
                IEnumerator lhs = m_lAttributes.GetEnumerator();
                IEnumerator rhs = other.m_lAttributes.GetEnumerator();

                SecurityStringPair attr1, attr2;
                while (lhs.MoveNext())
                {
                    rhs.MoveNext();
                    attr1 = (SecurityStringPair)lhs.Current;
                    attr2 = (SecurityStringPair)rhs.Current;

                    // Sanity check
                    if (attr1 == null || attr2 == null)
                    {
                        return(false);
                    }

                    if (!String.Equals(attr1.m_strAttributeName, attr2.m_strAttributeName) || !String.Equals(attr1.m_strAttributeValue, attr2.m_strAttributeValue))
                    {
                        return(false);
                    }
                }
            }

            // Finally we must check the child and make sure they are
            // equal and in the same order

            // Maybe we can get away by only checking the number of children
            if (m_lChildren == null || other.m_lChildren == null)
            {
                if (m_lChildren != other.m_lChildren)
                {
                    return(false);
                }
            }
            else
            {
                if (m_lChildren.Count != other.m_lChildren.Count)
                {
                    return(false);
                }

                // Okay, we'll need to go through each one of them
                IEnumerator lhs = m_lChildren.GetEnumerator();
                IEnumerator rhs = other.m_lChildren.GetEnumerator();

                SecurityElement e1, e2;
                while (lhs.MoveNext())
                {
                    rhs.MoveNext();
                    e1 = (SecurityElement)lhs.Current;
                    e2 = (SecurityElement)rhs.Current;
                    if (e1 == null || !e1.Equal(e2))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public bool Equal(SecurityElement other)
        {
            if (other == null)
            {
                return(false);
            }

            // Check if the tags are the same
            if (!String.Equals(m_strTag, other.m_strTag))
            {
                return(false);
            }

            // Check if the text is the same
            if (!String.Equals(m_strText, other.m_strText))
            {
                return(false);
            }

            // Check if the attributes are the same and appear in the same
            // order.

            // Maybe we can get away by only checking the number of attributes
            if (m_lAttributes == null || other.m_lAttributes == null)
            {
                if (m_lAttributes != other.m_lAttributes)
                {
                    return(false);
                }
            }
            else
            {
                int iMax = m_lAttributes.Count;
                Contract.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");

                if (iMax != other.m_lAttributes.Count)
                {
                    return(false);
                }

                for (int i = 0; i < iMax; i++)
                {
                    String lhs = (String)m_lAttributes[i];
                    String rhs = (String)other.m_lAttributes[i];

                    if (!String.Equals(lhs, rhs))
                    {
                        return(false);
                    }
                }
            }

            // Finally we must check the child and make sure they are
            // equal and in the same order

            // Maybe we can get away by only checking the number of children
            if (m_lChildren == null || other.m_lChildren == null)
            {
                if (m_lChildren != other.m_lChildren)
                {
                    return(false);
                }
            }
            else
            {
                if (m_lChildren.Count != other.m_lChildren.Count)
                {
                    return(false);
                }

                this.ConvertSecurityElementFactories();
                other.ConvertSecurityElementFactories();

                // Okay, we'll need to go through each one of them
                IEnumerator lhs = m_lChildren.GetEnumerator();
                IEnumerator rhs = other.m_lChildren.GetEnumerator();

                SecurityElement e1, e2;
                while (lhs.MoveNext())
                {
                    rhs.MoveNext();
                    e1 = (SecurityElement)lhs.Current;
                    e2 = (SecurityElement)rhs.Current;
                    if (e1 == null || !e1.Equal(e2))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        public bool Equal(SecurityElement other)
        {
            if (other == null)
            {
                return(false);
            }

            if (this == other)
            {
                return(true);
            }

            if (this.text != other.text)
            {
                return(false);
            }

            if (this.tag != other.tag)
            {
                return(false);
            }

            if (this.attributes == null && other.attributes != null && other.attributes.Count != 0)
            {
                return(false);
            }

            if (other.attributes == null && this.attributes != null && this.attributes.Count != 0)
            {
                return(false);
            }

            if (this.attributes != null && other.attributes != null)
            {
                if (this.attributes.Count != other.attributes.Count)
                {
                    return(false);
                }
                foreach (SecurityAttribute sa1 in attributes)
                {
                    SecurityAttribute sa2 = other.GetAttribute(sa1.Name);
                    if ((sa2 == null) || (sa1.Value != sa2.Value))
                    {
                        return(false);
                    }
                }
            }

            if (this.children == null && other.children != null && other.children.Count != 0)
            {
                return(false);
            }

            if (other.children == null && this.children != null && this.children.Count != 0)
            {
                return(false);
            }

            if (this.children != null && other.children != null)
            {
                if (this.children.Count != other.children.Count)
                {
                    return(false);
                }
                for (int i = 0; i < this.children.Count; i++)
                {
                    if (!((SecurityElement)this.children [i]).Equal((SecurityElement)other.children [i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #46
0
 abstract public void FromXml(SecurityElement elem);
Exemple #47
0
        public override string ToString()
        {
            SecurityElement elem = ToXml();

            return(elem.ToString());
        }
Exemple #48
0
 public virtual void FromXml(SecurityElement et)
 {
 }
 /// <summary>Determines whether a string is a valid attribute name.</summary>
 /// <returns>true if the <paramref name="name" /> parameter is a valid XML attribute name; otherwise, false.</returns>
 /// <param name="name">The attribute name to test for validity. </param>
 public static bool IsValidAttributeName(string name)
 {
     return(SecurityElement.IsValidTag(name));
 }
Exemple #50
0
 /// <summary>Reconstructs a named permission set with a specified state from an XML encoding.</summary><param name="et">A security element containing the XML representation of the named permission set. </param><exception cref="T:System.ArgumentException">The <paramref name="et" /> parameter is not a valid representation of a named permission set. </exception><exception cref="T:System.ArgumentNullException">The <paramref name="et" /> parameter is null. </exception><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /></PermissionSet>
 public override void FromXml(SecurityElement et)
 {
     throw new NotImplementedException();
 }
        internal void FromXmlNameOnly(SecurityElement et)
        {
            string str = et.Attribute("Name");

            this.m_name = (str == null) ? null : str;
        }
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.ReadOnlyPermissionSet" /> class. </summary><param name="permissionSetXml">The XML element from which to take the value of the new <see cref="T:System.Security.ReadOnlyPermissionSet" />.</param><exception cref="T:System.ArgumentNullException"><paramref name="permissionSetXml" /> is null.</exception>
 public ReadOnlyPermissionSet(SecurityElement permissionSetXml)
     : base(null)
 {
     throw new NotImplementedException();
 }
 public override void FromXml(SecurityElement et)
 {
 }
 public override void FromXml(SecurityElement et)
 {
     this.FromXml(et, false, false);
 }
 internal static int CheckSecurityElement(SecurityElement se, string parameterName, int minimumVersion, int maximumVersion)
 {
     return(0);
 }
 internal NamedPermissionSet(SecurityElement permissionSetXml) : base(PermissionState.None)
 {
     this.FromXml(permissionSetXml);
 }
Exemple #57
0
        internal static void EncodeLevel(PolicyLevel level)
        {
            SecurityElement elConf     = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy   = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                MemoryStream stream = new MemoryStream(24576);

                StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false));

                Encoding encoding = level.Encoding;

                if (encoding == null)
                {
                    encoding = writer.Encoding;
                }

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                writer.Write(format.ToString());
                writer.Flush();
                writer = new StreamWriter(stream, encoding);

                writer.Write(elConf.ToString());

                writer.Flush();

                // Write out the new config.

                if (!Config.SaveData(level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length))
                {
                    throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label));
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                {
                    throw e;
                }
                else
                {
                    throw new PolicyException(String.Format(Environment.GetResourceString("Policy_UnableToSave"), level.Label), e);
                }
            }

            Config.ResetCacheData(level.ConfigId);

            try
            {
                if (CanUseQuickCache(level.RootCodeGroup))
                {
                    Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
                }
            }
            catch (Exception)
            {
            }
        }
 internal static bool IsUnrestricted(SecurityElement se)
 {
     return(true);
 }