Example #1
0
        public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sFormat != "Raw Files")
            {
                return(false);
            }
            string text  = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            bool   flag  = true;
            bool   flag2 = true;
            bool   flag3 = true;
            bool   flag4 = false;

            if (dictOptions != null)
            {
                if (dictOptions.ContainsKey("Folder"))
                {
                    text  = (dictOptions["Folder"] as string);
                    flag4 = true;
                }
                if (dictOptions.ContainsKey("RecreateStructure"))
                {
                    flag  = string.Equals("True", dictOptions["RecreateStructure"] as string, StringComparison.OrdinalIgnoreCase);
                    flag4 = true;
                }
                if (dictOptions.ContainsKey("OpenFolder"))
                {
                    flag2 = string.Equals("True", dictOptions["OpenFolder"] as string, StringComparison.OrdinalIgnoreCase);
                    flag4 = true;
                }
                if (dictOptions.ContainsKey("SkipNon200"))
                {
                    flag3 = string.Equals("True", dictOptions["SkipNon200"] as string, StringComparison.OrdinalIgnoreCase);
                    flag4 = true;
                }
            }
            if (!flag4)
            {
                UIFileExport uIFileExport = new UIFileExport();
                uIFileExport.txtLocation.Text = text;
                uIFileExport.cbRecreateFolderStructure.Checked = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", true);
                uIFileExport.cbOpenFolder.Checked  = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.OpenFolder", true);
                uIFileExport.cbHTTP200Only.Checked = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.SkipNon200", true);
                this.SetDefaultPath(uIFileExport.txtLocation, "fiddler.exporters.RawFiles.DefaultPath", text);
                DialogResult dialogResult = uIFileExport.ShowDialog();
                if (dialogResult != DialogResult.OK)
                {
                    return(false);
                }
                flag  = uIFileExport.cbRecreateFolderStructure.Checked;
                flag2 = uIFileExport.cbOpenFolder.Checked;
                flag3 = uIFileExport.cbHTTP200Only.Checked;
                text  = uIFileExport.txtLocation.Text;
                text  = Utilities.EnsurePathIsAbsolute(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), text).Trim();
                FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", flag);
                FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.OpenFolder", flag2);
                FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.SkipNon200", flag3);
                FiddlerApplication.get_Prefs().SetStringPref("fiddler.exporters.RawFiles.DefaultPath", text);
                uIFileExport.Dispose();
                text = string.Concat(new object[]
                {
                    text,
                    Path.DirectorySeparatorChar,
                    "Dump-",
                    DateTime.Now.ToString("MMdd-HH-mm-ss"),
                    Path.DirectorySeparatorChar
                });
            }
            try
            {
                Directory.CreateDirectory(text);
            }
            catch (Exception ex)
            {
                FiddlerApplication.ReportException(ex, "Export Failed");
                bool result = false;
                return(result);
            }
            int num = 0;

            for (int i = 0; i < oSessions.Length; i++)
            {
                Session session = oSessions[i];
                try
                {
                    if (!flag3 || session.get_responseCode() == 200)
                    {
                        if (session.HTTPMethodIs("CONNECT"))
                        {
                            num++;
                        }
                        else
                        {
                            if (session.responseBodyBytes != null && session.responseBodyBytes.Length > 0)
                            {
                                string text3;
                                if (flag)
                                {
                                    string text2 = Utilities.TrimAfter(session.get_url(), '?');
                                    text3 = text2.Replace('/', Path.DirectorySeparatorChar);
                                    if (text3.EndsWith(string.Empty + Path.DirectorySeparatorChar))
                                    {
                                        text3 += session.get_SuggestedFilename();
                                    }
                                    if (text3.Length > 0 && text3.Length < 260)
                                    {
                                        text3 = text + this._MakeSafeFilename(text3);
                                    }
                                    else
                                    {
                                        text3 = text + session.get_SuggestedFilename();
                                    }
                                }
                                else
                                {
                                    text3 = text + session.get_SuggestedFilename();
                                }
                                text3 = Utilities.EnsureUniqueFilename(text3);
                                byte[] array = session.responseBodyBytes;
                                if (session.oResponse.get_headers().Exists("Content-Encoding") || session.oResponse.get_headers().Exists("Transfer-Encoding"))
                                {
                                    array = (byte[])array.Clone();
                                    Utilities.utilDecodeHTTPBody(session.oResponse.get_headers(), ref array);
                                }
                                FiddlerApplication.get_Log().LogFormat("Writing #{0} to {1}", new object[]
                                {
                                    session.get_id().ToString(),
                                    text3
                                });
                                Utilities.WriteArrayToFile(text3, array);
                            }
                            num++;
                            if (evtProgressNotifications != null)
                            {
                                ProgressCallbackEventArgs progressCallbackEventArgs = new ProgressCallbackEventArgs((float)num / (float)oSessions.Length, "Dumped " + num.ToString() + " files to disk.");
                                evtProgressNotifications(null, progressCallbackEventArgs);
                                if (progressCallbackEventArgs.get_Cancel())
                                {
                                    bool result = false;
                                    return(result);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex2)
                {
                    FiddlerApplication.ReportException(ex2, "Failed to generate response file.");
                }
            }
            if (flag2)
            {
                try
                {
                    string fileName = string.Format("\"{0}\"", text);
                    using (Process.Start(new ProcessStartInfo(fileName)
                    {
                        Verb = "explore"
                    }))
                    {
                    }
                }
                catch (Exception ex3)
                {
                    FiddlerApplication.ReportException(ex3, "Cannot open folder");
                }
            }
            return(true);
        }
Example #2
0
        public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sFormat != "MeddlerScript")
            {
                return(false);
            }
            bool   result = false;
            string text   = null;

            if (dictOptions != null && dictOptions.ContainsKey("Filename"))
            {
                text = (dictOptions["Filename"] as string);
            }
            if (string.IsNullOrEmpty(text))
            {
                text = Utilities.ObtainSaveFilename("Export As " + sFormat, "MeddlerScript (*.ms)|*.ms");
            }
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    int           num           = 0;
                    string        text2         = null;
                    bool          result2;
                    for (int i = 0; i < oSessions.Length; i++)
                    {
                        Session session = oSessions[i];
                        if (text2 == null)
                        {
                            text2 = "http://localhost:{$PORT}" + session.get_PathAndQuery();
                        }
                        stringBuilder.AppendFormat("\r\n\t\t\tif (oSession.requestHeaders.Path == '{0}')\r\n\t\t\t{{\r\n", session.get_PathAndQuery().Replace("'", "\\'"));
                        stringBuilder.AppendFormat("\r\n\t\t\t\toHeaders.Version='{0}';", session.oResponse.get_headers().HTTPVersion.Replace("'", "\\'"));
                        stringBuilder.AppendFormat("\r\n\t\t\t\toHeaders.Status='{0}';\r\n", session.oResponse.get_headers().HTTPResponseStatus.Replace("'", "\\'"));
                        foreach (HTTPHeaderItem current in session.oResponse.get_headers())
                        {
                            stringBuilder.AppendFormat("\r\n\t\t\t\toHeaders.Add('{0}', '{1}');", current.Name.Replace("'", "\\'"), current.Value.Replace("'", "\\'"));
                        }
                        stringBuilder.AppendFormat("\r\n\t\t\t\toSession.WriteString(oHeaders);\r\n", new object[0]);
                        stringBuilder.AppendFormat("\r\n\t\t\t\toSession.WriteBytes(Convert.FromBase64String('", new object[0]);
                        stringBuilder.AppendFormat(Convert.ToBase64String(session.responseBodyBytes), new object[0]);
                        stringBuilder.AppendFormat("'));\r\n", new object[0]);
                        stringBuilder.AppendFormat("\t\t\t\toSession.CloseSocket(); return;\r\n\t\t\t}}\r\n", new object[0]);
                        num++;
                        if (evtProgressNotifications != null)
                        {
                            ProgressCallbackEventArgs progressCallbackEventArgs = new ProgressCallbackEventArgs((float)num / (float)oSessions.Length, "Added " + num.ToString() + " sessions to MeddlerScript.");
                            evtProgressNotifications(null, progressCallbackEventArgs);
                            if (progressCallbackEventArgs.get_Cancel())
                            {
                                result2 = false;
                                return(result2);
                            }
                        }
                    }
                    this.PrependMeddlerHeader(stringBuilder, text2 ?? "http://localhost:{$PORT}/");
                    this.EmitMeddlerFooter(stringBuilder);
                    File.WriteAllText(text, stringBuilder.ToString());
                    result2 = true;
                    return(result2);
                }
                catch (Exception ex)
                {
                    FiddlerApplication.ReportException(ex, "Failed to save MeddlerScript");
                    bool result2 = false;
                    return(result2);
                }
                return(result);
            }
            return(result);
        }
Example #3
0
        public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sFormat != "cURL Script")
            {
                return(false);
            }
            bool   result = false;
            string text   = null;

            if (dictOptions != null && dictOptions.ContainsKey("Filename"))
            {
                text = (dictOptions["Filename"] as string);
            }
            if (string.IsNullOrEmpty(text))
            {
                text = Utilities.ObtainSaveFilename("Export As " + sFormat, "Batch Script (*.bat)|*.bat");
            }
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    string        stringPref    = FiddlerApplication.get_Prefs().GetStringPref("fiddler.exporters.cURL.DefaultOptions", "-k -i --raw");
                    int           num           = 0;
                    int           num2          = 0;
                    bool          result2;
                    for (int i = 0; i < oSessions.Length; i++)
                    {
                        Session session = oSessions[i];
                        string  text2   = string.Empty;
                        if (session.HTTPMethodIs("CONNECT"))
                        {
                            num++;
                        }
                        else
                        {
                            if (!session.HTTPMethodIs("GET"))
                            {
                                if (session.HTTPMethodIs("HEAD"))
                                {
                                    text2 = "-I ";
                                }
                                else
                                {
                                    text2 = string.Format("-X {0} ", session.get_RequestMethod());
                                }
                            }
                            string text3;
                            if (stringPref.Contains("-i"))
                            {
                                text3 = string.Format("{0}.dat", num2);
                            }
                            else
                            {
                                text3 = session.get_SuggestedFilename();
                            }
                            string text4 = string.Empty;
                            if (session.oRequest.get_Item("Content-Type").StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
                            {
                                text4 = string.Format("-d \"{0}\" ", cURLExport._EscapeString(session.GetRequestBodyAsString()));
                            }
                            string text5 = cURLExport._EscapeString(session.get_fullUrl());
                            stringBuilder.AppendFormat("curl {0} -o {1} {2}{3}\"{4}\"", new object[]
                            {
                                stringPref,
                                text3,
                                text2,
                                text4,
                                text5
                            });
                            foreach (HTTPHeaderItem current in session.oRequest.get_headers())
                            {
                                if (!(current.Name == "Content-Length"))
                                {
                                    stringBuilder.AppendFormat(" -H \"{0}\"", cURLExport._EscapeString(current.ToString()));
                                }
                            }
                            stringBuilder.AppendLine();
                            num++;
                            num2++;
                            if (evtProgressNotifications != null)
                            {
                                ProgressCallbackEventArgs progressCallbackEventArgs = new ProgressCallbackEventArgs((float)num / (float)oSessions.Length, "Added " + num.ToString() + " sessions to cURL Script.");
                                evtProgressNotifications(null, progressCallbackEventArgs);
                                if (progressCallbackEventArgs.get_Cancel())
                                {
                                    result2 = false;
                                    return(result2);
                                }
                            }
                        }
                    }
                    this.PrependScriptHeader(stringBuilder);
                    this.EmitScriptFooter(stringBuilder);
                    File.WriteAllText(text, stringBuilder.ToString());
                    result2 = true;
                    return(result2);
                }
                catch (Exception ex)
                {
                    FiddlerApplication.ReportException(ex, "Failed to save cURLScript");
                    bool result2 = false;
                    return(result2);
                }
                return(result);
            }
            return(result);
        }
Example #4
0
        internal static bool WriteStream(StreamWriter swOutput, Session[] oSessions, bool bUseV1dot2Format, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications, int iMaxTextBodyLength, int iMaxBinaryBodyLength)
        {
            HTTPArchiveJSONExport._iMaxTextBodyLength   = iMaxTextBodyLength;
            HTTPArchiveJSONExport._iMaxBinaryBodyLength = iMaxBinaryBodyLength;
            Hashtable hashtable = new Hashtable();

            hashtable.Add("version", bUseV1dot2Format ? "1.2" : "1.1");
            hashtable.Add("pages", new ArrayList(0));
            if (bUseV1dot2Format)
            {
                hashtable.Add("comment", "exported @ " + DateTime.Now.ToString());
            }
            Hashtable hashtable2 = new Hashtable();

            hashtable2.Add("name", "Fiddler");
            hashtable2.Add("version", Application.ProductVersion);
            if (bUseV1dot2Format)
            {
                hashtable2.Add("comment", "http://www.fiddler2.com");
            }
            hashtable.Add("creator", hashtable2);
            ArrayList arrayList = new ArrayList();
            int       num       = 0;
            int       i         = 0;

            while (i < oSessions.Length)
            {
                Session session = oSessions[i];
                try
                {
                    if (session.get_state() < 11)
                    {
                        goto IL_24D;
                    }
                    Hashtable hashtable3 = new Hashtable();
                    hashtable3.Add("startedDateTime", session.Timers.ClientBeginRequest.ToString("o"));
                    hashtable3.Add("request", HTTPArchiveJSONExport.getRequest(session));
                    hashtable3.Add("response", HTTPArchiveJSONExport.getResponse(session, bUseV1dot2Format));
                    hashtable3.Add("cache", new Hashtable());
                    Hashtable timings = HTTPArchiveJSONExport.getTimings(session.Timers, bUseV1dot2Format);
                    hashtable3.Add("time", HTTPArchiveJSONExport.getTotalTime(timings));
                    hashtable3.Add("timings", timings);
                    if (bUseV1dot2Format)
                    {
                        string value = session.get_Item("ui-comments");
                        if (!string.IsNullOrEmpty(value))
                        {
                            hashtable3.Add("comment", session.get_Item("ui-comments"));
                        }
                        string arg_1A9_0 = session.m_hostIP;
                        if (!string.IsNullOrEmpty(value) && !session.isFlagSet(2048))
                        {
                            hashtable3.Add("serverIPAddress", session.m_hostIP);
                        }
                        hashtable3.Add("connection", session.get_clientPort().ToString());
                    }
                    arrayList.Add(hashtable3);
                }
                catch (Exception ex)
                {
                    FiddlerApplication.ReportException(ex, "Failed to Export Session");
                }
                goto IL_20B;
IL_24D:
                i++;
                continue;
IL_20B:
                num++;
                if (evtProgressNotifications == null)
                {
                    goto IL_24D;
                }
                ProgressCallbackEventArgs progressCallbackEventArgs = new ProgressCallbackEventArgs((float)num / (float)oSessions.Length, "Wrote " + num.ToString() + " sessions to HTTPArchive.");
                evtProgressNotifications(null, progressCallbackEventArgs);
                if (progressCallbackEventArgs.get_Cancel())
                {
                    return(false);
                }
                goto IL_24D;
            }
            hashtable.Add("entries", arrayList);
            swOutput.WriteLine(JSON.JsonEncode(new Hashtable
            {
                {
                    "log",
                    hashtable
                }
            }));
            return(true);
        }