Skip to content

Commit

Permalink
+ added support for loading packets from a file to inspect them
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Maiquez Murcia <[email protected]>
  • Loading branch information
Almamu committed Feb 12, 2021
1 parent 32b9c87 commit cc9a077
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 35 deletions.
164 changes: 136 additions & 28 deletions Editor/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 40 additions & 5 deletions Editor/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Common.Network;
using PythonTypes;
using PythonTypes.Marshal;
using PythonTypes.Types.Network;
using PythonTypes.Types.Primitives;

Expand Down Expand Up @@ -157,6 +160,22 @@ private void LoadPacketDetails(int index)
this.packetTreeView.EndUpdate();
}

private void LoadFileDetails(PyDataType packet)
{
this.fileTextBox.Text = PrettyPrinter.FromDataType(packet);

this.fileTreeView.BeginUpdate();
this.fileTreeView.Nodes.Clear();

TreeViewPrettyPrinter.Process(packet, this.fileTreeView.Nodes.Add("RawData"));

foreach (TreeNode node in this.fileTreeView.Nodes)
node.ExpandAll();

this.fileTreeView.Nodes[0].EnsureVisible();
this.fileTreeView.EndUpdate();
}

private void ClearPacketDetails()
{
this.packetTextBox.Text = "";
Expand Down Expand Up @@ -304,13 +323,12 @@ private void newCaptureToolStripMenuItem_Click(object sender, EventArgs e)
this.ClearPacketDetails();

this.mIgnoreIncomingPackets = false;

}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
PacketListFile.SavePackets(saveFileDialog1.FileName, this.mPackets, this.mClients);
if (saveCaptureDialog.ShowDialog() == DialogResult.OK)
PacketListFile.SavePackets(saveCaptureDialog.FileName, this.mPackets, this.mClients);
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -348,7 +366,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
if (this.openCaptureDialog.ShowDialog() == DialogResult.OK)
{
foreach (Client client in this.mClients)
{
Expand All @@ -367,7 +385,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)

this.mIgnoreIncomingPackets = true;

PacketListFile.LoadPackets(this.openFileDialog1.FileName, out this.mPackets, out this.mClients);
PacketListFile.LoadPackets(this.openCaptureDialog.FileName, out this.mPackets, out this.mClients);

listenStatusLabel.Text = "Listener stopped on capture load. Start a new capture to listen again";

Expand Down Expand Up @@ -396,5 +414,22 @@ private void toolStripButton1_Click(object sender, EventArgs e)
this.mPacketListBinding.Clear();
}
}

private void openMarshalFileButton_Click(object sender, EventArgs e)
{
try
{
if (this.openMarshalFile.ShowDialog() == DialogResult.OK)
{
byte[] fileContents = File.ReadAllBytes(this.openMarshalFile.FileName);
LoadFileDetails(Unmarshal.ReadFromByteArray(fileContents));
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
}
}
7 changes: 5 additions & 2 deletions Editor/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,16 @@
<metadata name="packetCall.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="saveCaptureDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>116, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="openCaptureDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>248, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>381, 17</value>
</metadata>
<metadata name="openMarshalFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>492, 17</value>
</metadata>
</root>

0 comments on commit cc9a077

Please sign in to comment.