Пример #1
0
        void SetRoot(uint address)
        {
            address |= 0x80000000;

            _treeViewDecompile.Nodes.Clear();
            var rootNode = _treeViewDecompile.Nodes.Add(DecompilerFunctionUtilities.AddressToString(address));

            // Expand root node
            ExpandNode(rootNode, false);

            _currentRootAddress = address;
        }
Пример #2
0
        // Unused, but partially implemented in the case of smarters history that can resolve the selected function in the tree view
        public void SelectSetRootPath(IEnumerable <uint> rootPath)
        {
            if (rootPath == null)
            {
                return;
            }

            bool     first       = true;
            TreeNode currentNode = null;

            foreach (uint address in rootPath)
            {
                // First node should update the root
                if (first)
                {
                    if (address != _currentRootAddress)
                    {
                        SetRoot(address);
                    }

                    currentNode = _treeViewDecompile.TopNode;
                    first       = false;
                    continue;
                }

                // Failed to find node, end
                if (currentNode == null)
                {
                    return;
                }

                // Create subnodes
                ExpandNode(currentNode, false);

                // Find address in sub-nodes
                var foundNodes = currentNode.Nodes.Find(DecompilerFunctionUtilities.AddressToString(address), false);
                if (foundNodes.Length == 0)
                {
                    return;
                }
                currentNode = foundNodes[0];
            }

            _treeViewDecompile.SelectedNode = currentNode;
        }
Пример #3
0
        void ExpandNode(TreeNode node, bool decompile)
        {
            if (node.Text == null || node.Text == "" || node.Text == "?")
            {
                return;
            }

            uint?address = TryParseFunctionAddress(node.Text);

            if (!address.HasValue)
            {
                return;
            }

            // Expand if not already expanded
            if (node.ForeColor != Color.Blue)
            {
                int?         instructionCount = DecompilerFunctionUtilities.FindEndAddress(address.Value, _ramState);
                List <uint?> calls            = new List <uint?>();
                if (instructionCount.HasValue)
                {
                    calls.AddRange(DecompilerFunctionUtilities.GetCalls(address.Value, instructionCount.Value, _ramState));
                }

                foreach (var function in calls)
                {
                    TreeNode newNode;
                    if (!function.HasValue)
                    {
                        newNode = node.Nodes.Add("?");
                    }
                    else
                    {
                        newNode = node.Nodes.Add(DecompilerFunctionUtilities.AddressToString(function.Value));
                    }
                    newNode.ForeColor = Color.Red;
                }
            }

            if (decompile)
            {
                Decompile(address.Value, false);
            }
            node.ForeColor = Color.Blue;
        }
Пример #4
0
        public void Decompile(uint address, bool setRoot, bool updateHistory = true)
        {
            address |= 0x80000000;

            if (_ramState == null)
            {
                UpdateSnapshot();
            }

            if (setRoot)
            {
                SetRoot(address);
            }

            if (updateHistory)
            {
                HistoricPoint currentPoint = new HistoricPoint(address, null);
                if (_currentHistoricPoint != null && currentPoint == _currentHistoricPoint.Value)
                {
                    // Same history, don't update
                }
                // End of history is free; add to end
                else if (_currentHistoricPoint == null || _currentHistoricPoint == _history.Last)
                {
                    _currentHistoricPoint = _history.AddLast(currentPoint);
                }
                else // End of history contians history
                {
                    // Same history; don't change
                    if (currentPoint == _currentHistoricPoint.Next.Value)
                    {
                        _currentHistoricPoint = _currentHistoricPoint.Next;
                    }
                    else // Writing over existing history
                    {
                        // Remove existing history
                        while (_history.Last != null && _history.Last != _currentHistoricPoint)
                        {
                            _history.RemoveLast();
                        }

                        // Add new item
                        _currentHistoricPoint = _history.AddLast(currentPoint);
                    }
                }

                // Clean history
                while (_history.Count > MaxHistoryCount)
                {
                    // We need to make sure that we are not removing the first element, which
                    // will never happen, since we are always at least moving away from the first item
                    // Therefore, the only case would be when MaxHistory is set to 0, which it never is.
                    _history.RemoveFirst();
                }
                UpdateHistoryButtons();
            }

            _decompilerView.Text = DecompileFunction(address);
            _textBoxAddress.Text = DecompilerFunctionUtilities.AddressToString(address);
            _currentAddress      = address;
        }