예제 #1
0
 private void miAREdit_Click(object sender, EventArgs e)
 {
     ListView.SelectedListViewItemCollection selectedItems = this.lvRespondRules.SelectedItems;
     if (selectedItems.Count == 1)
     {
         if (selectedItems[0] != null)
         {
             this.actLaunchEditor(selectedItems[0]);
         }
         else
         {
             ResponderRule tag = (ResponderRule)selectedItems[0].Tag;
             if (!File.Exists(tag.sAction))
             {
                 MessageBox.Show("No local file exists for this rule");
             }
             else
             {
                 using (Process.Start("rundll32", "shell32.dll,OpenAs_RunDLL " + tag.sAction))
                 {
                 }
             }
         }
     }
 }
예제 #2
0
 public bool RemoveRule(ResponderRule oRule)
 {
     try
     {
         try
         {
             this._RWLockRules.AcquireWriterLock(-1);
             this._alRules.Remove(oRule);
         }
         finally
         {
             this._RWLockRules.ReleaseWriterLock();
         }
         this._bRuleListIsDirty = true;
         if (oRule.ViewItem != null)
         {
             oRule.ViewItem.Remove();
             oRule.ViewItem = null;
         }
         if (oRule._oEditor != null)
         {
             oRule._oEditor.Dispose();
             oRule._oEditor = null;
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #3
0
        private bool CheckMatch(string sURI, ResponderRule oCandidate)
        {
            if (!oCandidate.IsEnabled)
            {
                return(false);
            }
            string sMatch = oCandidate.sMatch;

            if ((sMatch.Length > 6) && sMatch.StartsWith("REGEX:", StringComparison.OrdinalIgnoreCase))
            {
                string pattern = sMatch.Substring(6);
                try
                {
                    Regex regex = new Regex(pattern);
                    if (regex.Match(sURI).Success)
                    {
                        return(true);
                    }
                }
                catch
                {
                }
                return(false);
            }
            if ((sMatch.Length > 6) && sMatch.StartsWith("EXACT:", StringComparison.OrdinalIgnoreCase))
            {
                return(sMatch.Substring(6).Equals(sURI, StringComparison.Ordinal));
            }
            if ((sMatch.Length > 4) && sMatch.StartsWith("NOT:", StringComparison.OrdinalIgnoreCase))
            {
                string str4 = sMatch.Substring(4);
                return(sURI.IndexOf(str4, StringComparison.OrdinalIgnoreCase) < 0);
            }
            return((sMatch == "*") || (-1 < sURI.IndexOf(sMatch, StringComparison.OrdinalIgnoreCase)));
        }
예제 #4
0
 private void DoDelay(ResponderRule oMatch)
 {
     if (FiddlerApplication.oAutoResponder.UseLatency && (oMatch.iLatency > 0))
     {
         Thread.Sleep(oMatch.iLatency);
     }
 }
예제 #5
0
        private void lvRespondRules_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            ResponderRule tag = (ResponderRule)e.Item.Tag;

            if (tag != null)
            {
                tag.IsEnabled = e.Item.Checked;
            }
        }
예제 #6
0
 public UIARRuleEditor(ResponderRule oRR)
 {
     this.InitializeComponent();
     this._oOwningRule = oRR;
     base.Icon         = FiddlerApplication.UI.Icon;
     FiddlerApplication.oInspectors.AddResponseInspectorsToTabControl(this.tabsResponseEditors);
     this.tmpRH = (HTTPResponseHeaders)this._oOwningRule._oResponseHeaders.Clone();
     this.tmpRB = (byte[])this._oOwningRule._arrResponseBodyBytes.Clone();
     this.Text  = "Fiddler - AutoResponse for " + this._oOwningRule.sMatch;
     FiddlerApplication.UI.actActivateTabByTitle("Headers", this.tabsResponseEditors);
     this.actUpdateEditor();
 }
예제 #7
0
 private void CreateViewItem(ResponderRule oRule)
 {
     if (oRule != null)
     {
         ListViewItem item = this.oAutoResponderUI.lvRespondRules.Items.Add(oRule.sMatch);
         item.SubItems.Add(oRule.sAction);
         item.SubItems.Add(oRule.iLatency.ToString());
         item.Checked   = oRule.IsEnabled;
         item.Tag       = oRule;
         oRule.ViewItem = item;
     }
 }
예제 #8
0
 private void miRespondCloneRule_Click(object sender, EventArgs e)
 {
     if (this.lvRespondRules.SelectedItems.Count == 1)
     {
         ResponderRule       tag             = (ResponderRule)this.lvRespondRules.SelectedItems[0].Tag;
         byte[]              arrResponseBody = null;
         HTTPResponseHeaders oRH             = null;
         if (tag.HasImportedResponse)
         {
             oRH             = (HTTPResponseHeaders)tag._oResponseHeaders.Clone();
             arrResponseBody = (byte[])tag._arrResponseBodyBytes.Clone();
         }
         FiddlerApplication._AutoResponder.AddRule(tag.sMatch, oRH, arrResponseBody, tag.sAction, tag.iLatency, tag.IsEnabled);
     }
 }
예제 #9
0
        private void actLaunchEditor(ListViewItem lvi)
        {
            ResponderRule tag = lvi.Tag as ResponderRule;

            if (tag.HasImportedResponse)
            {
                if ((tag._oEditor == null) || tag._oEditor.IsDisposed)
                {
                    tag._oEditor = new UIARRuleEditor(tag);
                    tag._oEditor.Show();
                }
                else
                {
                    tag._oEditor.BringToFront();
                }
            }
        }
예제 #10
0
 private void miAutoResponderGenerate_Click(object sender, EventArgs e)
 {
     ListView.SelectedListViewItemCollection selectedItems = this.lvRespondRules.SelectedItems;
     if (selectedItems.Count >= 1)
     {
         this.lvRespondRules.BeginUpdate();
         foreach (ListViewItem item in selectedItems)
         {
             ResponderRule tag = (ResponderRule)item.Tag;
             if (tag != null)
             {
                 tag.ConvertToFileBackedRule();
             }
         }
         this.lvRespondRules.SelectedItems.Clear();
         this.lvRespondRules.EndUpdate();
     }
 }
예제 #11
0
 private void lvRespondRules_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.lvRespondRules.SelectedItems.Count == 0)
     {
         this.gbResponderEditor.Enabled = false;
     }
     else if (this.lvRespondRules.SelectedItems.Count > 1)
     {
         this.cbxRuleURI.Visible = false;
     }
     else
     {
         ListViewItem  item = this.lvRespondRules.SelectedItems[0];
         ResponderRule tag  = (ResponderRule)item.Tag;
         this.cbxRuleURI.Visible        = true;
         this.cbxRuleURI.Text           = tag.sMatch;
         this.cbxRuleAction.Text        = tag.sAction;
         this.gbResponderEditor.Enabled = true;
     }
 }
예제 #12
0
        private void btnRespondAdd_Click(object sender, EventArgs e)
        {
            string str;

            if (FiddlerApplication.UI.lvSessions.SelectedItems.Count == 1)
            {
                str = "EXACT:" + FiddlerApplication.UI.GetFirstSelectedSession().fullUrl;
            }
            else
            {
                str = "StringToMatch[" + ((this.lvRespondRules.Items.Count + 1)).ToString() + "]";
            }
            this.lvRespondRules.SelectedItems.Clear();
            ResponderRule rule = FiddlerApplication._AutoResponder.AddRule(str, string.Empty, true);

            if (rule != null)
            {
                rule.ViewItem.EnsureVisible();
                rule.ViewItem.Selected = true;
            }
            this.cbxRuleURI.Focus();
        }
예제 #13
0
        internal bool PromoteRule(ResponderRule oRule)
        {
            bool flag;

            try
            {
                this._RWLockRules.AcquireWriterLock(-1);
                int index = this._alRules.IndexOf(oRule);
                if (index > 0)
                {
                    this._alRules.Reverse(index - 1, 2);
                    this._bRuleListIsDirty = true;
                    return(true);
                }
                flag = false;
            }
            finally
            {
                this._RWLockRules.ReleaseWriterLock();
            }
            return(flag);
        }
예제 #14
0
 private void btnSaveRule_Click(object sender, EventArgs e)
 {
     if (this.lvRespondRules.SelectedItems.Count >= 1)
     {
         foreach (ListViewItem item in this.lvRespondRules.SelectedItems)
         {
             ResponderRule tag = (ResponderRule)item.Tag;
             if (this.cbxRuleURI.Visible)
             {
                 tag.sMatch = this.cbxRuleURI.Text;
                 item.Text  = tag.sMatch;
             }
             if (tag.sAction != this.cbxRuleAction.Text)
             {
                 tag._arrResponseBodyBytes = null;
                 tag._oResponseHeaders     = null;
                 tag.sAction           = this.cbxRuleAction.Text;
                 item.SubItems[1].Text = tag.sAction;
             }
             FiddlerApplication._AutoResponder.IsRuleListDirty = true;
         }
     }
 }
예제 #15
0
 public ResponderRule AddRule(string sRule, HTTPResponseHeaders oRH, byte[] arrResponseBody, string sDescription, int iLatencyMS, bool bEnabled)
 {
     try
     {
         ResponderRule item = new ResponderRule(sRule, oRH, arrResponseBody, sDescription, iLatencyMS, bEnabled);
         try
         {
             this._RWLockRules.AcquireWriterLock(-1);
             this._alRules.Add(item);
         }
         finally
         {
             this._RWLockRules.ReleaseWriterLock();
         }
         this._bRuleListIsDirty = true;
         this.CreateViewItem(item);
         return(item);
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #16
0
        private bool HandleMatch(Session oSession, ResponderRule oMatch)
        {
            bool flag = oSession.HTTPMethodIs("CONNECT");

            if (oMatch.sAction.StartsWith("*"))
            {
                if (oMatch.sAction.Equals("*drop", StringComparison.OrdinalIgnoreCase))
                {
                    this.DoDelay(oMatch);
                    if ((oSession.oRequest != null) && (oSession.oRequest.pipeClient != null))
                    {
                        oSession.oRequest.pipeClient.End();
                    }
                    oSession.utilCreateResponseAndBypassServer();
                    oSession.oResponse.headers.HTTPResponseCode   = 0;
                    oSession.oResponse.headers.HTTPResponseStatus = "0 Aborted";
                    oSession.state = SessionStates.Aborted;
                    return(true);
                }
                if (oMatch.sAction.StartsWith("*delay:", StringComparison.OrdinalIgnoreCase))
                {
                    int result = 0;
                    if (int.TryParse(Utilities.TrimBefore(oMatch.sAction, ':'), out result))
                    {
                        Thread.Sleep(result);
                    }
                    return(false);
                }
                if (oMatch.sAction.Equals("*bpafter", StringComparison.OrdinalIgnoreCase))
                {
                    oSession["x-breakresponse"] = "AutoResponder";
                    oSession.bBufferResponse    = true;
                    return(false);
                }
                if (oMatch.sAction.StartsWith("*redir:", StringComparison.OrdinalIgnoreCase) && !flag)
                {
                    this.DoDelay(oMatch);
                    oSession.utilCreateResponseAndBypassServer();
                    oSession.oResponse.headers.HTTPResponseCode   = 0x133;
                    oSession.oResponse.headers.HTTPResponseStatus = "307 AutoRedir";
                    oSession.oResponse.headers["Location"]        = oMatch.sAction.Substring(7);
                    oSession.oResponse.headers["Cache-Control"]   = "max-age=0, must-revalidate";
                    return(true);
                }
                if (oMatch.sAction.Equals("*exit", StringComparison.OrdinalIgnoreCase))
                {
                    this.DoDelay(oMatch);
                    return(true);
                }
            }
            if (oMatch.HasImportedResponse && !flag)
            {
                if (oSession.state < SessionStates.SendingRequest)
                {
                    oSession.utilCreateResponseAndBypassServer();
                }
                else
                {
                    FiddlerApplication.Log.LogFormat("fiddler.autoresponder.error> AutoResponder will not respond to a request which is already in-flight; Session #{0} is at state: {1}", new object[] { oSession.id, oSession.state });
                    return(true);
                }
                if ((oMatch._arrResponseBodyBytes == null) || (oMatch._oResponseHeaders == null))
                {
                    FiddlerApplication.Log.LogString("fiddler.autoresponder.error> Response data from imported session is missing.");
                    return(true);
                }
                this.DoDelay(oMatch);
                if (oSession.HTTPMethodIs("HEAD"))
                {
                    oSession.responseBodyBytes = new byte[0];
                }
                else
                {
                    oSession.responseBodyBytes = oMatch._arrResponseBodyBytes;
                }
                oSession.oResponse.headers  = (HTTPResponseHeaders)oMatch._oResponseHeaders.Clone();
                oSession.state              = SessionStates.AutoTamperResponseBefore;
                oSession["x-AutoResponder"] = "Matched: " + oMatch.sMatch + ", sent: " + oMatch.sAction;
                oSession["ui-backcolor"]    = "Lavender";
                return(true);
            }
            if (!flag && (oMatch.sAction.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || oMatch.sAction.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
            {
                this.DoDelay(oMatch);
                oSession.oFlags["X-OriginalURL"] = oSession.fullUrl;
                oSession.fullUrl = oMatch.sAction;
                return(true);
            }
            this.DoDelay(oMatch);
            oSession["x-replywithfile"] = oMatch.sAction;
            oSession["ui-backcolor"]    = "Lavender";
            return(true);
        }