예제 #1
0
        /// <summary>
        /// 用文件替代response
        /// </summary>
        /// <param name="session"></param>
        /// <param name="path"></param>
        public static void LoadFileToResponse(Fiddler.Session session, string path)
        {
            var ct  = "text/html; charset=utf-8";
            var ext = System.IO.Path.GetExtension(path);

            //FiddlerLog("file ext:" + ext);
            if (".gif,.png,.jpg,.bmp,.jpeg,.webp".IndexOf(ext, StringComparison.OrdinalIgnoreCase) > -1)
            {
                ct = "image/" + ext.TrimStart('.');
            }

            if (System.IO.File.Exists(path))
            {
                ResetResponse(session, 200, ct);
                //var content = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8);
                //session.utilSetResponseBody(content);

                session.oResponse.headers.Add("jmFidExt_action", path);

                session.LoadResponseFromFile(path);
            }
            else
            {
                ResetResponse(session, 404, ct);
                session.utilSetResponseBody("文件:" + path + " 未找到");
            }
            //session.Ignore();
        }
예제 #2
0
        private void FiddlerApplication_BeforeResponse(Fiddler.Session oSession)
        {
            //flash 品質設定
            if (oSession.bBufferResponse && oSession.fullUrl.Contains("/gadget/js/kcs_flash.js"))
            {
                string js   = oSession.GetResponseBodyAsString();
                bool   flag = false;

                var wmode = _wmodeRegex.Match(js);
                if (wmode.Success)
                {
                    js   = js.Replace(wmode.Value, string.Format(@"""wmode"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashWMode));
                    flag = true;
                }

                var quality = _qualityRegex.Match(js);
                if (quality.Success)
                {
                    js   = js.Replace(quality.Value, string.Format(@"""quality"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashQuality));
                    flag = true;
                }

                if (flag)
                {
                    oSession.utilSetResponseBody(js);

                    Utility.Logger.Add(1, "flashの品質設定を行いました。");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 根配置重置session请求
        /// </summary>
        /// <param name="r"></param>
        /// <param name="session"></param>
        public static void ResetSession(Rule r, Fiddler.Session session, System.Text.RegularExpressions.Regex reg = null)
        {
            Utils.FiddlerLog("match success match:" + r.match + " action:" + r.action + " fullUrl:" + session.fullUrl);

            session["ui-backcolor"] = REQUICLOR;
            session["ui-bold"]      = "true";

            var action = r.action.Trim();

            //如果是替换为ip,则直接则host
            System.Net.IPAddress ip;

            //var m = System.Text.RegularExpressions.Regex.Match(action, @"^\s*(?<ip>\d+(\.\d+)+)\s*:\s*(\d+)\s*");
            //如果是带端口的格式 127.0.0.1:8000
            if (System.Text.RegularExpressions.Regex.IsMatch(action, @"^\s*(?<ip>\d+(\.\d+)+)\s*:\s*(\d+)\s*$"))
            {
                session["x-overridehost"] = action;
            }
            else if (System.Net.IPAddress.TryParse(action, out ip))
            {
                session["x-overridehost"] = action;
            }
            //如果是一个文件路径
            else if (System.Text.RegularExpressions.Regex.IsMatch(action, @"^[A-Za-z]\:(\\|\/)[^\s]+"))
            {
                if (System.IO.File.Exists(action))
                {
                    LoadFileToResponse(session, action);
                }
                //如果是一个目录,则当静态服务器用,所有匹配的请求都指向此目录的文件
                else if (System.IO.Directory.Exists(action))
                {
                    var path = ""; //拼接文件地址
                    if (reg != null)
                    {
                        var m = reg.Match(session.fullUrl);
                        if (m != null && m.Groups != null)
                        {
                            try
                            {
                                path = m.Groups["filename"].Value;
                            }
                            catch (Exception ex)
                            {
                                Utils.FiddlerLog(ex.ToString());
                            }
                        }
                    }
                    //如果没有获得文件名,则直接把url域名后的全截取
                    if (string.IsNullOrWhiteSpace(path))
                    {
                        var index = session.fullUrl.IndexOf("/", 10);//取http://后的第一个/
                        if (index > 0)
                        {
                            path = session.fullUrl.Substring(index).Trim('/');
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        var index = path.IndexOf('?');
                        if (index < 0)
                        {
                            index = path.IndexOf('#');
                        }
                        if (index > -1)
                        {
                            path = path.Substring(0, index);            //去除?后面的部分
                        }
                        path = System.IO.Path.Combine(action, path);
                    }

                    LoadFileToResponse(session, path);
                }
                else
                {
                    Utils.FiddlerLog("文件:" + action + " 不存在");
                    ResetResponse(session, 404);
                }
            }
            //如果是一个URL,则重置请求
            else if (System.Text.RegularExpressions.Regex.IsMatch(action, @"^(http(s)?:)?//([\w-]+\.)+[\w-:]+(/[\w- ./?%&=]*)?$"))
            {
                //如果是严格的 http://xx.xx.com 。则表示把所有匹配的请求提向这个协议和域名
                var protoreg = new System.Text.RegularExpressions.Regex(@"^(?<proto>http(s)?)://(?<domain>([\w-]+\.)+[\w-:]+)$");
                var m        = protoreg.Match(action);
                if (m.Success)
                {
                    var proto  = m.Groups["proto"].Value;
                    var domain = m.Groups["domain"].Value;

                    if (proto == "http")
                    {
                        /*if(!session.isHTTPS && session.port == 443) {
                         *  // 如果是代理请求,则不做处理
                         *  if (session.HTTPMethodIs("CONNECT"))
                         *  {
                         *      session["x-replywithtunnel"] = "FakeTunnel";
                         *      return;
                         *  }
                         * }*/
                    }
                    //else if(!session.isHTTPS) {
                    //    session.fullUrl = session.fullUrl.Replace("http://", proto + "://");
                    //}

                    session.oRequest.headers.UriScheme = proto;

                    Utils.FiddlerLog("change prototype to " + proto + " domain " + domain + " isHttps:" + session.isHTTPS + " isConnect:" + session.HTTPMethodIs("CONNECT"));

                    // IP或带端口模式,则投置为host
                    if (System.Text.RegularExpressions.Regex.IsMatch(domain, @"^\s*(?<ip>\d+(\.\d+)+)\s*:\s*(\d+)\s*$"))
                    {
                        Utils.FiddlerLog("set x-overridehost " + domain);
                        session["x-overridehost"] = domain;
                    }
                    else if (System.Net.IPAddress.TryParse(domain, out ip))
                    {
                        Utils.FiddlerLog("set x-overridehost " + domain);
                        session["x-overridehost"] = domain;
                    }
                    else
                    {
                        session["x-overrideGateway"] = domain;
                        Utils.FiddlerLog("set x-overrideGateway " + domain);
                    }
                }
                else
                {
                    //session["x-overrideGateway"] = action;
                    session.fullUrl = action;
                    Utils.FiddlerLog("set fullUrl " + action);
                }
            }
            //一个域名
            else if (System.Text.RegularExpressions.Regex.IsMatch(action, @"^[\w-]+(\.[\w-]+)+(:\s*(\d+)\s*)?$"))
            {
                session["x-overrideGateway"] = action;
                Utils.FiddlerLog("set x-overrideGateway " + action);
            }
            //否则直接当结果body返回
            else
            {
                ResetResponse(session);
                session.utilSetResponseBody(action);
            }
        }