Skip to content

Commit

Permalink
UINT Highlighting feature plus a couple fixes. (tfarley#22)
Browse files Browse the repository at this point in the history
* * Added a simple uint highlight feature.
* Added a "Highlight Object ID" function to the objects list context menu.
* Fixed a case where an exception could be thrown.
* Small refactor of the Find Object ID option.
* Prevent context menus from opening when there are no items present.
* When jumping to a message from the objects listview context menu the currently viewed packet number is now updated properly.

* * Changed some text for the UINT highlight feature.
* Added changelog.
  • Loading branch information
Slushnas authored and LtRipley36706 committed Jan 3, 2018
1 parent b81cb1c commit aef7bf7
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 8 deletions.
14 changes: 12 additions & 2 deletions aclogview/Form1.Designer.cs

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

97 changes: 91 additions & 6 deletions aclogview/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public partial class Form1 : Form

private string pcapFilePath;
private int currentOpcode;
private uint currentUint;
private string currentHighlightMode;
private string currentCSText;
private string currentCIText;
// Highlight mode options
private string opcodeMode = "Opcode";
private string textModeCS = "Text (Case-Sensitive)";
private string textModeCI = "Text (Case-Insensitive)";
private string uintMode = "UINT32";

static private string sortTypeUInt = "UInt";
static private string sortTypeString = "String";
Expand Down Expand Up @@ -88,6 +90,7 @@ private void Form1_Load(object sender, EventArgs e)
HighlightMode_comboBox.Items.Add(opcodeMode);
HighlightMode_comboBox.Items.Add(textModeCS);
HighlightMode_comboBox.Items.Add(textModeCI);
HighlightMode_comboBox.Items.Add(uintMode);

var options = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, options))
Expand Down Expand Up @@ -189,7 +192,7 @@ private void loadPcap(string fileName, bool asMessages, bool dontList = false) {
// Opcode highlighting is applied in listView_Packets_RetrieveVirtualItem
}
}
else if (currentHighlightMode == textModeCS)
else if (currentHighlightMode == textModeCS && textBox_Search.Text.Length != 0)
{
var result = SearchForText(record, currentCSText, caseSensitive: true);
if (result > 0)
Expand All @@ -198,7 +201,7 @@ private void loadPcap(string fileName, bool asMessages, bool dontList = false) {
hits++;
}
}
else if (currentHighlightMode == textModeCI)
else if (currentHighlightMode == textModeCI && textBox_Search.Text.Length != 0)
{
var result = SearchForText(record, currentCIText, caseSensitive: false);
if (result > 0)
Expand All @@ -207,6 +210,16 @@ private void loadPcap(string fileName, bool asMessages, bool dontList = false) {
hits++;
}
}
else if (currentHighlightMode == uintMode && textBox_Search.Text.Length != 0)
{
byte[] bytes = BitConverter.GetBytes(currentUint);
int result = SearchBytePattern(bytes, record.data);
if (result > 0)
{
newItem.BackColor = Color.LightBlue;
hits++;
}
}
packetListItems.Add(newItem);
}
if (hits > 0 && (currentHighlightMode == textModeCS || currentHighlightMode == textModeCI) )
Expand All @@ -224,6 +237,10 @@ private void loadPcap(string fileName, bool asMessages, bool dontList = false) {
foreach (var opcode in opCodesToHighlight)
Text += " 0x" + opcode.ToString("X4") + " (" + opcode + ")";
}
else if (hits > 0 && currentHighlightMode == uintMode)
{
Text = Text = "AC Log View - " + Path.GetFileName(pcapFilePath) + $" Highlighted {hits} message(s) containing UINT32: {textBox_Search.Text}";
}
}

if (!dontList && records.Count > 0)
Expand Down Expand Up @@ -678,6 +695,7 @@ private void mnuItem_EditPreviousHighlightedRow_Click(object sender, EventArgs e
else
{
listView_Packets.EnsureVisible(listView_Packets.SelectedIndices[0]);
listView_Packets.Items[listView_Packets.SelectedIndices[0]].Focused = true;
}

for (int i = listView_Packets.SelectedIndices[0] - 1; i >= 0; i--)
Expand Down Expand Up @@ -712,6 +730,7 @@ private void mnuItem_EditNextHighlightedRow_Click(object sender, EventArgs e)
else
{
listView_Packets.EnsureVisible(listView_Packets.SelectedIndices[0]);
listView_Packets.Items[listView_Packets.SelectedIndices[0]].Focused = true;
}

for (int i = listView_Packets.SelectedIndices[0] + 1; i < listView_Packets.Items.Count; i++)
Expand Down Expand Up @@ -974,12 +993,12 @@ private void parsedContextMenu_ItemClicked(object sender, ToolStripItemClickedEv
break;
}
case "FindID":
foreach (ListViewItem lvi in createdListItems)
for (int i = 0; i < createdListItems.Count; i++)
{
if (treeView_ParsedData.SelectedNode.Text.Contains(lvi.SubItems[1].Text))
if (treeView_ParsedData.SelectedNode.Text.Contains(createdListItems[i].SubItems[1].Text))
{
listView_CreatedObjects.TopItem = lvi;
listView_CreatedObjects.Items[createdListItems[lvi.Index].Index].Selected = true;
listView_CreatedObjects.Items[i].Selected = true;
listView_CreatedObjects.TopItem = createdListItems[i];
System.Media.SystemSounds.Asterisk.Play();
break;
}
Expand Down Expand Up @@ -1167,6 +1186,44 @@ private void btnHighlight_Click(object sender, EventArgs e)
ClearHighlighting();
loadPcap(pcapFilePath, loadedAsMessages);
}
else if ((string)HighlightMode_comboBox.SelectedItem == uintMode)
{
// decimal
if (uint.TryParse(searchString, out currentUint))
{
// do nothing currently, currentObjectID should be set
}
// hex
else if (HexTest(searchString))
{
currentUint = UInt32.Parse(searchString, System.Globalization.NumberStyles.HexNumber);
}
// c-style hex check
else if (CHexTest(searchString))
{
currentUint = UInt32.Parse(searchString.Remove(0, 2), System.Globalization.NumberStyles.HexNumber);
}
// reset
else
{
textBox_Search.Clear();
}

if (currentUint != 0)
{
textBox_Search.Text = "0x";
for (int i = currentUint.ToString("X").Length; i < 8; i++)
{
textBox_Search.Text += "0";
}
textBox_Search.Text += currentUint.ToString("X");
loadPcap(pcapFilePath, loadedAsMessages);
}
else
{
toolStripStatus.Text = "Invalid hex code.";
}
}
}

public bool CHexTest(string test)
Expand Down Expand Up @@ -1311,6 +1368,15 @@ private void HighlightMode_comboBox_SelectedIndexChanged(object sender, EventArg
ClearHighlighting();
textBox_Search.MaxLength = 256;
}
else if ((string)HighlightMode_comboBox.SelectedItem == uintMode)
{
currentHighlightMode = uintMode;
Text = "AC Log View - " + Path.GetFileName(pcapFilePath);
textBox_Search.Clear();
opCodesToHighlight.Clear();
ClearHighlighting();
textBox_Search.MaxLength = 10;
}
}

private void ClearHighlighting()
Expand Down Expand Up @@ -1407,6 +1473,19 @@ private void objectsContextMenu_ItemClicked(object sender, ToolStripItemClickedE
var selected = Int32.Parse(createdListItems[listView_CreatedObjects.SelectedIndices[0]].Text);
listView_Packets.TopItem = listView_Packets.Items[selected];
listView_Packets.Items[selected].Selected = true;
lblTracker.Text = "Viewing #" + listView_Packets.Items[selected].Index;
}
else if (e.ClickedItem == highlightObjectIDMenuItem)
{
if (currentHighlightMode != uintMode)
{
// Set highlight mode so we don't need to wait on the event handler
// HighlightMode_comboBox_SelectedIndexChanged to finish
currentHighlightMode = uintMode;
HighlightMode_comboBox.SelectedItem = uintMode;
}
textBox_Search.Text = createdListItems[listView_CreatedObjects.SelectedIndices[0]].SubItems[1].Text;
btnHighlight.PerformClick();
}
}

Expand All @@ -1418,6 +1497,7 @@ private void treeView_ParsedData_NodeMouseClick(object sender, TreeNodeMouseClic

private void parsedContextMenu_Opening(object sender, CancelEventArgs e)
{
e.Cancel = (treeView_ParsedData.Nodes.Count == 0);
if (treeView_ParsedData.SelectedNode != null && createdListItems.Count > 0)
{
parsedContextMenu.Items[3].Visible = true;
Expand All @@ -1427,6 +1507,11 @@ private void parsedContextMenu_Opening(object sender, CancelEventArgs e)
parsedContextMenu.Items[3].Visible = false;
}
}

private void objectsContextMenu_Opening(object sender, CancelEventArgs e)
{
e.Cancel = (createdListItems.Count == 0);
}
}
}

9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 2018-01-02
[Slushnas]
* Added a simple highlight UINT32 feature for currently opened files. This can be used to search for Object IDs, DIDs, etc.
* Added a _Highlight Object ID_ function to the created objects list context menu.
* Fixed a case where an exception could be thrown.
* Small refactor of the _Find ID In Object List_ option.
* Prevent context menus from opening when there are no items present.
* When jumping to a message from the objects listview context menu the currently viewed packet number is now updated properly.

### 2017-12-16
[Slushnas]
* Migrated to .NET framework 4.6.1 to keep in line with the ACEmulator/ACE project.
Expand Down

0 comments on commit aef7bf7

Please sign in to comment.