Search in sources :

Example 61 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.

the class CLineHighlighter method highlightLine.

/**
 * Highlights or unhighlights a line in a code node.
 *
 * @param node The node where the user clicked.
 * @param codeNode The node that provides the raw data for the node.
 * @param y The y location where the user clicked.
 */
private void highlightLine(final NaviNode node, final INaviCodeNode codeNode, final double y) {
    final double yPos = y - node.getY();
    final int row = node.positionToRow(yPos);
    final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, row);
    if (instruction == null) {
        return;
    }
    if (m_highlightedInstructions.contains(instruction)) {
        codeNode.setInstructionColor(instruction, CHighlightLayers.HIGHLIGHTING_LAYER, null);
        m_highlightedInstructions.remove(instruction);
    } else {
        codeNode.setInstructionColor(instruction, CHighlightLayers.HIGHLIGHTING_LAYER, new Color(0x36D0FE));
        m_highlightedInstructions.add(instruction);
    }
}
Also used : Color(java.awt.Color) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 62 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.

the class CGraphDebugger method toggleBreakpoint.

/**
 * Sets or removes a breakpoint at a given line of a code node.
 *
 * @param debuggerProvider Debugger provider that contains all possible debuggers for the code
 *        node.
 * @param codeNode The code node where the breakpoint is set.
 * @param row The code node row where the breakpoint is set.
 */
public static void toggleBreakpoint(final BackEndDebuggerProvider debuggerProvider, final INaviCodeNode codeNode, final int row) {
    Preconditions.checkNotNull(debuggerProvider, "IE01719: Debugger provider argument can not be null");
    Preconditions.checkNotNull(codeNode, "IE01720: Code node argument can not be null");
    final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, row);
    if (instruction == null) {
        return;
    }
    final IDebugger debugger = getDebugger(debuggerProvider, instruction);
    if (debugger == null) {
        return;
    }
    toggleBreakpoint(debugger.getBreakpointManager(), instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 63 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.

the class CFollowInDumpMenu method addFollowInDumpMenu.

/**
 * Adds the menu that follow in dump menu for the clicked instruction.
 *
 * @param menu The code node menu that is extended.
 * @param model The graph model that provides information about the graph.
 * @param node The node whose menu is created.
 * @param clickedObject The object that was clicked.
 * @param y The y-coordinate of the click.
 */
public static void addFollowInDumpMenu(final JPopupMenu menu, final CGraphModel model, final NaviNode node, final Object clickedObject, final double y) {
    Preconditions.checkNotNull(menu, "IE02371: menu argument can not be null");
    Preconditions.checkNotNull(model, "IE02372: model argument can not be null");
    Preconditions.checkNotNull(node, "IE02373: node argument can not be null");
    final int line = node.positionToRow(y);
    if (line == -1) {
        return;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
    final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, line);
    if (instruction != null) {
        final IDebugger debugger = CGraphDebugger.getDebugger(model.getDebuggerProvider(), instruction);
        if ((debugger != null) && (clickedObject instanceof COperandTreeNode)) {
            final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
            if (activeThread != null) {
                final CDebugPerspectiveModel viewModel = (CDebugPerspectiveModel) model.getGraphPanel().getViewModel().getModel(PerspectiveType.DebugPerspective);
                final COperandTreeNode treeNode = (COperandTreeNode) clickedObject;
                final boolean added = addFollowInDumpMenu(menu, viewModel, debugger, activeThread, instruction.getModule(), treeNode);
                if (added) {
                    menu.addSeparator();
                }
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 64 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.

the class CNodeFunctions method splitAfter.

/**
 * Splits a node.
 *
 * @param view View the node belongs to.
 * @param originalNode Node to split.
 * @param instruction Instruction after which the node is split.
 */
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
    final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
    if (instruction == Iterables.getLast(oldInstructions)) {
        return;
    }
    // Step I: Find out what instructions belong to the new upper block and what
    // instructions belong to the new lower block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentInstructions = upperInstructions;
    for (final INaviInstruction oldInstruction : oldInstructions) {
        currentInstructions.add(oldInstruction);
        if (oldInstruction == instruction) {
            currentInstructions = lowerInstructions;
        }
    }
    // Step II: Create the two new code nodes.
    INaviFunction parentFunction = null;
    try {
        parentFunction = originalNode.getParentFunction();
    } catch (final MaybeNullException e) {
    // No parent function
    }
    final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
    final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
    newNode1.setColor(originalNode.getColor());
    newNode1.setBorderColor(originalNode.getBorderColor());
    newNode2.setColor(originalNode.getColor());
    // Step III: Transfer node comments and instruction comments from the old node
    // to the new nodes.
    transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
    // Step IV: Connect the two new nodes.
    view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
    for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
        view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
    }
    for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
        view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
    }
    // Step VI: Get rid of the old node.
    view.getContent().deleteNode(originalNode);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 65 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.

the class InternalNodeCallBack method zoomToAddress.

/**
 * Zooms to an address in a code node.
 *
 * @param graph The graph where zooming happens.
 * @param address The address to zoom to.
 * @param animate True, to animate the zoom operation.
 * @param node The node to zoom to if it contains the address.
 * @param codeNode The code node that backs the visible node.
 *
 * @return True, if the node contains the address and was zoomed to.
 */
static boolean zoomToAddress(final ZyGraph graph, final IAddress address, final boolean animate, final NaviNode node, final INaviCodeNode codeNode) {
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        if (instruction.getAddress().equals(address)) {
            uncollapseParents(codeNode);
            if (!node.isVisible()) {
                graph.showNode(node, true);
            }
            ZoomFunctions.zoomToNode(graph, node, CCodeNodeHelpers.instructionToLine(codeNode, instruction), animate);
            return true;
        }
    }
    return false;
}
Also used : INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)82 Test (org.junit.Test)27 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)26 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 ArrayList (java.util.ArrayList)24 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)20 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)18 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)16 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)15 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)15 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)9 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)9 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)8 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)7