public bool ExportSessions(string sExportFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sExportFormat != "SmileVideo") return false;

            string sampleFilename = null;
            string[] filenameBase = new string[]{null};

            if (dictOptions != null && dictOptions.ContainsKey("FileName"))
                sampleFilename = dictOptions["FileName"] as string;
            if(sampleFilename != null)
                filenameBase = pathMatcher.Match(sampleFilename).GetGroupValues().ToArray();

            if (string.IsNullOrEmpty(filenameBase[0]))
            {
                sampleFilename = Utilities.ObtainSaveFilename("Export as SmileVideo", "Video (use sm{num} as placeholder)|*.mp4;*.flv");
                if (sampleFilename != null)
                    filenameBase = pathMatcher.Match(sampleFilename).GetGroupValues().ToArray();
                if (string.IsNullOrEmpty(filenameBase[0]))
                    return false;
            }

            bool isHitted = false;
            int processedCount = 0;

            foreach (var s in oSessions)
            {
                var vid = uriMatcher.Match(s.url).Groups[1].Value;
                var ctype = s["Response","Content-Type"];
                if (!string.IsNullOrEmpty(vid) && ctype.StartsWith("video/"))
                {
                    var filename = string.Format("{0}sm{1}{2}.{3}", filenameBase[1], vid, filenameBase[2], ctype.Substring(6));
                    if (evtProgressNotifications != null)
                    {
                        var args = new ProgressCallbackEventArgs((float)processedCount++ / oSessions.Length, string.Format("Saving sm{0}...", vid));
                        evtProgressNotifications(this, args);
                        if (args.Cancel) return false;
                    }
                    s.SaveResponseBody(filename);
                    isHitted = true;
                }
            }

            return isHitted;
        }
Пример #2
0
 public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
 {
     if (sFormat != "Raw Files")
     {
         return false;
     }
     string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     bool bValue = true;
     bool flag2 = true;
     bool flag3 = false;
     if (dictOptions != null)
     {
         if (dictOptions.ContainsKey("Folder"))
         {
             folderPath = dictOptions["Folder"] as string;
             flag3 = true;
         }
         if (dictOptions.ContainsKey("RecreateStructure"))
         {
             bValue = string.Equals("True", dictOptions["RecreateStructure"] as string, StringComparison.OrdinalIgnoreCase);
             flag3 = true;
         }
         if (dictOptions.ContainsKey("OpenFolder"))
         {
             flag2 = string.Equals("True", dictOptions["OpenFolder"] as string, StringComparison.OrdinalIgnoreCase);
             flag3 = true;
         }
     }
     if (!flag3)
     {
         UIFileExport export = new UIFileExport {
             txtLocation = { Text = folderPath },
             cbRecreateFolderStructure = { Checked = FiddlerApplication.Prefs.GetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", true) },
             cbOpenFolder = { Checked = FiddlerApplication.Prefs.GetBoolPref("fiddler.exporters.RawFiles.OpenFolder", true) }
         };
         this.SetDefaultPath(export.txtLocation, "fiddler.exporters.RawFiles.DefaultPath", folderPath);
         if (export.ShowDialog() != DialogResult.OK)
         {
             return false;
         }
         bValue = export.cbRecreateFolderStructure.Checked;
         flag2 = export.cbOpenFolder.Checked;
         folderPath = export.txtLocation.Text;
         FiddlerApplication.Prefs.SetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", bValue);
         FiddlerApplication.Prefs.SetBoolPref("fiddler.exporters.RawFiles.OpenFolder", flag2);
         FiddlerApplication.Prefs.SetStringPref("fiddler.exporters.RawFiles.DefaultPath", folderPath);
         export.Dispose();
         folderPath = folderPath + @"\Dump-" + DateTime.Now.ToString("MMdd-HH-mm-ss") + @"\";
     }
     try
     {
         Directory.CreateDirectory(folderPath);
     }
     catch (Exception exception)
     {
         FiddlerApplication.ReportException(exception, "Export Failed");
         return false;
     }
     int num = 0;
     foreach (Session session in oSessions)
     {
         try
         {
             if (session.HTTPMethodIs("CONNECT"))
             {
                 num++;
             }
             else
             {
                 if ((session.responseBodyBytes != null) && (session.responseBodyBytes.Length > 0))
                 {
                     string str2;
                     if (bValue)
                     {
                         str2 = Utilities.TrimAfter(session.url, '?').Replace('/', '\\');
                         if (str2.EndsWith(@"\"))
                         {
                             str2 = str2 + session.SuggestedFilename;
                         }
                         if ((str2.Length > 0) && (str2.Length < 260))
                         {
                             str2 = folderPath + this._MakeSafeFilename(str2);
                         }
                         else
                         {
                             str2 = folderPath + session.SuggestedFilename;
                         }
                     }
                     else
                     {
                         str2 = folderPath + session.SuggestedFilename;
                     }
                     str2 = Utilities.EnsureUniqueFilename(str2);
                     byte[] responseBodyBytes = session.responseBodyBytes;
                     if (session.oResponse.headers.Exists("Content-Encoding") || session.oResponse.headers.Exists("Transfer-Encoding"))
                     {
                         responseBodyBytes = (byte[]) responseBodyBytes.Clone();
                         Utilities.utilDecodeHTTPBody(session.oResponse.headers, ref responseBodyBytes);
                     }
                     Utilities.WriteArrayToFile(str2, responseBodyBytes);
                 }
                 num++;
                 if (evtProgressNotifications != null)
                 {
                     ProgressCallbackEventArgs e = new ProgressCallbackEventArgs(((float) num) / ((float) oSessions.Length), "Dumped " + num.ToString() + " files to disk.");
                     evtProgressNotifications(null, e);
                     if (e.Cancel)
                     {
                         return false;
                     }
                 }
             }
         }
         catch (Exception exception2)
         {
             FiddlerApplication.ReportException(exception2, "Failed to generate response file.");
         }
     }
     if (flag2)
     {
         Process.Start("explorer.exe", folderPath);
     }
     return true;
 }
Пример #3
0
 public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
 {
     if (sFormat != "MeddlerScript")
     {
         return false;
     }
     string str = null;
     if ((dictOptions != null) && dictOptions.ContainsKey("Filename"))
     {
         str = dictOptions["Filename"] as string;
     }
     if (string.IsNullOrEmpty(str))
     {
         str = Utilities.ObtainSaveFilename("Export As " + sFormat, "MeddlerScript (*.ms)|*.ms");
     }
     if (!string.IsNullOrEmpty(str))
     {
         try
         {
             StringBuilder sb = new StringBuilder();
             int num = 0;
             string str2 = null;
             foreach (Session session in oSessions)
             {
                 if (str2 == null)
                 {
                     str2 = "http://*****:*****@"\'"));
                 sb.AppendFormat("\r\n\t\t\t\toHeaders.Version='{0}';", session.oResponse.headers.HTTPVersion.Replace("'", @"\'"));
                 sb.AppendFormat("\r\n\t\t\t\toHeaders.Status='{0}';\r\n", session.oResponse.headers.HTTPResponseStatus.Replace("'", @"\'"));
                 foreach (HTTPHeaderItem item in session.oResponse.headers)
                 {
                     sb.AppendFormat("\r\n\t\t\t\toHeaders.Add('{0}', '{1}');", item.Name.Replace("'", @"\'"), item.Value.Replace("'", @"\'"));
                 }
                 sb.AppendFormat("\r\n\t\t\t\toSession.WriteString(oHeaders);\r\n", new object[0]);
                 sb.AppendFormat("\r\n\t\t\t\toSession.WriteBytes(Convert.FromBase64String('", new object[0]);
                 sb.AppendFormat(Convert.ToBase64String(session.responseBodyBytes), new object[0]);
                 sb.AppendFormat("'));\r\n", new object[0]);
                 sb.AppendFormat("\t\t\t\toSession.CloseSocket(); return;\r\n\t\t\t}}\r\n", new object[0]);
                 num++;
                 if (evtProgressNotifications != null)
                 {
                     ProgressCallbackEventArgs e = new ProgressCallbackEventArgs(((float) num) / ((float) oSessions.Length), "Added " + num.ToString() + " sessions to MeddlerScript.");
                     evtProgressNotifications(null, e);
                     if (e.Cancel)
                     {
                         return false;
                     }
                 }
             }
             this.PrependMeddlerHeader(sb, str2 ?? "http://localhost:{$PORT}/");
             this.EmitMeddlerFooter(sb);
             File.WriteAllText(str, sb.ToString());
             return true;
         }
         catch (Exception exception)
         {
             FiddlerApplication.ReportException(exception, "Failed to save MeddlerScript");
             return false;
         }
     }
     return false;
 }
Пример #4
0
 public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
 {
     if (sFormat != "WCAT Script")
     {
         return false;
     }
     string str = null;
     if ((dictOptions != null) && dictOptions.ContainsKey("Filename"))
     {
         str = dictOptions["Filename"] as string;
     }
     if (string.IsNullOrEmpty(str))
     {
         str = Utilities.ObtainSaveFilename("Export As " + sFormat, "WCAT Script (*.wcat)|*.wcat");
     }
     if (!string.IsNullOrEmpty(str))
     {
         try
         {
             StringBuilder sb = new StringBuilder();
             this.EmitScenarioHeader(sb);
             int num = 0;
             foreach (Session session in oSessions)
             {
                 if (session.HTTPMethodIs("GET") || session.HTTPMethodIs("POST"))
                 {
                     sb.AppendLine("    request");
                     sb.AppendLine("    {");
                     if (session.HTTPMethodIs("POST"))
                     {
                         sb.AppendLine("      verb = POST;");
                         sb.AppendFormat("      postdata = \"{0}\";", Encoding.UTF8.GetString(session.requestBodyBytes).Replace("\"", "\\\""));
                     }
                     sb.AppendFormat("      url     = \"{0}\";", session.PathAndQuery.Replace("\"", "\\\""));
                     foreach (HTTPHeaderItem item in session.oRequest.headers)
                     {
                         this.EmitRequestHeaderEntry(sb, item.Name, item.Value);
                     }
                     sb.AppendLine("    }");
                     num++;
                     if (evtProgressNotifications != null)
                     {
                         ProgressCallbackEventArgs e = new ProgressCallbackEventArgs(((float) num) / ((float) oSessions.Length), "Added " + num.ToString() + " sessions to WCAT Script.");
                         evtProgressNotifications(null, e);
                         if (e.Cancel)
                         {
                             return false;
                         }
                     }
                 }
             }
             sb.AppendLine("  }\r\n}");
             File.WriteAllText(str, sb.ToString());
             return true;
         }
         catch (Exception exception)
         {
             FiddlerApplication.ReportException(exception, "Failed to save WCAT Script");
             return false;
         }
     }
     return false;
 }
Пример #5
0
 internal static bool WriteStream(StreamWriter swOutput, Session[] oSessions, bool bUseV1dot2Format, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications, int iMaxTextBodyLength, int iMaxBinaryBodyLength)
 {
     _iMaxTextBodyLength = iMaxTextBodyLength;
     _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 list = new ArrayList();
     int num = 0;
     foreach (Session session in oSessions)
     {
         try
         {
             if (session.state < SessionStates.Done)
             {
                 continue;
             }
             Hashtable hashtable3 = new Hashtable();
             hashtable3.Add("startedDateTime", session.Timers.ClientBeginRequest.ToString("o"));
             hashtable3.Add("request", getRequest(session));
             hashtable3.Add("response", getResponse(session, bUseV1dot2Format));
             hashtable3.Add("cache", new Hashtable());
             Hashtable htTimers = getTimings(session.Timers, bUseV1dot2Format);
             hashtable3.Add("time", getTotalTime(htTimers));
             hashtable3.Add("timings", htTimers);
             if (bUseV1dot2Format)
             {
                 string str = session["ui-comments"];
                 if (!string.IsNullOrEmpty(str))
                 {
                     hashtable3.Add("comment", session["ui-comments"]);
                 }
                 string hostIP = session.m_hostIP;
                 if (!string.IsNullOrEmpty(str) && !session.isFlagSet(SessionFlags.SentToGateway))
                 {
                     hashtable3.Add("serverIPAddress", session.m_hostIP);
                 }
                 hashtable3.Add("connection", session.clientPort.ToString());
             }
             list.Add(hashtable3);
         }
         catch (Exception exception)
         {
             FiddlerApplication.ReportException(exception, "Failed to Export Session");
         }
         num++;
         if (evtProgressNotifications != null)
         {
             ProgressCallbackEventArgs e = new ProgressCallbackEventArgs(((float) num) / ((float) oSessions.Length), "Wrote " + num.ToString() + " sessions to HTTPArchive.");
             evtProgressNotifications(null, e);
             if (e.Cancel)
             {
                 return false;
             }
         }
     }
     hashtable.Add("entries", list);
     Hashtable json = new Hashtable();
     json.Add("log", hashtable);
     swOutput.WriteLine(JSON.JsonEncode(json));
     return true;
 }