public string setRequestBody(string old_requestBody, UserTabpage oPage)
        {
            string requestBody;
            string[] requestBodyPar = null;
            List<Para> paraValue_list = oPage.getPara_list();

            requestBodyPar = old_requestBody.Split(new char[1] { '&' });

            foreach (Para para in paraValue_list)
            {
                if (para.getParaTypeComboBox().Text == "修改")
                {
                    foreach (string ii in requestBodyPar)
                    {
                        if ((ii.ToString().Substring(0, para.getParaName().Length)) == para.getParaName())
                        {
                            old_requestBody = old_requestBody.Replace(ii.ToString().Substring(ii.ToString().IndexOf("=") + 1), para.getParaValue());
                        }
                    }
                }
            }

            requestBody = old_requestBody;
            AutoTamperReqBeforeHandler.rbody = old_requestBody;

            return requestBody;
        }
        public string setRequestUrl(String ori_url, UserTabpage oPage)
        {
            string new_url;
            string[] requestPar = null;
            List<Para> paraValue_list = oPage.getPara_list();

            requestPar = ori_url.Split(new char[2] { '?', '&' });

            foreach (Para para in paraValue_list)
            {
                if (para.getParaTypeComboBox().Text == "修改")
                {
                    foreach (string ii in requestPar)
                    {
                        if ((ii.ToString().Substring(0, para.getParaName().Length)) == para.getParaName())
                        {
                            if(para.getParaName() == "sign")
                            {
                                string sign = this.Sign(para.getParaValue(), paraValue_list, oPage);
                                ori_url = ori_url.Replace(ii.ToString().Substring(ii.ToString().IndexOf("=") + 1), sign);
                            }
                            else
                            {
                                ori_url = ori_url.Replace(ii.ToString().Substring(ii.ToString().IndexOf("=") + 1), para.getParaValue());
                            }
                        }
                    }
                }
            }

            new_url = ori_url;

            return new_url;
        }
        public void updateRequest(UserTabpage oPage)
        {
            if (this.oSession.HTTPMethodIs("POST") && oPage.getRequestType_cb().Text == "POST" && this.oSession.uriContains(oPage.getUrlTextBox().Text) && this.oSession.GetRequestBodyAsString().Contains(oPage.getRequestbody_tb().Text))
            {
                oSession.utilSetRequestBody(this.setRequestBody(oSession.GetRequestBodyAsString(), oPage));

                string ori_url = oSession.url;
                string new_url = this.setRequestUrl(ori_url, oPage);
                oSession.url = new_url;

            }
            else if (this.oSession.HTTPMethodIs("GET") && oPage.getRequestType_cb().Text == "GET" && this.oSession.uriContains(oPage.getUrlTextBox().Text))
            {
                string ori_url = oSession.url;
                string new_url = this.setRequestUrl(ori_url, oPage);
                oSession.url = new_url;
            }
        }
 public AutoTamperReqBeforeHandler(Session oSession, UserTabpage oPage)
 {
     this.oSession = oSession;
     this.oPage = oPage;
 }
        /*MD5加密函数*/
        public string Sign(string paraValue, List<Para> paraValue_list, UserTabpage oPage)
        {
            string sign = "";

            Regex reg = new Regex(@"(?<={)[^{}]+(?=})");
            MatchCollection mc = reg.Matches(paraValue);

            if(paraValue_list.Count == 0)
            {
                foreach (Match m in mc)
                {
                    if(m.Value == "json")
                    {
                        paraValue = paraValue.Replace("{" + m.Value + "}", this.jsonTOurlencode(oPage.getPreviewTextbox().Text));
                    }
                }
            }
            else
            {
                 foreach (Match m in mc)
                {
                    foreach (Para para in paraValue_list)
                    {
                        if (m.Value == para.getParaName())
                        {
                            paraValue = paraValue.Replace("{" + m.Value + "}", para.getParaValue());
                        }else if(m.Value == "json")
                        {
                            paraValue = paraValue.Replace("{" + m.Value + "}", this.jsonTOurlencode(oPage.getPreviewTextbox().Text));
                        }else if(m.Value == "reqBody")
                        {
                            paraValue = paraValue.Replace("{" + m.Value + "}", AutoTamperReqBeforeHandler.rbody);
                        }else if(m.Value == "fKey")
                        {
                            paraValue = paraValue.Replace("{" + m.Value + "}", oPage.getKeyText());
                        }
                    }
                }
            }

            sign = FormsAuthentication.HashPasswordForStoringInConfigFile(paraValue, "MD5").ToLower();

            return sign;
        }
        /*设置返回值*/
        public string setResponseBody(string response_ta_value, List<Para> paraValue_list, Session oSession, UserTabpage oPage)
        {
            string[] requestPar = null;

            oSession["ui-color"] = "brown";

            if (oPage.getRequestType_cb().Text == "GET")
            {
                string url = oSession.url;
                requestPar = url.Split(new char[2] { '?', '&' });
            }
            else if(oPage.getRequestType_cb().Text == "POST")
            {
                string url = oSession.GetRequestBodyAsString();
                requestPar = url.Split(new char[1] { '&' });
            }

            foreach (Para para in paraValue_list)
            {
                if (para.getParaTypeComboBox().Text == "读取")
                {
                    foreach (string ii in requestPar)
                    {
                        if (ii.Contains(para.getParaName()))
                        {
                            para.setParaValue(ii.ToString().Substring(ii.ToString().IndexOf("=") + 1));
                        }
                    }
                }
            }

            oPage.updatepPreview_response1();

            if(oPage.getCheckBox2().Checked)
            {
                oPage.getResponseTextBoxValue().Text += "|" + oPage.getPreviewTextbox().Text;
            }

            /*将大括号中符合规定的值替换*/
            Regex reg = new Regex(@"(?<={)[^{}]+(?=})");
            MatchCollection mc = reg.Matches(response_ta_value);

            if (paraValue_list.Count == 0)
            {
                foreach (Match m in mc)
                {
                    if (m.Value == "json")
                    {
                        response_ta_value = response_ta_value.Replace("{" + m.Value + "}", this.jsonTOurlencode(oPage.getPreviewTextbox().Text));
                    }
                    else if (m.Value == "sign")
                    {
                        response_ta_value = response_ta_value.Replace("{" + m.Value + "}", this.Sign(oPage.getSignValue_text().Text, paraValue_list, oPage));
                    }
                }
            }
            else
            {
                foreach (Match m in mc)
                {
                    foreach(Para para in paraValue_list)
                    {
                        if(m.Value == para.getParaName())
                        {
                            if (para.getParaTypeComboBox().Text == "MD5")
                            {
                                response_ta_value = response_ta_value.Replace("{" + m.Value + "}", this.Sign(para.getParaValue(), paraValue_list, oPage));
                            }
                            else
                            {
                                response_ta_value = response_ta_value.Replace("{" + m.Value + "}", para.getParaValue());
                            }
                        }
                        else if(m.Value == "json")
                        {
                            response_ta_value = response_ta_value.Replace("{" + m.Value + "}", this.jsonTOurlencode(oPage.getPreviewTextbox().Text));
                        }
                        else if(m.Value == "sign")
                        {
                            response_ta_value = response_ta_value.Replace("{" + m.Value + "}", this.Sign(oPage.getSignValue_text().Text, paraValue_list, oPage));
                        }
               	 	}
                }
            }

            return response_ta_value;
        }
 /*更新返回值和json预览*/
 public void updateResponseBody(UserTabpage oPage)
 {
     if (this.oSession.HTTPMethodIs("POST") && oPage.getRequestType_cb().Text == "POST" && this.oSession.uriContains(oPage.getUrlTextBox().Text) && this.oSession.GetRequestBodyAsString().Contains(oPage.getRequestbody_tb().Text))
     {
         //oPage.updatepPreview_response1();
         oSession.utilSetResponseBody(setResponseBody(oPage.getResponseTextBoxValue().Text, oPage.getPara_list(), oSession, oPage));
     }
     else if (this.oSession.HTTPMethodIs("GET") && oPage.getRequestType_cb().Text == "GET" && this.oSession.uriContains(oPage.getUrlTextBox().Text))
     {
         //oPage.updatepPreview_response1();
         oSession.utilSetResponseBody(setResponseBody(oPage.getResponseTextBoxValue().Text, oPage.getPara_list(), oSession, oPage));
     }
 }
예제 #8
0
 public OperateXML(string myXMLFilePath, XmlDocument myXmlDoc, UserTabpage oPage)
 {
     this.myXMLFilePath = myXMLFilePath;
     this.myXmlDoc = myXmlDoc;
     this.oPage = oPage;
 }
예제 #9
0
        public void OnLoad()
        {
            /* Load your UI here */
            oPage = new UserTabpage();

            FiddlerApplication.UI.tabsViews.TabPages.Add(oPage);
        }