コード例 #1
0
        public void LoadLocalAssembly(string assemblyFilename)
        {
            var currentAssembly = Cecil.AssemblyDefinition.ReadAssembly(assemblyFilename);

            foreach (var method in IterateMethods(currentAssembly))
            {
                var lm = new LocalMethod();
                lm.CurrentMethodDef = method;
                lm.CurrentSwap      = null;
                lm.BodyString       = ConcatBody(method);
                lm.BodyHashCode     = lm.BodyString.GetHashCode();

                try {
                    var localType = recompiler.FindType(method.DeclaringType);
                    lm.Type = localType;
                    if (localType != null)
                    {
                        lm.Method = recompiler.FindMethod(localType, method);
                    }

                    localMethods[method.FullName] = lm;

                    Debug.Trace($"Loading method: {method.FullName}");
                } catch (Exception e) {
                    Debug.Trace($"Failed to load method: {method.FullName}");
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// 发送简单的http get请求
        /// </summary>
        /// <param name="url">请求的url</param>
        /// <returns></returns>
        public static string Get(string url, string charset = "UTF-8", string cookies = null, int Timeout = 10000)
        {
            try
            {
                var enc = LocalMethod.GetEncoding(charset);
                // 获取目录页
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method      = "GET";
                request.ContentType = $"text/html;charset={charset}";
                request.UserAgent   = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36";
                request.Timeout     = Timeout;
                if (!string.IsNullOrEmpty(cookies))
                {
                    var cookieContainer = new CookieContainer();
                    var cookieArr       = cookies.Split(';');
                    foreach (var item in cookieArr)
                    {
                        var keyValue = item.Trim().Split('=');
                        cookieContainer.Add(new Cookie(keyValue[0], keyValue[1]));
                    }

                    request.CookieContainer = cookieContainer;
                }

                HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
                Stream          myResponseStream = response.GetResponseStream();
                StreamReader    reader           = null;
                if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
                {
                    reader = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress), enc);
                }
                else
                {
                    reader = new StreamReader(response.GetResponseStream(), enc);
                }
                string html = reader.ReadToEnd();
                return(html);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return("");
            }
        }