From d0dda9dabb82094163fdd806238e6d5c49b1706b Mon Sep 17 00:00:00 2001 From: Erwin Oegema Date: Sun, 23 Aug 2015 16:09:08 +0200 Subject: [PATCH] Make public static value 'StartupArguments' a private value in MainForm Fix outbound and inbound packets being added while ignored. Fixes #12 Fix exception caused by invalid encoding name, switch to static numbers instead Rename 'ascii' to 'encoding' Push to version 2.0.2.6 Change 'Import' to 'Import .pcap file' --- MainForm.Designer.cs | 39 +++++++++++++-------------- MainForm.cs | 8 +++--- MapleKeys.cs | 10 +++---- Program.cs | 5 +--- Properties/AssemblyInfo.cs | 6 ++--- SessionForm.cs | 5 +++- StructureSegment.cs | 55 +++++++++++++++++++++----------------- 7 files changed, 68 insertions(+), 60 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index db7450e..2d22d77 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -97,61 +97,60 @@ private void InitializeComponent() this.mFileSeparatorMenu, this.mFileQuit}); this.mFileMenu.Name = "mFileMenu"; - this.mFileMenu.Size = new System.Drawing.Size(38, 20); + this.mFileMenu.Size = new System.Drawing.Size(37, 20); this.mFileMenu.Text = "&File"; // // mFileOpenMenu // this.mFileOpenMenu.Name = "mFileOpenMenu"; this.mFileOpenMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.mFileOpenMenu.Size = new System.Drawing.Size(229, 22); + this.mFileOpenMenu.Size = new System.Drawing.Size(218, 22); this.mFileOpenMenu.Text = "&Open"; this.mFileOpenMenu.Click += new System.EventHandler(this.mFileOpenMenu_Click); // // mFileImportMenu // this.mFileImportMenu.Name = "mFileImportMenu"; - this.mFileImportMenu.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.I))); - this.mFileImportMenu.Size = new System.Drawing.Size(229, 22); - this.mFileImportMenu.Text = "&Import"; + this.mFileImportMenu.Size = new System.Drawing.Size(218, 22); + this.mFileImportMenu.Text = "Import .pcap file"; this.mFileImportMenu.Click += new System.EventHandler(this.mFileImportMenu_Click); // // importJavapropertiesFileToolStripMenuItem // this.importJavapropertiesFileToolStripMenuItem.Name = "importJavapropertiesFileToolStripMenuItem"; - this.importJavapropertiesFileToolStripMenuItem.Size = new System.Drawing.Size(229, 22); + this.importJavapropertiesFileToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.importJavapropertiesFileToolStripMenuItem.Text = "Import Java *.properties file"; this.importJavapropertiesFileToolStripMenuItem.Click += new System.EventHandler(this.importJavapropertiesFileToolStripMenuItem_Click); // // importMSnifferToolStripMenuItem // this.importMSnifferToolStripMenuItem.Name = "importMSnifferToolStripMenuItem"; - this.importMSnifferToolStripMenuItem.Size = new System.Drawing.Size(229, 22); + this.importMSnifferToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.importMSnifferToolStripMenuItem.Text = "Import MSniffer logfile"; this.importMSnifferToolStripMenuItem.Click += new System.EventHandler(this.importMSnifferToolStripMenuItem_Click); // // toolStripSeparator4 // this.toolStripSeparator4.Name = "toolStripSeparator4"; - this.toolStripSeparator4.Size = new System.Drawing.Size(226, 6); + this.toolStripSeparator4.Size = new System.Drawing.Size(215, 6); // // setupToolStripMenuItem // this.setupToolStripMenuItem.Name = "setupToolStripMenuItem"; - this.setupToolStripMenuItem.Size = new System.Drawing.Size(229, 22); + this.setupToolStripMenuItem.Size = new System.Drawing.Size(218, 22); this.setupToolStripMenuItem.Text = "MapleShark Setup"; this.setupToolStripMenuItem.Click += new System.EventHandler(this.setupToolStripMenuItem_Click); // // mFileSeparatorMenu // this.mFileSeparatorMenu.Name = "mFileSeparatorMenu"; - this.mFileSeparatorMenu.Size = new System.Drawing.Size(226, 6); + this.mFileSeparatorMenu.Size = new System.Drawing.Size(215, 6); // // mFileQuit // this.mFileQuit.Name = "mFileQuit"; this.mFileQuit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4))); - this.mFileQuit.Size = new System.Drawing.Size(229, 22); + this.mFileQuit.Size = new System.Drawing.Size(218, 22); this.mFileQuit.Text = "&Quit"; this.mFileQuit.Click += new System.EventHandler(this.mFileQuit_Click); // @@ -163,7 +162,7 @@ private void InitializeComponent() this.mViewStructureMenu, this.mViewPropertiesMenu}); this.mViewMenu.Name = "mViewMenu"; - this.mViewMenu.Size = new System.Drawing.Size(46, 20); + this.mViewMenu.Size = new System.Drawing.Size(44, 20); this.mViewMenu.Text = "&View"; this.mViewMenu.DropDownOpening += new System.EventHandler(this.mViewMenu_DropDownOpening); // @@ -174,7 +173,7 @@ private void InitializeComponent() this.mViewSearchMenu.CheckState = System.Windows.Forms.CheckState.Checked; this.mViewSearchMenu.Name = "mViewSearchMenu"; this.mViewSearchMenu.ShortcutKeys = System.Windows.Forms.Keys.F9; - this.mViewSearchMenu.Size = new System.Drawing.Size(158, 22); + this.mViewSearchMenu.Size = new System.Drawing.Size(152, 22); this.mViewSearchMenu.Text = "Sea&rch"; this.mViewSearchMenu.CheckedChanged += new System.EventHandler(this.mViewSearchMenu_CheckedChanged); // @@ -185,7 +184,7 @@ private void InitializeComponent() this.mViewDataMenu.CheckState = System.Windows.Forms.CheckState.Checked; this.mViewDataMenu.Name = "mViewDataMenu"; this.mViewDataMenu.ShortcutKeys = System.Windows.Forms.Keys.F10; - this.mViewDataMenu.Size = new System.Drawing.Size(158, 22); + this.mViewDataMenu.Size = new System.Drawing.Size(152, 22); this.mViewDataMenu.Text = "&Data"; this.mViewDataMenu.CheckedChanged += new System.EventHandler(this.mViewDataMenu_CheckedChanged); // @@ -196,7 +195,7 @@ private void InitializeComponent() this.mViewStructureMenu.CheckState = System.Windows.Forms.CheckState.Checked; this.mViewStructureMenu.Name = "mViewStructureMenu"; this.mViewStructureMenu.ShortcutKeys = System.Windows.Forms.Keys.F11; - this.mViewStructureMenu.Size = new System.Drawing.Size(158, 22); + this.mViewStructureMenu.Size = new System.Drawing.Size(152, 22); this.mViewStructureMenu.Text = "&Structure"; this.mViewStructureMenu.CheckedChanged += new System.EventHandler(this.mViewStructureMenu_CheckedChanged); // @@ -207,7 +206,7 @@ private void InitializeComponent() this.mViewPropertiesMenu.CheckState = System.Windows.Forms.CheckState.Checked; this.mViewPropertiesMenu.Name = "mViewPropertiesMenu"; this.mViewPropertiesMenu.ShortcutKeys = System.Windows.Forms.Keys.F12; - this.mViewPropertiesMenu.Size = new System.Drawing.Size(158, 22); + this.mViewPropertiesMenu.Size = new System.Drawing.Size(152, 22); this.mViewPropertiesMenu.Text = "&Properties"; this.mViewPropertiesMenu.CheckedChanged += new System.EventHandler(this.mViewPropertiesMenu_CheckedChanged); // @@ -276,7 +275,7 @@ private void InitializeComponent() this.mStopStartButton.Image = global::MapleShark.Properties.Resources.Button_Blank_Red_icon; this.mStopStartButton.ImageTransparentColor = System.Drawing.Color.Magenta; this.mStopStartButton.Name = "mStopStartButton"; - this.mStopStartButton.Size = new System.Drawing.Size(98, 22); + this.mStopStartButton.Size = new System.Drawing.Size(94, 22); this.mStopStartButton.Text = "Stop sniffing"; this.mStopStartButton.Click += new System.EventHandler(this.toolStripButton1_Click); // @@ -306,7 +305,7 @@ private void InitializeComponent() this.mDockPanel.DockTopPortion = 75D; this.mDockPanel.Location = new System.Drawing.Point(0, 49); this.mDockPanel.Name = "mDockPanel"; - this.mDockPanel.Size = new System.Drawing.Size(944, 562); + this.mDockPanel.Size = new System.Drawing.Size(944, 613); dockPanelGradient1.EndColor = System.Drawing.SystemColors.ControlLight; dockPanelGradient1.StartColor = System.Drawing.SystemColors.ControlLight; autoHideStripSkin1.DockStripGradient = dockPanelGradient1; @@ -357,9 +356,9 @@ private void InitializeComponent() // MainForm // this.AllowDrop = true; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(944, 611); + this.ClientSize = new System.Drawing.Size(944, 662); this.Controls.Add(this.mDockPanel); this.Controls.Add(this.toolStrip); this.Controls.Add(this.mMenu); diff --git a/MainForm.cs b/MainForm.cs index fe34a9f..6040a40 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -27,12 +27,14 @@ public partial class MainForm : Form private StructureForm mStructureForm = new StructureForm(); private PropertyForm mPropertyForm = new PropertyForm(); - public static string[] StartupArguments = null; + private string[] _startupArguments = null; - public MainForm() + public MainForm(string[] startupArguments) { InitializeComponent(); Text = "MapleShark " + Program.AssemblyVersion; + + _startupArguments = startupArguments; } public SearchForm SearchForm { get { return mSearchForm; } } @@ -142,7 +144,7 @@ private void MainForm_Load(object pSender, EventArgs pArgs) rightPane2.Show(); - foreach (string arg in StartupArguments) + foreach (string arg in _startupArguments) { SessionForm session = NewSession(); session.OpenReadOnly(arg); diff --git a/MapleKeys.cs b/MapleKeys.cs index b27e3a4..0e49bff 100644 --- a/MapleKeys.cs +++ b/MapleKeys.cs @@ -99,11 +99,11 @@ public static byte[] GetKeyForVersion(byte locale, ushort version, byte subversi } // Get first version known - for (; version > 0; version--) + for (ushort v = version; v > 0; v--) { - for (byte subVersion = subversion; subVersion >= 0; subVersion--) + for (byte sv = subversion; sv >= 0; sv--) { - var tuple = new KeyValuePair(version, subVersion); + var tuple = new KeyValuePair(v, sv); if (MapleStoryKeys[locale].ContainsKey(tuple)) { byte[] key = MapleStoryKeys[locale][tuple]; @@ -111,10 +111,10 @@ public static byte[] GetKeyForVersion(byte locale, ushort version, byte subversi for (int i = 0; i < 8; i++) ret[i * 4] = key[i]; - Console.WriteLine("Using key for version {0}.{1}", version, subVersion); + Console.WriteLine("Using key for version {0}.{1}", v, sv); return ret; } - if (subVersion == 0) break; + if (sv == 0) break; } } Console.WriteLine("Version {0}.{1} for locale {2} not found!", version, subversion, locale); diff --git a/Program.cs b/Program.cs index b6dcddc..766696f 100644 --- a/Program.cs +++ b/Program.cs @@ -40,14 +40,11 @@ private static void Main(string[] pArgs) } }; - - MainForm.StartupArguments = pArgs; - Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (new frmSplash().ShowDialog() == DialogResult.OK) - Application.Run(new MainForm()); + Application.Run(new MainForm(pArgs)); } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 6529ce0..c396985 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MapleShark")] -[assembly: AssemblyCopyright("Copyright © Astaelan, Diamondo25 '11 - '14")] +[assembly: AssemblyCopyright("Copyright © Astaelan, Diamondo25 '11 - '15")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.2.5")] -[assembly: AssemblyFileVersion("2.0.2.5")] +[assembly: AssemblyVersion("2.0.2.6")] +[assembly: AssemblyFileVersion("2.0.2.6")] diff --git a/SessionForm.cs b/SessionForm.cs index 8c3c575..3735888 100644 --- a/SessionForm.cs +++ b/SessionForm.cs @@ -30,7 +30,6 @@ public enum Results private string mFilename = null; private bool mTerminated = false; - //private bool mSavedAfterTermination = false; private ushort mLocalPort = 0; private ushort mRemotePort = 0; private ushort mProxyPort = 0; @@ -350,6 +349,9 @@ private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictiona refreshOpcodes = true; } if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue; + if (packet.Outbound && !mViewOutboundMenu.Checked) continue; + if (!packet.Outbound && !mViewInboundMenu.Checked) continue; + mPacketList.Items.Add(packet); if (mPacketList.SelectedItems.Count == 0) packet.EnsureVisible(); } @@ -496,6 +498,7 @@ public void RefreshPackets() MaplePacket packet = mPackets[index]; if (packet.Outbound && !mViewOutboundMenu.Checked) continue; if (!packet.Outbound && !mViewInboundMenu.Checked) continue; + Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode); packet.Name = definition == null ? "" : definition.Name; if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode)) mOpcodes.Add(new Pair(packet.Outbound, packet.Opcode)); diff --git a/StructureSegment.cs b/StructureSegment.cs index b9cd9e2..0f1fdb7 100644 --- a/StructureSegment.cs +++ b/StructureSegment.cs @@ -7,32 +7,39 @@ namespace MapleShark public sealed class StructureSegment { private byte[] mBuffer; - private Encoding ascii = Encoding.UTF8; + private Encoding encoding = Encoding.UTF8; public StructureSegment(byte[] pBuffer, int pStart, int pLength, byte locale) { mBuffer = new byte[pLength]; - switch (locale) + try { - case MapleLocale.KOREA: - case MapleLocale.KOREA_TEST: - ascii = Encoding.GetEncoding("EUC_KR"); - break; - case MapleLocale.JAPAN: - ascii = Encoding.GetEncoding("Shift_JIS"); - break; - case MapleLocale.CHINA: - ascii = Encoding.GetEncoding("GB18030"); - break; - case MapleLocale.TESPIA: - ascii = Encoding.Default; - break; - case MapleLocale.TAIWAN: - ascii = Encoding.GetEncoding("BIG5-HKSCS"); - break; - default: - ascii = Encoding.UTF8; - break; + switch (locale) + { + case MapleLocale.KOREA: + case MapleLocale.KOREA_TEST: + encoding = Encoding.GetEncoding(51949); // EUC_KR + break; + case MapleLocale.JAPAN: + encoding = Encoding.GetEncoding(50222); // Shift_JIS + break; + case MapleLocale.CHINA: + encoding = Encoding.GetEncoding(54936); // GB18030 + break; + case MapleLocale.TESPIA: + encoding = Encoding.Default; + break; + case MapleLocale.TAIWAN: + encoding = Encoding.GetEncoding("BIG5-HKSCS"); + break; + default: + encoding = Encoding.UTF8; + break; + } + } + catch + { + encoding = Encoding.UTF8; } Buffer.BlockCopy(pBuffer, pStart, mBuffer, 0, pLength); } @@ -117,8 +124,8 @@ public string String { if (mBuffer.Length == 0) return null; if (mBuffer[0] == 0x00) return ""; - for (int index = 0; index < mBuffer.Length; ++index) if (mBuffer[index] == 0x00) return ascii.GetString(mBuffer, 0, index); - return ascii.GetString(mBuffer, 0, mBuffer.Length); + for (int index = 0; index < mBuffer.Length; ++index) if (mBuffer[index] == 0x00) return encoding.GetString(mBuffer, 0, index); + return encoding.GetString(mBuffer, 0, mBuffer.Length); } } @@ -130,7 +137,7 @@ public string StringIgnore Buffer.BlockCopy(mBuffer, 0, sBuffer, 0, mBuffer.Length); if (sBuffer.Length == 0) return null; for (int index = 0; index < sBuffer.Length; ++index) if (sBuffer[index] >= 0x00 && sBuffer[index] < 0x20) sBuffer[index] = 0x2E; - return ascii.GetString(sBuffer, 0, sBuffer.Length); + return encoding.GetString(sBuffer, 0, sBuffer.Length); } }