コード例 #1
0
ファイル: FileDumper.cs プロジェクト: Domer79/CIAPI.CS
 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;
 }
コード例 #2
0
ファイル: FileDumper.cs プロジェクト: fagan2888/CIAPI.CS
        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 != "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);
        }