[Test] public void Seek() { InstanceTreeNode instance = PrepareInstance( "struct A { seek(3); u8 a; }", new byte[] { 2, 0, 17, 37 }); Assert.AreEqual("37", instance.Cells[0].ToString()); }
[Test] public void LoadChildOffset() { StructInstance instance = PrepareInstance( "struct A { u8 a; child B [offset=a]; } struct B { u8 value; } ", new byte[] { 2, 0, 17 }); InstanceTreeNode childInstance = instance.Children[0]; Assert.AreEqual("17", childInstance.Cells[0].ToString()); }
private void _structTreeView_AfterSelect(object sender, TreeViewEventArgs e) { _activeInstance = (InstanceTreeNode)e.Node.Tag; if (_nodeControl != null) { _nodeControl.Parent.Controls.Remove(_nodeControl); _nodeControl.Dispose(); _nodeControl = null; } _structTreeView.BeginUpdate(); try { if (_activeInstance == null) { _structGridView.DataSource = new List <StructCell>(); } else { NodeUI ui = FindNodeUI(_activeInstance); if (ui != null) { _nodeControl = ui.CreateControl(); _nodeControl.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(_nodeControl); _structGridView.Visible = false; } else { _structGridView.Visible = true; _structGridView.DataSource = _activeInstance.Cells; } // while we're in BeginUpdate, pre-evaluate all cell values _activeInstance.Cells.ToList().ForEach(cell => cell.Value.ToString()); } } finally { _structTreeView.EndUpdate(); } var instance = _activeInstance as StructInstance; if (instance == null) { InstanceTree tree = ActiveInstanceTree; if (tree != null) { _hexDump.Stream = FindDataFile(tree).Stream; } _currentStructureHighlighter.SetRange(-1, -1); } else { _hexDump.Stream = instance.Stream; _currentStructureHighlighter.SetRange(instance.Offset, instance.EndOffset); } }
[Test] public void ChildEvaluateContext() { StructInstance instance = PrepareInstance( "struct data { child C1 [group=C, offset=0]; child C2 [group=C2, offset=1]; } struct C1 { i8 v; } struct C2 { [hidden] u8 ci; calc q [value=(root.child(\"C\", ci).v)]; } ", new byte[] { 5, 0 }); InstanceTreeNode group = instance.Children[1]; group.NeedChildren(); Assert.AreEqual("5", group.Children[0].Cells[0].Value); }
[Test] public void LoadDataRestoreOffset() { StructInstance instance = PrepareInstance( "struct data { child C1 [group=C, offset=0]; child C2 [group=C2, offset=2]; } struct C1 { i8 v; } struct C2 { [hidden] u8 ci; calc q [value=(root.child(\"C\", ci).v)]; u8 v2; } ", new byte[] { 5, 17, 0, 42 }); InstanceTreeNode group = instance.Children[1]; group.NeedChildren(); Assert.AreEqual("42", group.Children[0].Cells[1].Value); }
private static string AppendSequenceIndex(InstanceTreeNode node) { string name = node.NodeName; var structInstance = node as StructInstance; if (structInstance != null && structInstance.SequenceIndex >= 0) { name = structInstance.SequenceIndex + ". " + name; } return(name); }
[Test] public void LoadChildCount() { StructInstance instance = PrepareInstance( "struct A { u8 a; child B [offset=a, count=2]; } struct B { u8 value; } ", new byte[] { 2, 0, 17, 37 }); Assert.AreEqual(2, instance.Children.Count); InstanceTreeNode childInstance = instance.Children[1]; Assert.AreEqual("37", childInstance.Cells[0].ToString()); }
[Test] public void ChildGroup() { StructInstance instance = PrepareInstance( "struct A { u8 a; child B [group=X]; } struct B { u8 value; } ", new byte[] { 2, 17 }); InstanceTreeNode groupInstance = instance.Children[0]; Assert.AreEqual("X", groupInstance.NodeName); Assert.AreEqual(1, groupInstance.Children.Count); Assert.AreEqual("17", groupInstance.Children[0].Cells[0].Value); }
private static NodeUI FindNodeUI(InstanceTreeNode instance) { foreach (var cell in instance.Cells) { var ui = NodeUIRegistry.GetNodeUI(cell); if (ui != null) { return(ui); } } return(null); }
[Test] public void LoadChild() { StructInstance instance = PrepareInstance( "struct BITMAPFILEHEADER { x32 biSize; child BITMAPINFOHEADER; } struct BITMAPINFOHEADER { u32 biSize; } ", new byte[] { 0x5, 0, 0, 0, 0x10, 0, 0, 0 }); Assert.IsTrue(instance.HasChildren); Assert.AreEqual(1, instance.Children.Count); InstanceTreeNode childInstance = instance.Children[0]; Assert.IsFalse(childInstance.HasChildren); Assert.AreEqual("16", childInstance.Cells[0].ToString()); }
private void DoLoadChildren(StructInstance instance, InstanceTreeNode parent, Stream stream, long?offset, int count) { StructInstance lastChild = instance.LastChild; string groupName = GetStringAttribute("group"); if (groupName != null) { GroupContainer container = new GroupContainer(parent, groupName); parent.AddChild(container); parent = container; } if (count == 0) { return; } StructDef childDef = GetStructAttribute("struct"); if (childDef == null) { childDef = _structDef; } StructInstance childInstance; bool followChildren = GetBoolAttribute("followchildren"); if (offset.HasValue) { childInstance = new StructInstance(childDef, parent, stream, offset.Value); } else { bool firstFollowChildren = followChildren && lastChild != parent; childInstance = new StructInstance(childDef, parent, stream, lastChild, firstFollowChildren); } parent.AddChild(childInstance); if (count > 1) { childInstance.SequenceIndex = 0; } for (int i = 1; i < count; i++) { var nextInstance = new StructInstance(childDef, parent, stream, childInstance, followChildren); parent.AddChild(nextInstance); nextInstance.SequenceIndex = i; childInstance = nextInstance; } }
[Test] public void NodeName() { InstanceTree tree = PrepareInstanceTree( "struct A { enum8 e [enum=X]; nodename e; } enum X { q=12 }", new byte[] { 0x0C }); InstanceTreeNode lastChangedNode = null; tree.NodeNameChanged += delegate(object sender, NodeNameChangedEventArgs e) { lastChangedNode = e.Node; }; Assert.AreEqual(1, tree.Children [0].Cells.Count); Assert.AreEqual("q", tree.Children [0].NodeName); Assert.AreSame(tree.Children [0], lastChangedNode); }
private TreeNode LoadNode(TreeNodeCollection nodes, int index) { int lastLoadedIndex = 0; while (index >= nodes.Count && lastLoadedIndex < nodes.Count) { InstanceTreeNode instance = (InstanceTreeNode)nodes [lastLoadedIndex].Tag; instance.NeedData(); lastLoadedIndex++; } if (index < nodes.Count) { return(nodes[index]); } return(null); }
private void UpdateNodeName(InstanceTreeNode instance) { TreeNode node; if (_nodeMap.TryGetValue(instance, out node)) { if (InvokeRequired) { _nameChangedNodes.Add(instance); } else { node.Text = AppendSequenceIndex(instance); } } }
private DataTable LoadDS(InstanceTreeNode itn) { if (itn == null) { return(null); } DataTable fakeGridData = new DataTable(); // Make header List <string> headers = new List <string>(); for (int i = 0; i < itn.Children.First().Cells.Count; i++) { fakeGridData.Columns.Add(itn.Children.First().Cells[i].Tag); headers.Add(itn.Children.First().Cells[i].Tag); } this.parent.setFilterField(headers); // Make data DataRow dr; foreach (InstanceTreeNode children in itn.Children) { dr = fakeGridData.NewRow(); for (int i = 0; i < children.Cells.Count; i++) { dr[children.Cells[i].Tag] = children.Cells[i].Value; if (Utils.IsNumeric(children.Cells[i].GetValue())) { this._checksumData += long.Parse(children.Cells[i].Value); } else if (children.Cells[i].GetValue().GetTypeCode() == TypeCode.String && children.Cells[i].Offset < this.GetStream().Length - 34) { byte[] buffer = Utils.ToBytes(children.Cells[i].Value); this._checksumData += ((StrField)children.Cells[i].GetStructDef()).GetWide() ? buffer.Length / 2 : buffer.Length; for (int j = 0; j < buffer.Length; j++) { this._checksumData += buffer[j]; } } else { int a = 10; } } fakeGridData.Rows.Add(dr); } return(fakeGridData); }
[Test] public void NotifyChild() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [offset=a]; } struct B { u8 value; } ", new byte[] { 2, 0, 17, 37 }); InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; tree.Children [0].NeedChildren(); Assert.AreSame(tree.Children [0], lastAddParent); Assert.AreSame(tree.Children [0].Children[0], lastAddChild); }
private void DoLoadChildren(StructInstance instance, InstanceTreeNode parent, Stream stream, long? offset, int count) { StructInstance lastChild = instance.LastChild; string groupName = GetStringAttribute("group"); if (groupName != null) { GroupContainer container = new GroupContainer(parent, groupName); parent.AddChild(container); parent = container; } if (count == 0) return; StructDef childDef = GetStructAttribute("struct"); if (childDef == null) childDef = _structDef; StructInstance childInstance; bool followChildren = GetBoolAttribute("followchildren"); if (offset.HasValue) { childInstance = new StructInstance(childDef, parent, stream, offset.Value); } else { bool firstFollowChildren = followChildren && lastChild != parent; childInstance = new StructInstance(childDef, parent, stream, lastChild, firstFollowChildren); } parent.AddChild(childInstance); if (count > 1) { childInstance.SequenceIndex = 0; } for (int i = 1; i < count; i++) { var nextInstance = new StructInstance(childDef, parent, stream, childInstance, followChildren); parent.AddChild(nextInstance); nextInstance.SequenceIndex = i; childInstance = nextInstance; } }
[Test] public void NotifyFromGroupContainer() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [group=X]; } struct B { u8 value; } ", new byte[] { 2, 17, 37 }); InstanceTreeNode groupInstance = tree.Children[0].Children [0]; InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; groupInstance.NeedChildren(); Assert.AreSame(groupInstance, lastAddParent); Assert.AreSame(groupInstance.Children[0], lastAddChild); }
[Test] public void Preload() { InstanceTree tree = PrepareInstanceTree( "[preload] struct A { u8 a; child B [offset=a]; } [preload] struct B { nodename (\"Q\"); u8 value; child C [offset=Parent.a]; } struct C { u8 value; nodename(\"W\"); }", new byte[] { 2, 0, 17, 37 }); InstanceTreeNode lastAddParent = null; InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddParent = e.Parent; lastAddChild = e.Child; }; tree.Children[0].NeedData(); Assert.AreSame(tree.Children[0], lastAddParent); Assert.AreSame(tree.Children[0].Children[0], lastAddChild); Assert.AreEqual("Q", lastAddChild.NodeName); tree.Children[0].Children[0].NeedChildren(); Assert.AreEqual("W", tree.Children[0].Children[0].Children[0].NodeName); }
private void _structTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Node.Nodes.Count == 0) { currentInstanceTree = (InstanceTreeNode)e.Node.Tag; _structTreeView.BeginUpdate(); try { currentInstanceTree.NeedChildren(); } finally { _structTreeView.EndUpdate(); } if (currentInstanceTree.Children.Count == 0) { WindowsAPI.SetHasChildren(e.Node, false); } } }
private void AddInstanceNode(TreeNode parent, InstanceTreeNode instance) { TreeNode node; if (parent == null) { string fileName = FindDataFile(instance).Name; node = _structTreeView.Nodes.Add(instance.NodeName + " (" + Path.GetFileName(fileName) + ")"); } else { node = parent.Nodes.Add(AppendSequenceIndex(instance)); } _nodeMap.Add(instance, node); node.Tag = instance; if (instance.HasChildren) { WindowsAPI.SetHasChildren(node, true); } }
[Test] public void NotifySiblingInGroup() { InstanceTree tree = PrepareInstanceTree( "struct A { u8 a; child B [group=q]; } struct B { u8 c; if (c != 0) { sibling; } }", new byte[] { 17, 37, 2 }); InstanceTreeNode lastAddChild = null; tree.InstanceAdded += delegate(object sender, InstanceAddedEventArgs e) { lastAddChild = e.Child; }; InstanceTreeNode a = tree.Children[0]; a.NeedChildren(); InstanceTreeNode q = a.Children[0]; q.NeedChildren(); Assert.AreEqual(1, q.Children.Count); InstanceTreeNode b = q.Children[0]; b.NeedChildren(); Assert.AreEqual(2, q.Children.Count); Assert.AreSame(q.Children[1], lastAddChild); }
private DataFile FindDataFile(InstanceTreeNode instance) { InstanceTree tree = instance.GetInstanceTree(); return(_dataFiles.Find(f => f.InstanceTree == tree)); }
private void _structTreeView_AfterSelect(object sender, TreeViewEventArgs e) { _activeInstance = (InstanceTreeNode)e.Node.Tag; if (_nodeControl != null) { _nodeControl.Parent.Controls.Remove(_nodeControl); _nodeControl.Dispose(); _nodeControl = null; } _structTreeView.BeginUpdate(); try { if (_activeInstance == null) { _structGridView.DataSource = new List <StructCell>(); } else { NodeUI ui = FindNodeUI(_activeInstance); if (ui != null) { _nodeControl = ui.CreateControl(); _nodeControl.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(_nodeControl); _structGridView.Visible = false; } else { _structGridView.Visible = true; // _structGridView.DataSource = _activeInstance.Cells; if (_structGridView.DataSource == null) { _structGridView.DataSource = LoadDS(currentInstanceTree); } } // while we're in BeginUpdate, pre-evaluate all cell values _activeInstance.Cells.ToList().ForEach(cell => cell.Value.ToString()); } if (!string.IsNullOrEmpty(this.parent.getFilterField())) { (_structGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("{0} like '%{1}%'", this.parent.getFilterField(), this.parent.getFilterValue()); } } finally { _structTreeView.EndUpdate(); } var instance = _activeInstance as StructInstance; if (instance == null) { InstanceTree tree = ActiveInstanceTree; if (tree != null) { _hexDump.Stream = FindDataFile(tree).Stream; } _currentStructureHighlighter.SetRange(-1, -1); } else { _hexDump.Stream = instance.Stream; _currentStructureHighlighter.SetRange(instance.Offset, instance.EndOffset); } // Re-select grid if (_structGridView.Rows.Count >= e.Node.Index && _structGridView.CurrentCell != null) { _structGridView.CurrentCell = _structGridView.Rows[e.Node.Index].Cells[_structGridView.CurrentCell.ColumnIndex]; } }