Example #1
0
 public Session[] ImportSessions(string sFormat, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
 {
     if (sFormat == "HTTPArchive")
     {
         string str = null;
         if ((dictOptions != null) && dictOptions.ContainsKey("Filename"))
         {
             str = dictOptions["Filename"] as string;
         }
         if (string.IsNullOrEmpty(str))
         {
             str = Utilities.ObtainOpenFilename("Import " + sFormat, "HTTPArchive JSON (*.har)|*.har");
         }
         if (!string.IsNullOrEmpty(str))
         {
             try
             {
                 List <Session> listSessions = new List <Session>();
                 StreamReader   oSR          = new StreamReader(str, Encoding.UTF8);
                 HTTPArchiveJSONImport.LoadStream(oSR, listSessions, evtProgressNotifications);
                 oSR.Close();
                 return(listSessions.ToArray());
             }
             catch (Exception exception)
             {
                 FiddlerApplication.ReportException(exception, "Failed to import HTTPArchive");
                 return(null);
             }
         }
     }
     return(null);
 }
Example #2
0
        public static bool LoadStream(StreamReader oSR, List <Session> listSessions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            string text = oSR.ReadToEnd();

            JSON.JSONParseErrors jSONParseErrors;
            Hashtable            hashtable = JSON.JsonDecode(text, ref jSONParseErrors) as Hashtable;

            if (hashtable == null)
            {
                MessageBox.Show("This file is not properly formatted HAR JSON", "Import aborted");
                return(false);
            }
            Hashtable hashtable2 = hashtable["log"] as Hashtable;
            ArrayList arrayList;

            if (hashtable2 != null)
            {
                if (evtProgressNotifications != null)
                {
                    evtProgressNotifications(null, new ProgressCallbackEventArgs(0f, "Found HTTPArchive v" + hashtable2["version"] + "..."));
                }
                arrayList = (ArrayList)hashtable2["entries"];
            }
            else
            {
                MessageBox.Show("This file is not properly formatted HAR JSON.\n\nNote: Chrome does not save valid HAR content when you use 'Save Entry as HAR'. It only generates a valid file if you use 'Save All as HAR'", "Warning");
                arrayList = new ArrayList();
                arrayList.Add(hashtable);
            }
            int num   = 0;
            int count = arrayList.Count;

            foreach (Hashtable htEntry in arrayList)
            {
                try
                {
                    Session session = HTTPArchiveJSONImport._getSessionFromEntry(htEntry);
                    if (session != null)
                    {
                        num++;
                        listSessions.Add(session);
                        if (evtProgressNotifications != null)
                        {
                            evtProgressNotifications(null, new ProgressCallbackEventArgs((float)(num / count), "Imported " + num.ToString() + " sessions."));
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (evtProgressNotifications != null)
                    {
                        evtProgressNotifications(null, new ProgressCallbackEventArgs((float)(num / count), "Skipping malformed session." + ex.Message));
                    }
                }
            }
            return(true);
        }
Example #3
0
        private static Session _getSessionFromEntry(Hashtable htEntry)
        {
            Hashtable htRequest = (Hashtable)htEntry["request"];

            byte[]    array     = HTTPArchiveJSONImport._getRequestFromEntry(htRequest);
            Hashtable hashtable = (Hashtable)htEntry["response"];

            byte[] array2 = HTTPArchiveJSONImport._getResponseFromEntry(hashtable);
            if (array == null || array2 == null)
            {
                MessageBox.Show("Failed to get session from entry");
                return(null);
            }
            SessionFlags sessionFlags = 64;
            Session      session      = new Session(array, array2, sessionFlags);
            int          totalSize    = HTTPArchiveJSONImport.getTotalSize(hashtable);

            if (totalSize > 0)
            {
                session.set_Item("X-TRANSFER-SIZE", totalSize.ToString());
            }
            if (htEntry.ContainsKey("comment"))
            {
                string text = (string)htEntry["comment"];
                if (!string.IsNullOrEmpty(text))
                {
                    session.set_Item("ui-comments", text);
                }
            }
            DateTime now;

            if (!DateTime.TryParse((string)htEntry["startedDateTime"], out now))
            {
                now = DateTime.Now;
            }
            if (htEntry.ContainsKey("timings"))
            {
                Hashtable htTimers = (Hashtable)htEntry["timings"];
                session.Timers.DNSTime             = HTTPArchiveJSONImport.getMilliseconds(htTimers, "dns");
                session.Timers.TCPConnectTime      = HTTPArchiveJSONImport.getMilliseconds(htTimers, "connect");
                session.Timers.HTTPSHandshakeTime  = HTTPArchiveJSONImport.getMilliseconds(htTimers, "ssl");
                session.Timers.ClientConnected     = (session.Timers.ClientBeginRequest = (session.Timers.FiddlerGotRequestHeaders = (session.Timers.ClientDoneRequest = now)));
                session.Timers.ServerConnected     = (session.Timers.FiddlerBeginRequest = now.AddMilliseconds((double)(HTTPArchiveJSONImport.getMilliseconds(htTimers, "blocked") + session.Timers.DNSTime + session.Timers.TCPConnectTime + session.Timers.HTTPSHandshakeTime)));
                session.Timers.ServerGotRequest    = session.Timers.FiddlerBeginRequest.AddMilliseconds((double)HTTPArchiveJSONImport.getMilliseconds(htTimers, "send"));
                session.Timers.ServerBeginResponse = (session.Timers.FiddlerGotResponseHeaders = session.Timers.ServerGotRequest.AddMilliseconds((double)HTTPArchiveJSONImport.getMilliseconds(htTimers, "wait")));
                session.Timers.ServerDoneResponse  = session.Timers.ServerBeginResponse.AddMilliseconds((double)HTTPArchiveJSONImport.getMilliseconds(htTimers, "receive"));
                session.Timers.ClientBeginResponse = (session.Timers.ClientDoneResponse = session.Timers.ServerDoneResponse);
            }
            return(session);
        }
Example #4
0
        private static byte[] _getRequestFromEntry(Hashtable htRequest)
        {
            string text  = (string)htRequest["method"];
            string text2 = htRequest["httpVersion"] as string;

            if (string.IsNullOrEmpty(text2))
            {
                text2 = "HTTP/0.0";
            }
            string text3 = (string)htRequest["url"];
            string text4 = HTTPArchiveJSONImport._getHeaderStringFromArrayList((ArrayList)htRequest["headers"]);
            string text5 = string.Empty;

            if (htRequest.ContainsKey("postData"))
            {
                Hashtable hashtable = htRequest["postData"] as Hashtable;
                if (hashtable != null)
                {
                    if (hashtable.ContainsKey("text"))
                    {
                        text5 = (string)hashtable["text"];
                    }
                    else
                    {
                        if (hashtable.ContainsKey("params"))
                        {
                            text5 = HTTPArchiveJSONImport._getStringFromParams((ArrayList)hashtable["params"]);
                        }
                    }
                }
            }
            if (string.Equals("CONNECT", text, StringComparison.OrdinalIgnoreCase))
            {
                text3 = Utilities.TrimBeforeLast(text3, '/');
            }
            string s = string.Format("{0} {1} {2}\r\n{3}\r\n{4}", new object[]
            {
                text,
                text3,
                text2,
                text4,
                text5
            });

            return(CONFIG.oHeaderEncoding.GetBytes(s));
        }
Example #5
0
        private static byte[] _getResponseFromEntry(Hashtable htResponse)
        {
            string text  = ((double)htResponse["status"]).ToString();
            string text2 = (string)htResponse["statusText"];
            string text3 = htResponse["httpVersion"] as string;

            if (string.IsNullOrEmpty(text3))
            {
                text3 = "HTTP/0.0";
            }
            else
            {
                if (text3.Contains(" "))
                {
                    text3 = text3.Replace(' ', '_');
                }
                else
                {
                    if (text3.StartsWith("1."))
                    {
                        text3 = "HTTP/" + text3;
                    }
                }
            }
            string text4 = HTTPArchiveJSONImport._getHeaderStringFromArrayList((ArrayList)htResponse["headers"]);

            byte[] array = HTTPArchiveJSONImport._getBodyArrayFromContent((Hashtable)htResponse["content"], text4);
            string s     = string.Format("{0} {1} {2}\r\n{3}\r\n", new object[]
            {
                text3,
                text,
                text2,
                text4
            });

            byte[] bytes  = CONFIG.oHeaderEncoding.GetBytes(s);
            byte[] array2 = new byte[bytes.Length + array.Length];
            Buffer.BlockCopy(bytes, 0, array2, 0, bytes.Length);
            Buffer.BlockCopy(array, 0, array2, bytes.Length, array.Length);
            return(array2);
        }
Example #6
0
        public Session[] ImportSessions(string sFormat, Dictionary <string, object> dictOptions, EventHandler <ProgressCallbackEventArgs> evtProgressNotifications)
        {
            if (sFormat != "HTTPArchive")
            {
                return(null);
            }
            string text = null;

            if (dictOptions != null && dictOptions.ContainsKey("Filename"))
            {
                text = (dictOptions["Filename"] as string);
            }
            if (string.IsNullOrEmpty(text))
            {
                text = Utilities.ObtainOpenFilename("Import " + sFormat, "HTTPArchive JSON (*.har)|*.har");
            }
            if (!string.IsNullOrEmpty(text))
            {
                try
                {
                    List <Session> list         = new List <Session>();
                    StreamReader   streamReader = new StreamReader(text, Encoding.UTF8);
                    HTTPArchiveJSONImport.LoadStream(streamReader, list, evtProgressNotifications);
                    streamReader.Close();
                    Session[] result = list.ToArray();
                    return(result);
                }
                catch (Exception ex)
                {
                    FiddlerApplication.ReportException(ex, "Failed to import HTTPArchive");
                    Session[] result = null;
                    return(result);
                }
            }
            return(null);
        }