Search in sources :

Example 11 with INaviCodeNode

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

the class CCodeNodeMenu method addOpenOriginalFunctionMenu.

private void addOpenOriginalFunctionMenu(final CGraphModel model, final NaviNode node) {
    final INaviCodeNode rawNode = (INaviCodeNode) node.getRawNode();
    try {
        final INaviFunction nodeFunction = rawNode.getParentFunction();
        final INaviFunction viewFunction = model.getViewContainer().getFunction(model.getGraph().getRawView());
        if (nodeFunction != viewFunction) {
            add(CActionProxy.proxy(new COpenOriginalFunction(model.getParent(), model.getViewContainer(), nodeFunction)));
        }
    } catch (final MaybeNullException e) {
    // If there is no original function then we can not open it.
    }
}
Also used : COpenOriginalFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.COpenOriginalFunction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 12 with INaviCodeNode

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

the class InternalNodeCallBack method zoomToAddress.

/**
 * Zooms to the first occurrence of an address in a graph.
 *
 * @param graph The graph where the zoom operation takes place.
 * @param address The address to zoom to.
 */
public static void zoomToAddress(final ZyGraph graph, final IAddress address) {
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            if (node.getRawNode() instanceof INaviCodeNode) {
                final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
                for (final INaviInstruction instruction : codeNode.getInstructions()) {
                    if (instruction.getAddress().equals(address)) {
                        uncollapseParents(codeNode);
                        graph.showNode(node, true);
                        ZoomFunctions.zoomToNode(graph, node);
                        return IterationMode.STOP;
                    }
                }
            } else if (node.getRawNode() instanceof INaviFunctionNode) {
                final INaviFunctionNode functionNode = (INaviFunctionNode) node.getRawNode();
                if (functionNode.getFunction().getAddress().equals(address)) {
                    uncollapseParents(functionNode);
                    graph.showNode(node, true);
                    ZoomFunctions.zoomToNode(graph, node);
                    return IterationMode.STOP;
                }
            }
            return IterationMode.CONTINUE;
        }
    });
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 13 with INaviCodeNode

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

the class CDebuggerPainter method updateDebuggerHighlighting.

/**
 * Updates the program counter highlighting in a whole graph.
 *
 * @param graph The graph where the highlighting is updated.
 * @param address The address of the program counter to be highlighted.
 * @param module The module in which the address is located.
 */
public static void updateDebuggerHighlighting(final ZyGraph graph, final UnrelocatedAddress address, final INaviModule module) {
    Preconditions.checkNotNull(graph, "IE02187: Graph argument can not be null");
    Preconditions.checkNotNull(address, "IE02188: Address argument can not be null");
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            final INaviViewNode rawNode = node.getRawNode();
            if (rawNode instanceof ICodeNode) {
                final INaviCodeNode codeNode = (INaviCodeNode) rawNode;
                try {
                    if (module.equals(codeNode.getParentFunction().getModule())) {
                        updateDebuggerHighlighting(graph, address, node, codeNode);
                    }
                } catch (final MaybeNullException exception) {
                    CUtilityFunctions.logException(exception);
                }
            } else if (rawNode instanceof INaviFunctionNode) {
                final INaviFunctionNode functionNode = (INaviFunctionNode) rawNode;
                if (module.equals(functionNode.getFunction().getModule())) {
                    updateDebuggerHighlighting(address, node, functionNode);
                }
            }
            return IterationMode.CONTINUE;
        }
    });
    ZyZoomHelpers.zoomToAddress(graph, address.getAddress(), module, false);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ICodeNode(com.google.security.zynamics.zylib.gui.zygraph.nodes.ICodeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode)

Example 14 with INaviCodeNode

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

the class CNodeClickHandler method handleRegisterTracking.

private void handleRegisterTracking(final NaviNode node, final double y, final COperandTreeNode operand, final AnalysisDirection direction) {
    if (!(node.getRawNode() instanceof INaviCodeNode)) {
        // register tracking is only possible on code nodes.
        return;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
    final double yPos = y - node.getY();
    final int row = node.positionToRow(yPos);
    final INaviInstruction instruction = CCodeNodeHelpers.lineToInstruction(codeNode, row);
    if (instruction == null) {
        return;
    }
    if (!operand.getType().equals(ExpressionType.REGISTER)) {
        return;
    }
    final Set<String> clearedRegisters = Sets.newHashSet();
    if (instruction.getArchitecture().equalsIgnoreCase("x86-32")) {
        clearedRegisters.add("eax");
    } else if (instruction.getArchitecture().equalsIgnoreCase("x86-64")) {
        clearedRegisters.add("rax");
    } else if (instruction.getArchitecture().equalsIgnoreCase("PowerPC-32")) {
        clearedRegisters.addAll(Lists.newArrayList("R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12"));
    } else if (instruction.getArchitecture().equalsIgnoreCase("ARM-32")) {
        clearedRegisters.addAll(Lists.newArrayList("r0", "r1", "r2", "r3", "r12", "r14"));
    } else if (instruction.getArchitecture().equalsIgnoreCase("MIPS-32")) {
        clearedRegisters.addAll(Lists.newArrayList("$a0", "$a1", "$a2", "$a3", "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$v0", "$v1"));
    } else {
        return;
    }
    final boolean trackIncoming = instruction.getOperandPosition(operand.getOperand()) != 0;
    final RegisterTrackingOptions options = new RegisterTrackingOptions(false, clearedRegisters, trackIncoming, direction);
    try {
        // TODO(timkornau): comment this code in once we know how to access the bottom panel.
        // final CTrackingResult result =
        CTracking.track(m_model.getGraph().getRawView(), instruction, operand.getValue(), options);
    } catch (final InternalTranslationException exception) {
        CUtilityFunctions.logException(exception);
    }
// TODO: (timkornau@google) there is currently no way to access the bottom panel to display the
// results. We need to somehow get access to the register tracking results container which
// exposes a method to set a new result.
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 15 with INaviCodeNode

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

the class CGraphDebuggerTest method testToggleBreakpoint3.

@Test
public void testToggleBreakpoint3() {
    final MockModule module = new MockModule();
    module.getConfiguration().setDebugger(m_debugger);
    m_debugger.setAddressTranslator(module, m_fileBase, m_imageBase);
    final DebugTargetSettings target = new ModuleTargetSettings(module);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    debuggerProvider.addDebugger(m_debugger);
    final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
    final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
    assertEquals(1, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(0x124, m_debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, 0).getAddress().getAddress().getAddress().toLong());
    assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_debugger.getBreakpointManager().getBreakpointStatus(BreakpointType.REGULAR, 0));
    CGraphDebugger.toggleBreakpoint(debuggerProvider, codeNode, 2);
    assertEquals(0, m_debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.REGULAR));
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) Test(org.junit.Test)

Aggregations

INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)70 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)25 Test (org.junit.Test)23 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)21 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)18 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)17 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)14 ArrayList (java.util.ArrayList)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)9 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)9 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)8 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)5