Esempio n. 1
0
        private void mTimer_Tick(object pSender, EventArgs pArgs)
        {
            Packet packet = null;

            try
            {
                while ((packet = mDevice.GetNextPacket()) != null)
                {
                    TCPPacket   tcpPacket = packet as TCPPacket;
                    SessionForm session   = null;
                    if (tcpPacket.Syn && !tcpPacket.Ack)
                    {
                        session = NewSession();
                    }
                    else
                    {
                        session = Array.Find(MdiChildren, f => (f as SessionForm).MatchTCPPacket(tcpPacket)) as SessionForm;
                    }
                    if (session != null)
                    {
                        session.BufferTCPPacket(tcpPacket);
                    }
                }
            }
            catch { }
        }
Esempio n. 2
0
        private void MainForm_Load(object pSender, EventArgs pArgs)
        {
            if (!Config.Instance.LoadedFromFile)
            {
                if (ShowSetupForm() != DialogResult.OK)
                {
                    Close();
                    return;
                }
            }

            SetupAdapter();

            mTimer.Enabled = true;

            mSearchForm.Show(mDockPanel);
            mDataForm.Show(mDockPanel);
            mStructureForm.Show(mDockPanel);
            mPropertyForm.Show(mDockPanel);
            DockPane rightPane1 = new DockPane(mStructureForm, DockState.DockRight, true);
            DockPane rightPane2 = new DockPane(mPropertyForm, DockState.DockRight, true);

            rightPane1.Show();
            rightPane2.Show();


            foreach (string arg in _startupArguments)
            {
                SessionForm session = NewSession();
                session.OpenReadOnly(arg);
                session.Show(mDockPanel, DockState.Document);
            }
        }
Esempio n. 3
0
        private SessionForm NewSession()
        {
            SessionForm session = new SessionForm();

            session.Show(mDockPanel, DockState.Document);
            return(session);
        }
Esempio n. 4
0
        private void mFileImportMenu_Click(object pSender, EventArgs pArgs)
        {
            if (mImportDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            PcapOfflineDevice device = new PcapOfflineDevice(mImportDialog.FileName);

            device.Open();

            Packet      packet  = null;
            SessionForm session = null;

            while ((packet = device.GetNextPacket()) != null)
            {
                TCPPacket tcpPacket = packet as TCPPacket;
                if (tcpPacket == null)
                {
                    continue;
                }
                if ((tcpPacket.SourcePort < Config.Instance.LowPort || tcpPacket.SourcePort > Config.Instance.HighPort) &&
                    (tcpPacket.DestinationPort < Config.Instance.LowPort || tcpPacket.DestinationPort > Config.Instance.HighPort))
                {
                    continue;
                }
                if (tcpPacket.Syn && !tcpPacket.Ack)
                {
                    session = NewSession(); session.BufferTCPPacket(tcpPacket);
                }
                else if (session.MatchTCPPacket(tcpPacket))
                {
                    session.BufferTCPPacket(tcpPacket);
                }
            }
        }
Esempio n. 5
0
        public void RefreshOpcodes(bool pReselect)
        {
            SessionForm         session  = DockPanel.ActiveDocument as SessionForm;
            Pair <bool, ushort> selected = pReselect && session != null && mOpcodeCombo.SelectedIndex >= 0 ? session.Opcodes[mOpcodeCombo.SelectedIndex] : null;

            mOpcodeCombo.Items.Clear();
            if (session == null)
            {
                return;
            }
            foreach (Pair <bool, ushort> kv in session.Opcodes)
            {
                Definition definition = Config.Instance.Definitions.Find(d => d.Outbound == kv.First && d.Opcode == kv.Second);
                int        addedIndex = -1;
                if (definition == null || string.IsNullOrEmpty(definition.Name))
                {
                    addedIndex = mOpcodeCombo.Items.Add((kv.First ? "Outbound  " : "Inbound   ") + "0x" + kv.Second.ToString("X4"));
                }
                else
                {
                    addedIndex = mOpcodeCombo.Items.Add(definition.Name);
                }
                if (selected != null && selected.First == kv.First && selected.Second == kv.Second)
                {
                    mOpcodeCombo.SelectedIndex = addedIndex;
                }
            }
        }
Esempio n. 6
0
        private void mPrevOpcode_Click(object sender, EventArgs e)
        {
            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null || mOpcodeCombo.SelectedIndex < 0)
            {
                return;
            }
            Pair <bool, ushort> search = (DockPanel.ActiveDocument as SessionForm).Opcodes[mOpcodeCombo.SelectedIndex];
            int initialIndex           = session.ListView.SelectedIndices.Count == 0 ? 0 : session.ListView.SelectedIndices[0];

            for (int index = initialIndex; index >= 0; --index)
            {
                FiestaPacket packet = session.ListView.Items[index] as FiestaPacket;
                if (packet.Outbound == search.First && packet.Opcode == search.Second)
                {
                    session.ListView.SelectedIndices.Clear();
                    session.ListView.SelectedIndices.Add(index);
                    packet.EnsureVisible();
                    session.ListView.Focus();
                    return;
                }
            }
            MessageBox.Show("No further packets found with the selected opcode.", "End Of Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
            session.ListView.Focus();
        }
Esempio n. 7
0
        private void mNextOpcodeButton_Click(object pSender, EventArgs pArgs)
        {
            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null || mOpcodeCombo.SelectedIndex == -1)
            {
                return;
            }
            Opcode search       = (DockPanel.ActiveDocument as SessionForm).Opcodes[mOpcodeCombo.SelectedIndex];
            int    initialIndex = session.ListView.SelectedIndices.Count == 0 ? 0 : session.ListView.SelectedIndices[0] + 1;

            for (int index = initialIndex; index < session.ListView.Items.Count; ++index)
            {
                MaplePacket packet = session.ListView.Items[index] as MaplePacket;
                if (packet.Outbound == search.Outbound && packet.Opcode == search.Header)
                {
                    session.ListView.SelectedIndices.Clear();
                    session.ListView.SelectedIndices.Add(index);
                    packet.EnsureVisible();
                    session.ListView.Focus();
                    return;
                }
            }
            MessageBox.Show("No further packets found with the selected opcode.", "End Of Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
            session.ListView.Focus();
        }
Esempio n. 8
0
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            SessionForm session = mDockPanel.ActiveDocument as SessionForm;

            if (session != null)
            {
                session.RunSaveCMD();
            }
        }
Esempio n. 9
0
        void ParseImportedFile()
        {
            while (device.Opened)
            {
                RawCapture  packet  = null;
                SessionForm session = null;
                while ((packet = device.GetNextPacket()) != null)
                {
                    if (!started)
                    {
                        continue;
                    }
                    TcpPacket tcpPacket = TcpPacket.GetEncapsulated(Packet.ParsePacket(packet.LinkLayerType, packet.Data));
                    if (tcpPacket == null)
                    {
                        continue;
                    }

                    if ((tcpPacket.SourcePort < Config.Instance.LowPort || tcpPacket.SourcePort > Config.Instance.HighPort) &&
                        (tcpPacket.DestinationPort < Config.Instance.LowPort || tcpPacket.DestinationPort > Config.Instance.HighPort))
                    {
                        continue;
                    }
                    this.Invoke((MethodInvoker) delegate {
                        try
                        {
                            if (tcpPacket.Syn && !tcpPacket.Ack)
                            {
                                session = NewSession();
                                var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                                if (res == SessionForm.Results.Continue)
                                {
                                    session.Show(mDockPanel, DockState.Document);
                                }
                            }
                            else if (session != null && session.MatchTCPPacket(tcpPacket))
                            {
                                var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                                if (res == SessionForm.Results.CloseMe)
                                {
                                    session.Close();
                                }
                            }
                        }
                        catch (Exception)
                        {
                            session.Close();
                            session = null;
                        }
                    });
                }
                this.Invoke((MethodInvoker) delegate {
                    mSearchForm.RefreshOpcodes(false);
                });
            }
        }
Esempio n. 10
0
 public MainForm(string[] pArgs)
 {
     InitializeComponent();
     Text = "MapleShark " + Program.AssemblyVersion;
     foreach (string arg in pArgs)
     {
         SessionForm session = NewSession();
         session.OpenReadOnly(arg);
     }
 }
Esempio n. 11
0
 private void mFileOpenMenu_Click(object pSender, EventArgs pArgs)
 {
     if (mOpenDialog.ShowDialog(this) == DialogResult.OK)
     {
         foreach (string path in mOpenDialog.FileNames)
         {
             SessionForm session = NewSession();
             session.OpenReadOnly(mOpenDialog.FileName);
         }
     }
 }
Esempio n. 12
0
 public MainForm(string[] pArgs)
 {
     InitializeComponent();
     Text = "ElShark " + Program.AssemblyVersion;
     foreach (string arg in pArgs)
     {
         SessionForm session = NewSession();
         session.OpenReadOnly(arg);
         session.Show(mDockPanel, DockState.Document);
     }
 }
Esempio n. 13
0
 private void mFileOpenMenu_Click(object pSender, EventArgs pArgs)
 {
     if (mOpenDialog.ShowDialog(this) == DialogResult.OK)
     {
         foreach (string path in mOpenDialog.FileNames)
         {
             SessionForm session = NewSession();
             session.OpenReadOnly(path);
             session.Show(mDockPanel, DockState.Document);
         }
         mSearchForm.RefreshOpcodes(false);
     }
 }
Esempio n. 14
0
        private void NextSequence()
        {
            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null)
            {
                return;
            }
            int initialIndex = session.ListView.SelectedIndices.Count == 0 ? 0 : session.ListView.SelectedIndices[0];

            byte[] pattern    = (mSequenceHex.ByteProvider as DynamicByteProvider).Bytes.ToArray();
            long   startIndex = MainForm.DataForm.HexBox.SelectionLength > 0 ? MainForm.DataForm.HexBox.SelectionStart : -1;

            for (int index = initialIndex; index < session.ListView.Items.Count; ++index)
            {
                MaplePacket packet      = session.ListView.Items[index] as MaplePacket;
                long        searchIndex = startIndex + 1;
                bool        found       = false;
                while (searchIndex <= packet.Buffer.Length - pattern.Length)
                {
                    found = true;
                    for (int patternIndex = 0; found && patternIndex < pattern.Length; ++patternIndex)
                    {
                        found = packet.Buffer[searchIndex + patternIndex] == pattern[patternIndex];
                    }
                    if (found)
                    {
                        break;
                    }
                    ++searchIndex;
                }
                if (found)
                {
                    session.ListView.SelectedIndices.Clear();
                    session.ListView.SelectedIndices.Add(index);
                    packet.EnsureVisible();
                    MainForm.DataForm.HexBox.SelectionStart  = searchIndex;
                    MainForm.DataForm.HexBox.SelectionLength = pattern.Length;
                    MainForm.DataForm.HexBox.ScrollByteIntoView();
                    session.ListView.Focus();
                    return;
                }
                startIndex = -1;
            }
            MessageBox.Show("No further sequences found.", "End Of Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
            session.ListView.Focus();
        }
Esempio n. 15
0
        private void ReadMSnifferFile(string filename)
        {
            SessionForm currentSession = null;
            Regex       captureRegex   = new Regex(@"MapleStory ([^\(]+)\(版本([0-9\.]+)\).*");

            using (StreamReader sr = new StreamReader(filename))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line == "")
                    {
                        continue;
                    }

                    if (line[0] == '1')
                    {
                        // Most likely capturing text
                        var matches = captureRegex.Match(line);
                        if (matches.Captures.Count == 0)
                        {
                            continue;
                        }

                        Console.WriteLine("Version: {1} : {0}  ", matches.Groups[2].Value, matches.Groups[1].Value);

                        if (currentSession != null)
                        {
                            currentSession.Show(mDockPanel, DockState.Document);
                        }

                        currentSession = NewSession();
                        currentSession.SetMapleInfo((ushort)(double.Parse(matches.Groups[2].Value)), "", 8, matches.Groups[2].Value, 0);
                    }
                    //else if (line[0] == '[' && currentSession != null)
                    else if (currentSession != null)
                    {
                        currentSession.ParseMSnifferLine(line);
                    }
                }
            }

            if (currentSession != null)
            {
                currentSession.Show(mDockPanel, DockState.Document);
            }
        }
Esempio n. 16
0
        private void ReadMSnifferFile(string filename)
        {
            SessionForm currentSession = null;
            Regex       captureRegex   = new Regex(@"Capturing MapleStory version (\d+) on ([0-9\.]+):(\d+) with unknown ""(.*)"".*");

            using (StreamReader sr = new StreamReader(filename))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line == "" || (line[0] != '[' && line[0] != 'C'))
                    {
                        continue;
                    }

                    if (line[0] == 'C')
                    {
                        // Most likely capturing text
                        var matches = captureRegex.Match(line);
                        if (matches.Captures.Count == 0)
                        {
                            continue;
                        }

                        Console.WriteLine("Version: {0}.{1} IP {2} Port {3}", matches.Groups[1].Value, matches.Groups[4].Value, matches.Groups[2].Value, matches.Groups[3].Value);

                        if (currentSession != null)
                        {
                            currentSession.Show(mDockPanel, DockState.Document);
                        }

                        currentSession = NewSession();
                        currentSession.SetMapleInfo(ushort.Parse(matches.Groups[1].Value), matches.Groups[4].Value, 8, matches.Groups[2].Value, ushort.Parse(matches.Groups[3].Value));
                    }
                    else if (line[0] == '[' && currentSession != null)
                    {
                        currentSession.ParseMSnifferLine(line);
                    }
                }
            }

            if (currentSession != null)
            {
                currentSession.Show(mDockPanel, DockState.Document);
            }
        }
Esempio n. 17
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Try to close all sessions
            List <SessionForm> sessionForms = new List <SessionForm>();

            foreach (var form in mDockPanel.Contents)
            {
                if (form is SessionForm)
                {
                    sessionForms.Add(form as SessionForm);
                }
            }

            int  sessions          = sessionForms.Count;
            bool doSaveQuestioning = true;

            if (sessions > 5)
            {
                doSaveQuestioning = MessageBox.Show("You've got " + sessions + " sessions open. Say 'Yes' if you want to get a question for each session, 'No' if you want to quit MapleShark.", "MapleShark", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes;
            }

            while (doSaveQuestioning && sessionForms.Count > 0)
            {
                SessionForm ses = sessionForms[0];
                if (!ses.Saved)
                {
                    ses.Focus();
                    DialogResult result = MessageBox.Show(string.Format("Do you want to save the session '{0}'?", ses.Text), "MapleShark", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        ses.RunSaveCMD();
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        e.Cancel = true;

                        return;
                    }
                }
                mDockPanel.Contents.Remove(ses);
                sessionForms.Remove(ses);
            }

            DefinitionsContainer.Instance.Save();
        }
Esempio n. 18
0
 private void mDockPanel_ActiveDocumentChanged(object pSender, EventArgs pArgs)
 {
     if (!mClosed)
     {
         SessionForm session = mDockPanel.ActiveDocument as SessionForm;
         if (session != null)
         {
             session.RefreshPackets();
         }
         else
         {
             if (mDataForm.HexBox.ByteProvider != null)
             {
                 mDataForm.HexBox.ByteProvider.DeleteBytes(0, mDataForm.HexBox.ByteProvider.Length);
             }
             mStructureForm.Tree.Nodes.Clear();
             mPropertyForm.Properties.SelectedObject = null;
         }
     }
 }
Esempio n. 19
0
        private void mNextOpcodeButton_Click(object pSender, EventArgs pArgs)
        {
            bool headerDefined = HeaderBox.Text != "";
            byte header        = 0;

            if (headerDefined)
            {
                header = byte.Parse(HeaderBox.Text);
            }
            bool typeDefined = Typebox.Text != "";
            byte type        = 0;

            if (typeDefined)
            {
                type = byte.Parse(Typebox.Text);
            }

            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null)
            {
                return;
            }
            session.FilterOut = (packet) =>
            {
                bool ret = false;
                if (headerDefined && packet.Header != header)
                {
                    ret = true;
                }
                if (typeDefined && packet.Type != type)
                {
                    ret = true;
                }
                return(ret);
            };
            session.ListView.Focus();
            session.RefreshPackets();
        }
        public void RefreshOpcodes(bool pReselect)
        {
            SessionForm         session  = DockPanel.ActiveDocument as SessionForm;
            Pair <bool, ushort> selected = pReselect && session != null && mOpcodeCombo.SelectedIndex >= 0 ? session.Opcodes[mOpcodeCombo.SelectedIndex] : null;

            mOpcodeCombo.Items.Clear();
            if (session == null)
            {
                return;
            }
            session.UpdateOpcodeList();
            foreach (Pair <bool, ushort> kv in session.Opcodes)
            {
                Definition definition = Config.Instance.GetDefinition(session.Build, session.Locale, kv.First, kv.Second);
                int        addedIndex = mOpcodeCombo.Items.Add(string.Format("{0} 0x{1:X4} {2}", (kv.First ? "Outbound  " : "Inbound   "), kv.Second, definition == null || string.IsNullOrEmpty(definition.Name) ? "" : definition.Name));

                if (selected != null && selected.First == kv.First && selected.Second == kv.Second)
                {
                    mOpcodeCombo.SelectedIndex = addedIndex;
                }
            }
        }
Esempio n. 21
0
        public void RefreshOpcodes(bool pReselect)
        {
            SessionForm session  = DockPanel.ActiveDocument as SessionForm;
            Opcode      selected = pReselect && session != null && mOpcodeCombo.SelectedIndex >= 0 && session.Opcodes.Count > mOpcodeCombo.SelectedIndex ? session.Opcodes[mOpcodeCombo.SelectedIndex] : null;

            mOpcodeCombo.Items.Clear();
            if (session == null)
            {
                return;
            }
            session.UpdateOpcodeList();
            foreach (Opcode op in session.Opcodes)
            {
                Definition definition = Config.Instance.GetDefinition(session.Build, session.Locale, op.Outbound, op.Header);
                int        addedIndex = mOpcodeCombo.Items.Add(string.Format("{0} 0x{1:X4} {2}", (op.Outbound ? "Outbound  " : "Inbound   "), op.Header, definition == null || string.IsNullOrEmpty(definition.Name) ? "" : definition.Name));

                if (selected != null && selected.Outbound == op.Outbound && selected.Header == op.Header)
                {
                    mOpcodeCombo.SelectedIndex = addedIndex;
                }
            }
        }
Esempio n. 22
0
        private void MainForm_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (var file in files)
            {
                if (!System.IO.File.Exists(file))
                {
                    continue;
                }

                switch (System.IO.Path.GetExtension(file))
                {
                case ".msb":
                {
                    SessionForm session = NewSession();
                    session.OpenReadOnly(file);
                    session.Show(mDockPanel, DockState.Document);
                    mSearchForm.RefreshOpcodes(false);
                    break;
                }

                case ".pcap":
                {
                    device = new CaptureFileReaderDevice(file);
                    device.Open();
                    ParseImportedFile();
                    break;
                }

                case ".txt":
                {
                    ReadMSnifferFile(file);
                    break;
                }
                }
            }
        }
Esempio n. 23
0
 private SessionForm NewSession()
 {
     SessionForm session = new SessionForm();
     return session;
 }
Esempio n. 24
0
 public void CloseSession(SessionForm form)
 {
     mDockPanel.Contents.Remove(form);
 }
Esempio n. 25
0
        private void ProcessPacketQueue()
        {
            while (!Terminate)
            {
                bool bSleep = true;

                lock (QueueLock)
                {
                    if (PacketQueue.Count != 0)
                    {
                        bSleep = false;
                    }
                }

                if (bSleep)
                {
                    Thread.Sleep(250);
                }
                else
                {
                    List <RawCapture> CurQueue;
                    lock (QueueLock)
                    {
                        CurQueue    = PacketQueue;
                        PacketQueue = new List <RawCapture>();
                    }

                    foreach (var pPacket in CurQueue)
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            var packet          = PacketDotNet.Packet.ParsePacket(pPacket.LinkLayerType, pPacket.Data);
                            TcpPacket tcpPacket = (TcpPacket)packet.Extract(typeof(TcpPacket));
                            SessionForm session = null;
                            if (tcpPacket != null)
                            {
                                try
                                {
                                    if ((tcpPacket.SourcePort < Config.Instance.LowPort || tcpPacket.SourcePort > Config.Instance.HighPort) &&
                                        (tcpPacket.DestinationPort < Config.Instance.LowPort || tcpPacket.DestinationPort > Config.Instance.HighPort))
                                    {
                                        return;
                                    }

                                    if (tcpPacket.Syn && !tcpPacket.Ack && tcpPacket.DestinationPort >= Config.Instance.LowPort && tcpPacket.DestinationPort <= Config.Instance.HighPort)
                                    {
                                        session = NewSession();
                                        var res = session.BufferTCPPacket(tcpPacket, pPacket.Timeval.Date);
                                        if (res == SessionForm.Results.Continue)
                                        {
                                            int hash      = tcpPacket.SourcePort << 16 | tcpPacket.DestinationPort;
                                            waiting[hash] = session;
                                        }
                                    }
                                    else
                                    {
                                        int hash = tcpPacket.DestinationPort << 16 | tcpPacket.SourcePort;
                                        session  = Array.Find(MdiChildren, f => (f as SessionForm).MatchTCPPacket(tcpPacket)) as SessionForm;
                                        if (session != null)
                                        {
                                            var res = session.BufferTCPPacket(tcpPacket, pPacket.Timeval.Date);

                                            if (res == SessionForm.Results.CloseMe)
                                            {
                                                waiting.Remove(hash);
                                                session.Close();
                                            }
                                            return;
                                        }

                                        if (waiting.TryGetValue(hash, out session))
                                        {
                                            var res = session.BufferTCPPacket(tcpPacket, pPacket.Timeval.Date);

                                            switch (res)
                                            {
                                            case SessionForm.Results.Show:
                                                session.Show(mDockPanel, DockState.Document);
                                                break;

                                            case SessionForm.Results.Continue:
                                                return;
                                            }
                                            waiting.Remove(hash);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                            }
                        });
                    }
                }
            }
        }
Esempio n. 26
0
        private SessionForm NewSession()
        {
            SessionForm session = new SessionForm();

            return(session);
        }
Esempio n. 27
0
        private void mTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                RawCapture packet = null;
                mTimer.Enabled = false;

                DateTime now = DateTime.Now;
                foreach (SessionForm ses in MdiChildren)
                {
                    if (ses.CloseMe(now))
                    {
                        closes.Add(ses);
                    }
                }
                closes.ForEach((a) => { a.Close(); });
                closes.Clear();

                while ((packet = mDevice.GetNextPacket()) != null)
                {
                    if (!started)
                    {
                        continue;
                    }

                    TcpPacket   tcpPacket = (TcpPacket)PacketDotNet.Packet.ParsePacket(packet.LinkLayerType, packet.Data).Extract(typeof(TcpPacket));
                    SessionForm session   = null;
                    try
                    {
                        if (tcpPacket.Syn && !tcpPacket.Ack && tcpPacket.DestinationPort >= Config.Instance.LowPort && tcpPacket.DestinationPort <= Config.Instance.HighPort)
                        {
                            session = NewSession();
                            var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                            if (res == SessionForm.Results.Continue)
                            {
                                int hash = tcpPacket.SourcePort << 16 | tcpPacket.DestinationPort;
                                waiting[hash] = session;
                            }
                        }
                        else
                        {
                            int hash = tcpPacket.DestinationPort << 16 | tcpPacket.SourcePort;
                            session = Array.Find(MdiChildren, f => (f as SessionForm).MatchTCPPacket(tcpPacket)) as SessionForm;
                            if (session != null)
                            {
                                var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);

                                if (res == SessionForm.Results.CloseMe)
                                {
                                    waiting.Remove(hash);
                                    session.Close();
                                }
                                continue;
                            }

                            if (waiting.TryGetValue(hash, out session))
                            {
                                var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);

                                switch (res)
                                {
                                case SessionForm.Results.Show:
                                    session.Show(mDockPanel, DockState.Document);
                                    break;

                                case SessionForm.Results.Continue:
                                    continue;
                                }
                                waiting.Remove(hash);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        session.Close();
                        session = null;
                    }
                }
                mTimer.Enabled = true;
            }
            catch (Exception)
            {
                if (!mDevice.Opened)
                {
                    mDevice.Open(DeviceMode.Promiscuous, 1);
                }
            }
        }
Esempio n. 28
0
        private void mTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                RawCapture packet = null;
                mTimer.Enabled = false;

                DateTime now = DateTime.Now;
                foreach (SessionForm ses in MdiChildren)
                {
                    if (ses.CloseMe(now))
                    {
                        closes.Add(ses);
                    }
                }
                closes.ForEach((a) => { a.Close(); });
                closes.Clear();

                while ((packet = mDevice.GetNextPacket()) != null)
                {
                    if (!started)
                    {
                        continue;
                    }
                    TcpPacket   tcpPacket = TcpPacket.GetEncapsulated(Packet.ParsePacket(packet.LinkLayerType, packet.Data));
                    SessionForm session   = null;
                    try
                    {
                        if (tcpPacket.Syn && !tcpPacket.Ack && tcpPacket.DestinationPort >= Config.Instance.LowPort && tcpPacket.DestinationPort <= Config.Instance.HighPort && tcpPacket.DestinationPort != 9301)
                        {
                            session = NewSession();
                            var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                            if (res == SessionForm.Results.Continue)
                            {
                                session.Show(mDockPanel, DockState.Document);
                            }
                        }
                        else
                        {
                            session = Array.Find(MdiChildren, f => (f as SessionForm).MatchTCPPacket(tcpPacket)) as SessionForm;
                            if (session != null)
                            {
                                var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);

                                if (res == SessionForm.Results.CloseMe)
                                {
                                    session.Close();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        session.Close();
                        session = null;
                    }
                }
                mTimer.Enabled = true;
            }
            catch (Exception)
            {
                if (!mDevice.Opened)
                {
                    mDevice.Open(DeviceMode.Promiscuous, 1);
                }
            }
        }
Esempio n. 29
0
        void ParseImportedFile()
        {
            RawCapture  packet  = null;
            SessionForm session = null;

            this.Invoke((MethodInvoker) delegate
            {
                while ((packet = device.GetNextPacket()) != null)
                {
                    if (!started)
                    {
                        continue;
                    }

                    TcpPacket tcpPacket = (TcpPacket)PacketDotNet.Packet.ParsePacket(packet.LinkLayerType, packet.Data).Extract(typeof(TcpPacket));
                    if (tcpPacket == null)
                    {
                        continue;
                    }

                    if ((tcpPacket.SourcePort < Config.Instance.LowPort || tcpPacket.SourcePort > Config.Instance.HighPort) &&
                        (tcpPacket.DestinationPort < Config.Instance.LowPort || tcpPacket.DestinationPort > Config.Instance.HighPort))
                    {
                        continue;
                    }
                    try
                    {
                        if (tcpPacket.Syn && !tcpPacket.Ack)
                        {
                            if (session != null)
                            {
                                session.Show(mDockPanel, DockState.Document);
                            }

                            session = NewSession();
                            var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                            if (res == SessionForm.Results.Continue)
                            {
                                //    mDockPanel.Contents.Add(session);
                                //session.Show(mDockPanel, DockState.Document);
                            }
                        }
                        else if (session != null && session.MatchTCPPacket(tcpPacket))
                        {
                            var res = session.BufferTCPPacket(tcpPacket, packet.Timeval.Date);
                            if (res == SessionForm.Results.CloseMe)
                            {
                                session.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception while parsing logfile: {0}", ex);
                        session.Close();
                        session = null;
                    }
                }


                if (session != null)
                {
                    session.Show(mDockPanel, DockState.Document);
                }

                if (session != null)
                {
                    mSearchForm.RefreshOpcodes(false);
                }
            });
        }
Esempio n. 30
0
 private SessionForm NewSession()
 {
     SessionForm session = new SessionForm();
     session.Show(mDockPanel, DockState.Document);
     return session;
 }
Esempio n. 31
0
 public void CloseSession(SessionForm form)
 {
     mDockPanel.Contents.Remove(form);
 }