Ejemplo n.º 1
0
        private static int getTotalTime(Hashtable htTimers)
        {
            int num = 0;

            num += HTTPArchiveJSONExport.getMilliseconds(htTimers, "blocked");
            num += HTTPArchiveJSONExport.getMilliseconds(htTimers, "dns");
            num += HTTPArchiveJSONExport.getMilliseconds(htTimers, "connect");
            num += HTTPArchiveJSONExport.getMilliseconds(htTimers, "send");
            num += HTTPArchiveJSONExport.getMilliseconds(htTimers, "wait");
            return(num + HTTPArchiveJSONExport.getMilliseconds(htTimers, "receive"));
        }
Ejemplo n.º 2
0
        private static Hashtable getResponse(Session oS, bool bUseV1dot2Format)
        {
            return(new Hashtable
            {
                {
                    "status",
                    oS.get_responseCode()
                },

                {
                    "statusText",
                    Utilities.TrimBefore(oS.oResponse.get_headers().HTTPResponseStatus, ' ')
                },

                {
                    "httpVersion",
                    oS.oResponse.get_headers().HTTPVersion
                },

                {
                    "headersSize",
                    oS.oResponse.get_headers().ByteCount() + 2
                },

                {
                    "redirectURL",
                    oS.oResponse.get_headers().get_Item("Location")
                },

                {
                    "bodySize",
                    (oS.responseBodyBytes == null) ? 0 : oS.responseBodyBytes.Length
                },

                {
                    "headers",
                    HTTPArchiveJSONExport.getHeadersAsArrayList(oS.oResponse.get_headers())
                },

                {
                    "cookies",
                    HTTPArchiveJSONExport.getCookies(oS.oResponse.get_headers())
                },

                {
                    "content",
                    HTTPArchiveJSONExport.getBodyInfo(oS, bUseV1dot2Format)
                }
            });
        }
Ejemplo n.º 3
0
        public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sFormat != "HTTPArchive v1.1" && sFormat != "HTTPArchive v1.2")
            {
                return(false);
            }
            bool   result = false;
            string text   = null;
            int    iMaxBinaryBodyLength = FiddlerApplication.get_Prefs().GetInt32Pref("fiddler.importexport.HTTPArchiveJSON.MaxBinaryBodyLength", 32768);
            int    iMaxTextBodyLength   = FiddlerApplication.get_Prefs().GetInt32Pref("fiddler.importexport.HTTPArchiveJSON.MaxTextBodyLength", 22);

            if (dictOptions != null)
            {
                if (dictOptions.ContainsKey("Filename"))
                {
                    text = (dictOptions["Filename"] as string);
                }
                if (dictOptions.ContainsKey("MaxTextBodyLength"))
                {
                    iMaxTextBodyLength = (int)dictOptions["MaxTextBodyLength"];
                }
                if (dictOptions.ContainsKey("MaxBinaryBodyLength"))
                {
                    iMaxBinaryBodyLength = (int)dictOptions["MaxBinaryBodyLength"];
                }
            }
            if (string.IsNullOrEmpty(text))
            {
                text = Utilities.ObtainSaveFilename("Export As " + sFormat, "HTTPArchive JSON (*.har)|*.har");
            }
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    StreamWriter streamWriter = new StreamWriter(text, false, Encoding.UTF8);
                    HTTPArchiveJSONExport.WriteStream(streamWriter, oSessions, sFormat == "HTTPArchive v1.2", evtProgressNotifications, iMaxTextBodyLength, iMaxBinaryBodyLength);
                    streamWriter.Close();
                    bool result2 = true;
                    return(result2);
                }
                catch (Exception ex)
                {
                    FiddlerApplication.ReportException(ex, "Failed to save HTTPArchive");
                    bool result2 = false;
                    return(result2);
                }
                return(result);
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static Hashtable getBodyInfo(Session oS, bool bUseV1dot2Format)
        {
            Hashtable hashtable = new Hashtable();
            int       num;
            int       num2;

            HTTPArchiveJSONExport.getDecompressedSize(oS, out num, out num2);
            hashtable.Add("size", num);
            hashtable.Add("compression", num2);
            hashtable.Add("mimeType", oS.oResponse.get_Item("Content-Type"));
            if (oS.responseBodyBytes == null)
            {
                return(hashtable);
            }
            string mIMEType = oS.oResponse.get_MIMEType();
            bool   flag     = HTTPArchiveJSONExport.IsMIMETypeTextEquivalent(mIMEType);

            if (flag && "text/plain" == mIMEType && oS.responseBodyBytes.Length > 3 && ((oS.responseBodyBytes[0] == 67 && oS.responseBodyBytes[1] == 87 && oS.responseBodyBytes[2] == 83) || (oS.responseBodyBytes[0] == 70 && oS.responseBodyBytes[1] == 76 && oS.responseBodyBytes[2] == 86)))
            {
                flag = false;
            }
            if (flag)
            {
                if (oS.responseBodyBytes.Length < HTTPArchiveJSONExport._iMaxTextBodyLength)
                {
                    hashtable.Add("text", oS.GetResponseBodyAsString());
                }
                else
                {
                    hashtable.Add("comment", "Body length exceeded fiddler.importexport.HTTPArchiveJSON.MaxTextBodyLength, so body was omitted.");
                }
            }
            else
            {
                if (bUseV1dot2Format)
                {
                    if (oS.responseBodyBytes.Length < HTTPArchiveJSONExport._iMaxBinaryBodyLength)
                    {
                        hashtable.Add("encoding", "base64");
                        hashtable.Add("text", Convert.ToBase64String(oS.responseBodyBytes));
                    }
                    else
                    {
                        hashtable.Add("comment", "Body length exceeded fiddler.importexport.HTTPArchiveJSON.MaxBinaryBodyLength, so body was omitted.");
                    }
                }
            }
            return(hashtable);
        }
Ejemplo n.º 5
0
        private static Hashtable getPostData(Session oS)
        {
            Hashtable hashtable = new Hashtable();
            string    text      = oS.oRequest.get_Item("Content-Type");

            hashtable.Add("mimeType", Utilities.TrimAfter(text, ';'));
            if (text.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
            {
                hashtable.Add("params", HTTPArchiveJSONExport.getQueryString("http://fake/path?" + oS.GetRequestBodyAsString()));
            }
            else
            {
                hashtable.Add("text", oS.GetRequestBodyAsString());
            }
            return(hashtable);
        }
Ejemplo n.º 6
0
        public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if ((sFormat != "HTTPArchive v1.1") && (sFormat != "HTTPArchive v1.2"))
            {
                return(false);
            }
            string str = null;
            int    iMaxBinaryBodyLength = FiddlerApplication.Prefs.GetInt32Pref("fiddler.importexport.HTTPArchiveJSON.MaxBinaryBodyLength", 0x8000);
            int    iMaxTextBodyLength   = FiddlerApplication.Prefs.GetInt32Pref("fiddler.importexport.HTTPArchiveJSON.MaxTextBodyLength", 0x16);

            if (dictOptions != null)
            {
                if (dictOptions.ContainsKey("Filename"))
                {
                    str = dictOptions["Filename"] as string;
                }
                if (dictOptions.ContainsKey("MaxTextBodyLength"))
                {
                    iMaxTextBodyLength = (int)dictOptions["MaxTextBodyLength"];
                }
                if (dictOptions.ContainsKey("MaxBinaryBodyLength"))
                {
                    iMaxBinaryBodyLength = (int)dictOptions["MaxBinaryBodyLength"];
                }
            }
            if (string.IsNullOrEmpty(str))
            {
                str = Utilities.ObtainSaveFilename("Export As " + sFormat, "HTTPArchive JSON (*.har)|*.har");
            }
            if (!string.IsNullOrEmpty(str))
            {
                try
                {
                    StreamWriter swOutput = new StreamWriter(str, false, Encoding.UTF8);
                    HTTPArchiveJSONExport.WriteStream(swOutput, oSessions, sFormat == "HTTPArchive v1.2", evtProgressNotifications, iMaxTextBodyLength, iMaxBinaryBodyLength);
                    swOutput.Close();
                    return(true);
                }
                catch (Exception exception)
                {
                    FiddlerApplication.ReportException(exception, "Failed to save HTTPArchive");
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        private static Hashtable getRequest(Session oS)
        {
            Hashtable hashtable = new Hashtable();

            hashtable.Add("method", oS.oRequest.get_headers().HTTPMethod);
            hashtable.Add("url", oS.get_fullUrl());
            hashtable.Add("httpVersion", oS.oRequest.get_headers().HTTPVersion);
            hashtable.Add("headersSize", oS.oRequest.get_headers().ByteCount() + 2);
            hashtable.Add("bodySize", oS.requestBodyBytes.Length);
            hashtable.Add("headers", HTTPArchiveJSONExport.getHeadersAsArrayList(oS.oRequest.get_headers()));
            hashtable.Add("cookies", HTTPArchiveJSONExport.getCookies(oS.oRequest.get_headers()));
            hashtable.Add("queryString", HTTPArchiveJSONExport.getQueryString(oS.get_fullUrl()));
            if (oS.requestBodyBytes != null && oS.requestBodyBytes.Length > 0)
            {
                hashtable.Add("postData", HTTPArchiveJSONExport.getPostData(oS));
            }
            return(hashtable);
        }
Ejemplo n.º 8
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);
        }