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); } }
private SessionForm NewSession() { SessionForm session = new SessionForm(); session.Show(mDockPanel, DockState.Document); return(session); }
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); } }
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); } }
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); }); } }
public MainForm(string[] pArgs) { InitializeComponent(); Text = "MapleShark " + Program.AssemblyVersion; foreach (string arg in pArgs) { SessionForm session = NewSession(); session.OpenReadOnly(arg); session.Show(mDockPanel, DockState.Document); } }
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); } }
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; } } } }
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); } } }
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); } }); }
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); } } }); } } } }
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); } } }
private SessionForm NewSession() { SessionForm session = new SessionForm(); session.Show(mDockPanel, DockState.Document); return session; }