Ejemplo n.º 1
0
        private static void DemandPermission(string codeBase, bool havePath, int demandFlag)
        {
            FileIOPermissionAccess pathDiscovery = FileIOPermissionAccess.PathDiscovery;

            switch (demandFlag)
            {
            case 1:
                pathDiscovery = FileIOPermissionAccess.Read;
                break;

            case 2:
                pathDiscovery = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read;
                break;

            case 3:
                CreateWebPermission(AssemblyName.EscapeCodeBase(codeBase)).Demand();
                return;
            }
            if (!havePath)
            {
                codeBase = new URLString(codeBase, true).GetFileName();
            }
            codeBase = Path.GetFullPathInternal(codeBase);
            new FileIOPermission(pathDiscovery, codeBase).Demand();
        }
Ejemplo n.º 2
0
        internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity, ref StackCrawlMark stackMark, bool forIntrospection, bool suppressSecurityChecks)
        {
            if (assemblyRef == null)
            {
                throw new ArgumentNullException("assemblyRef");
            }
            assemblyRef = (AssemblyName)assemblyRef.Clone();
            if (assemblySecurity != null)
            {
                if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
                {
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
                }
                if (!suppressSecurityChecks)
                {
                    new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
                }
            }
            string strA = VerifyCodeBase(assemblyRef.CodeBase);

            if ((strA != null) && !suppressSecurityChecks)
            {
                if (string.Compare(strA, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    CreateWebPermission(assemblyRef.EscapedCodeBase).Demand();
                }
                else
                {
                    URLString str2 = new URLString(strA, true);
                    new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, str2.GetFileName()).Demand();
                }
            }
            return(nLoad(assemblyRef, strA, assemblySecurity, null, ref stackMark, true, forIntrospection, suppressSecurityChecks));
        }
 bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
 {
     usedEvidence = null;
     if (evidence != null)
     {
         ApplicationDirectory hostEvidence = evidence.GetHostEvidence <ApplicationDirectory>();
         Url url = evidence.GetHostEvidence <Url>();
         if ((hostEvidence != null) && (url != null))
         {
             string directory = hostEvidence.Directory;
             if ((directory != null) && (directory.Length > 1))
             {
                 if (directory[directory.Length - 1] == '/')
                 {
                     directory = directory + "*";
                 }
                 else
                 {
                     directory = directory + "/*";
                 }
                 URLString operand = new URLString(directory);
                 if (url.GetURLString().IsSubsetOf(operand))
                 {
                     usedEvidence = hostEvidence;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        // Token: 0x06002855 RID: 10325 RVA: 0x0009465C File Offset: 0x0009285C
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;
            if (evidence == null)
            {
                return(false);
            }
            ApplicationDirectory hostEvidence = evidence.GetHostEvidence <ApplicationDirectory>();
            Url hostEvidence2 = evidence.GetHostEvidence <Url>();

            if (hostEvidence != null && hostEvidence2 != null)
            {
                string text = hostEvidence.Directory;
                if (text != null && text.Length > 1)
                {
                    if (text[text.Length - 1] == '/')
                    {
                        text += "*";
                    }
                    else
                    {
                        text += "/*";
                    }
                    URLString operand = new URLString(text);
                    if (hostEvidence2.GetURLString().IsSubsetOf(operand))
                    {
                        usedEvidence = hostEvidence;
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        private void ParseURL()
        {
            lock (this)
            {
                if (m_element == null)
                {
                    return;
                }

                String elurl = m_element.Attribute("Url");
                if (elurl == null)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_UrlCannotBeNull"));
                }
                else
                {
                    URLString url = new URLString(elurl);
                    if (url.IsRelativeFileUrl)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"));
                    }

                    m_url = url;
                }

                m_element = null;
            }
        }
Ejemplo n.º 6
0
        /// <include file='doc\URLIdentityPermission.uex' path='docs/doc[@for="UrlIdentityPermission.Intersect"]/*' />
        public override IPermission Intersect(IPermission target)
        {
            if (target == null || this.m_url == null)
            {
                return(null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            UrlIdentityPermission operand = (UrlIdentityPermission)target;

            if (operand.m_url == null || this.m_url == null)
            {
                return(null);
            }

            URLString url = (URLString)this.m_url.Intersect(operand.m_url);

            if (url == null)
            {
                return(null);
            }
            else
            {
                return(new UrlIdentityPermission(url));
            }
        }
Ejemplo n.º 7
0
        /// <include file='doc\URLIdentityPermission.uex' path='docs/doc[@for="UrlIdentityPermission.FromXml"]/*' />
        public override void FromXml(SecurityElement esd)
        {
            CodeAccessPermission.ValidateElement(esd, this);
            String elem = esd.Attribute("Url");

            m_url = elem == null ? null : new URLString(elem, true);
        }
Ejemplo n.º 8
0
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = (object)null;
            if (evidence == null)
            {
                return(false);
            }
            ApplicationDirectory hostEvidence1 = evidence.GetHostEvidence <ApplicationDirectory>();
            Url hostEvidence2 = evidence.GetHostEvidence <Url>();

            if (hostEvidence1 != null && hostEvidence2 != null)
            {
                string directory = hostEvidence1.Directory;
                if (directory != null && directory.Length > 1)
                {
                    string    str       = directory;
                    int       index     = str.Length - 1;
                    URLString urlString = new URLString((int)str[index] != 47 ? directory + "/*" : directory + "*");
                    if (hostEvidence2.GetURLString().IsSubsetOf((SiteString)urlString))
                    {
                        usedEvidence = (object)hostEvidence1;
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
 private void VerifyCodeBaseDiscovery(string codeBase)
 {
     if ((codeBase != null) && (string.Compare(codeBase, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) == 0))
     {
         URLString str = new URLString(codeBase, true);
         new FileIOPermission(FileIOPermissionAccess.PathDiscovery, str.GetFileName()).Demand();
     }
 }
Ejemplo n.º 10
0
 private void OnSerialized(StreamingContext ctx)
 {
     if ((ctx.State & ~(StreamingContextStates.Clone | StreamingContextStates.CrossAppDomain)) != 0)
     {
         m_serializedPermission = null;
         m_url = null;
     }
 }
Ejemplo n.º 11
0
 public ApplicationDirectory( String name )
 {
     if (name == null)
         throw new ArgumentNullException( "name" );
     Contract.EndContractBlock();
 
     m_appDirectory = new URLString( name );
 }
Ejemplo n.º 12
0
 internal Url(string name, bool parsed)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.m_url = new URLString(name, parsed);
 }
 public ApplicationDirectory(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.m_appDirectory = new URLString(name);
 }
Ejemplo n.º 14
0
 public Url(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.m_url = new URLString(name);
 }
Ejemplo n.º 15
0
 private void OnSerialized(StreamingContext ctx)
 {
     if ((ctx.State & ~(StreamingContextStates.Clone | StreamingContextStates.CrossAppDomain)) == (StreamingContextStates)0)
     {
         return;
     }
     this.m_serializedPermission = (string)null;
     this.m_url = (URLString)null;
 }
Ejemplo n.º 16
0
        /// <include file='doc\URLIdentityPermission.uex' path='docs/doc[@for="UrlIdentityPermission.UrlIdentityPermission1"]/*' />
        public UrlIdentityPermission(String site)
        {
            if (site == null)
            {
                throw new ArgumentNullException("site");
            }

            m_url = new URLString(site);
        }
Ejemplo n.º 17
0
        //AddOrChangeUrlParameter(«www.example.com? key = oldValue», «key = newValue») => www.example.com?key=newValue
        public void TestMethodTask3_test3()
        {
            string URL = "www.example.com?key=oldValue";
            string KeyValue = "key=newValue";

            string result = "www.example.com?key=newValue";

            Assert.AreEqual(result, URLString.AddOrChangeUrlParameter(URL, KeyValue));
        }
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is <see langword="null" /> if the intersection is empty.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. -or-The Url property is not a valid URL.</exception>
        // Token: 0x06002671 RID: 9841 RVA: 0x0008B318 File Offset: 0x00089518
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            UrlIdentityPermission urlIdentityPermission = target as UrlIdentityPermission;

            if (urlIdentityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            if (this.m_unrestricted && urlIdentityPermission.m_unrestricted)
            {
                return(new UrlIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if (this.m_unrestricted)
            {
                return(urlIdentityPermission.Copy());
            }
            if (urlIdentityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_urls == null || urlIdentityPermission.m_urls == null || this.m_urls.Length == 0 || urlIdentityPermission.m_urls.Length == 0)
            {
                return(null);
            }
            List <URLString> list = new List <URLString>();

            foreach (URLString urlstring in this.m_urls)
            {
                foreach (URLString operand in urlIdentityPermission.m_urls)
                {
                    URLString urlstring2 = (URLString)urlstring.Intersect(operand);
                    if (urlstring2 != null)
                    {
                        list.Add(urlstring2);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(null);
            }
            return(new UrlIdentityPermission(PermissionState.None)
            {
                m_urls = list.ToArray()
            });
        }
Ejemplo n.º 19
0
        internal Url(String name, bool parsed)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Contract.EndContractBlock();

            m_url = new URLString(name, parsed);
        }
Ejemplo n.º 20
0
        private static SiteString ParseSiteFromUrl(String name)
        {
            URLString urlString = new URLString(name);

            // Add this in Whidbey
            // if (String.Compare( urlString.Scheme, "file", true, CultureInfo.InvariantCulture ) == 0)
            //     throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidSite" ) );

            return(new SiteString(new URLString(name).Host));
        }
Ejemplo n.º 21
0
        public Url(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Contract.EndContractBlock();

            m_url = new URLString(name);
        }
Ejemplo n.º 22
0
        // Token: 0x06002A14 RID: 10772 RVA: 0x0009C868 File Offset: 0x0009AA68
        private static SiteString ParseSiteFromUrl(string name)
        {
            URLString urlstring = new URLString(name);

            if (string.Compare(urlstring.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSite"));
            }
            return(new SiteString(new URLString(name).Host));
        }
Ejemplo n.º 23
0
        public UrlMembershipCondition(String url)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            // Parse the Url to check that it's valid.
            m_url = new URLString(url, false /* not parsed */, true /* parse eagerly */);
        }
Ejemplo n.º 24
0
        /// <include file='doc\ApplicationDirectory.uex' path='docs/doc[@for="ApplicationDirectory.char1"]/*' />
        /// <internalonly/>
        int IBuiltInEvidence.InitFromBuffer(char[] buffer, int position)
        {
            int length = BuiltInEvidenceHelper.GetIntFromCharArray(buffer, position);

            position += 2;

            m_appDirectory = new URLString(new String(buffer, position, length));

            return(position + length);
        }
Ejemplo n.º 25
0
 private void OnSerializing(StreamingContext ctx)
 {
     if ((ctx.State & ~(StreamingContextStates.Clone | StreamingContextStates.CrossAppDomain)) != 0)
     {
         m_serializedPermission = ToXml().ToString(); //for the v2 and beyond case
         if (m_urls != null && m_urls.Length == 1)    // for the v1.x case
         {
             m_url = m_urls[0];
         }
     }
 }
Ejemplo n.º 26
0
        /// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns>
        /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -Url 属性不是有效的 URL。</exception>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return((IPermission)null);
            }
            UrlIdentityPermission identityPermission = target as UrlIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.m_unrestricted && identityPermission.m_unrestricted)
            {
                return (IPermission) new UrlIdentityPermission(PermissionState.None)
                       {
                           m_unrestricted = true
                       }
            }
            ;
            if (this.m_unrestricted)
            {
                return(identityPermission.Copy());
            }
            if (identityPermission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_urls == null || identityPermission.m_urls == null || (this.m_urls.Length == 0 || identityPermission.m_urls.Length == 0))
            {
                return((IPermission)null);
            }
            List <URLString> urlStringList = new List <URLString>();

            foreach (URLString mUrl1 in this.m_urls)
            {
                foreach (URLString mUrl2 in identityPermission.m_urls)
                {
                    URLString urlString = (URLString)mUrl1.Intersect((SiteString)mUrl2);
                    if (urlString != null)
                    {
                        urlStringList.Add(urlString);
                    }
                }
            }
            if (urlStringList.Count == 0)
            {
                return((IPermission)null);
            }
            return((IPermission) new UrlIdentityPermission(PermissionState.None)
            {
                m_urls = urlStringList.ToArray()
            });
        }
 private void OnSerializing(StreamingContext ctx)
 {
     if ((ctx.State & ~(StreamingContextStates.CrossAppDomain | StreamingContextStates.Clone)) != 0)
     {
         this.m_serializedPermission = this.ToXml().ToString();
         if ((this.m_urls != null) && (this.m_urls.Length == 1))
         {
             this.m_url = this.m_urls[0];
         }
     }
 }
Ejemplo n.º 28
0
 /// <summary>用确定成员身份的 URL 初始化 <see cref="T:System.Security.Policy.UrlMembershipCondition" /> 类的新实例。</summary>
 /// <param name="url">要对其进行测试的 URL。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="url" /> 参数为 null。</exception>
 /// <exception cref="T:System.ArgumentException">
 /// <paramref name="url" /> 必须为绝对 URL。</exception>
 public UrlMembershipCondition(string url)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     this.m_url = new URLString(url, false, true);
     if (this.m_url.IsRelativeFileUrl)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_RelativeUrlMembershipCondition"), "url");
     }
 }
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            UrlIdentityPermission permission = target as UrlIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (this.m_unrestricted && permission.m_unrestricted)
            {
                return(new UrlIdentityPermission(PermissionState.None)
                {
                    m_unrestricted = true
                });
            }
            if (this.m_unrestricted)
            {
                return(permission.Copy());
            }
            if (permission.m_unrestricted)
            {
                return(this.Copy());
            }
            if (((this.m_urls == null) || (permission.m_urls == null)) || ((this.m_urls.Length == 0) || (permission.m_urls.Length == 0)))
            {
                return(null);
            }
            List <URLString> list = new List <URLString>();

            foreach (URLString str in this.m_urls)
            {
                foreach (URLString str2 in permission.m_urls)
                {
                    URLString item = (URLString)str.Intersect(str2);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(null);
            }
            return(new UrlIdentityPermission(PermissionState.None)
            {
                m_urls = list.ToArray()
            });
        }
Ejemplo n.º 30
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            UrlIdentityPermission that = target as UrlIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            if (this.m_unrestricted && that.m_unrestricted)
            {
                UrlIdentityPermission res = new UrlIdentityPermission(PermissionState.None);
                res.m_unrestricted = true;
                return(res);
            }
            if (this.m_unrestricted)
            {
                return(that.Copy());
            }
            if (that.m_unrestricted)
            {
                return(this.Copy());
            }
            if (this.m_urls == null || that.m_urls == null || this.m_urls.Length == 0 || that.m_urls.Length == 0)
            {
                return(null);
            }
            List <URLString> alUrls = new List <URLString>();

            foreach (URLString usThis in this.m_urls)
            {
                foreach (URLString usThat in that.m_urls)
                {
                    URLString usInt = (URLString)usThis.Intersect(usThat);
                    if (usInt != null)
                    {
                        alUrls.Add(usInt);
                    }
                }
            }
            if (alUrls.Count == 0)
            {
                return(null);
            }
            UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None);

            result.m_urls = alUrls.ToArray();
            return(result);
        }
Ejemplo n.º 31
0
Archivo: Form1.cs Proyecto: JuRogn/OA
        private void button1_Click(object sender, EventArgs e)
        {
            indexNum = 0;
            string yearStr = DateTime.Now.Year.ToString()+"-";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //System.IO.StreamReader sr = new
                //   System.IO.StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("utf-8"));

                //MessageBox.Show(sr.ReadToEnd());
                System.IO.StreamReader sr = new
                 System.IO.StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("GBK"));


                List<URLString> listAll = new List<URLString>();
                while (!sr.EndOfStream)
                {

                    URLString obj = new URLString();
                    string valuer = sr.ReadLine();
                    txtUrl.Text = txtUrl.Text + valuer;
                    if (valuer.Contains(yearStr))
                    {
                        int start = valuer.IndexOf(yearStr);
                        string k = valuer.Substring(start, 19);
                        obj.DataTimeString = k;
                        if(!valuer.Contains("访问网址"))
                        {
                            string valuer2 = sr.ReadLine();
                            valuer = valuer + valuer2;
                        }

                        if (valuer.Contains("访问网址:"))
                        {
                            string[] names = valuer.Split('名');
                            string strName = names[1].Substring(1, 10);
                            obj.strName = strName;
                            string[] urlall = valuer.Split('问');
                            if (urlall.Length > 1)
                            {
                                string url = urlall[1];
                                string strk = url.Substring(url.Length - 1, 1);
                                if (strk == ".")
                                {
                                    url = url.Substring(0, url.Length - 1);
                                    url = url.Substring(3);
                                    if(url.Contains(".js")
                                        ||url.Contains(".css"))
                                    {
                                        continue;
                                    }
                                    obj.URLAdress = url;
                                    indexNum++;
                                    obj.Index = indexNum;
                                    listAll.Add(obj);
                                }
                                else
                                {
                                    string valuer2 = sr.ReadLine();
                                    url = url + valuer2;
                                    url = url.Substring(0, url.Length - 1);
                                    if (url.Contains("网址"))
                                    {
                                        url = url.Substring(3);
                                    }
                                    obj.URLAdress = url;
                                    indexNum++;
                                    obj.Index = indexNum;
                                    listAll.Add(obj);
                                }
                            }
                        }
                    }
                   
                }
                listAll = (from ent in listAll
                           orderby ent.strName, ent.Index
                           select ent).ToList();
                dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
                dataGridView1.DataSource = listAll;
                sr.Close();
            }
        }