Search in sources :

Example 16 with CCodeNode

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

the class CVariableHighlighterTest method test1Simple.

@Test
public void test1Simple() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final ZyGraph graph = ZyGraphFactory.generateTestGraph();
    final List<INaviInstruction> mockInstructions = new ArrayList<INaviInstruction>();
    final CCodeNode node = graph.getRawView().getBasicBlocks().get(0);
    final NaviNode naviNode = graph.getNode(node);
    mockInstructions.add(Iterables.get(node.getInstructions(), 0));
    final BackEndDebuggerProvider provider = new MockDebuggerProvider();
    @SuppressWarnings("unused") final CCodeNodeUpdater updater = new CCodeNodeUpdater(graph, naviNode, node, provider);
    assertFalse(naviNode.getRealizer().getNodeContent().getLineContent(0).hasHighlighting(CHighlightLayers.VARIABLE_LAYER));
    CVariableHighlighter.highlightInstructions(graph, mockInstructions);
    assertTrue(naviNode.getRealizer().getNodeContent().getLineContent(0).hasHighlighting(CHighlightLayers.VARIABLE_LAYER));
}
Also used : ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CCodeNodeUpdater(com.google.security.zynamics.binnavi.ZyGraph.Updaters.CodeNodes.CCodeNodeUpdater) ArrayList(java.util.ArrayList) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) BackEndDebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.BackEndDebuggerProvider) MockDebuggerProvider(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebuggerProvider) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 17 with CCodeNode

use of com.google.security.zynamics.binnavi.disassembly.CCodeNode 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)

Example 18 with CCodeNode

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

the class CTaggedGraphNodeNodeTest method test1Simple.

@Test
public void test1Simple() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final ZyGraph graph = ZyGraphFactory.generateTestGraph();
    final CCodeNode node = graph.getRawView().getBasicBlocks().get(0);
    final NaviNode naviNode = graph.getNode(node);
    @SuppressWarnings("unused") final CTaggedGraphNodeNode taggedNode = new CTaggedGraphNodeNode(graph, naviNode);
}
Also used : ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) Test(org.junit.Test)

Example 19 with CCodeNode

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

the class CCodeNodeParser method extractNode.

/**
   * Builds individual nodes from the given dataset.
   *
   * @param dataset The dataset that provides information about nodes and instructions.
   * @return The node generated by that iteration.
   *
   * @throws ParserException Thrown if the node data could not be read.
   * @throws CPartialLoadException Thrown if not all required modules are loaded.
   */
private CCodeNode extractNode(final ICodeNodeProvider dataset) throws ParserException, CPartialLoadException {
    // Create the first node if necessary.
    if (currentNode == null) {
        currentNode = createCurrentNode(dataset);
    }
    final CCodeNode nodeInProcess = currentNode;
    // We have to get all instructions that belong to the node.
    while ((currentLine = extractLine(dataset)) != null) {
        if (currentLine.getBasicBlock() == currentNode.getId()) {
            // The instruction belongs to the current block => just add it.
            addInstruction(currentNode, currentLine);
        } else {
            // We found an instruction that belongs to the next block
            // => Create a new block and add the instruction there.
            currentNode = new CCodeNode(currentLine.getBasicBlock(), currentLine.getX(), currentLine.getY(), currentLine.getWidth(), currentLine.getHeight(), currentLine.getColor(), currentLine.getBorderColor(), currentLine.isSelected(), currentLine.isVisible(), null, currentLine.getParentFunction(), new HashSet<CTag>(), sqlProvider);
            addInstruction(currentNode, currentLine);
            return nodeInProcess;
        }
    }
    // We have reached the end of the data set.
    currentNode = null;
    return nodeInProcess;
}
Also used : CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) HashSet(java.util.HashSet)

Example 20 with CCodeNode

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

the class CUnInliner method unInline.

/**
   * Uninlines the inlined function a given node belongs to.
   *
   * @param view The view where the uninline operation takes place.
   * @param node The start node.
   *
   * @return True, if the operation was successful. False, if it was not.
   */
public static boolean unInline(final INaviView view, final INaviCodeNode node) {
    try {
        final CInlinedNodes inlinedNodes = getInlinedNodes(node);
        if (inlinedNodes == null) {
            return false;
        }
        final List<INaviInstruction> instructions = Lists.newArrayList(inlinedNodes.getStartNode().getInstructions());
        final boolean mergeBlocks = inlinedNodes.getEndNode().getIncomingEdges().size() == 1;
        if (mergeBlocks) {
            instructions.addAll(Lists.newArrayList(inlinedNodes.getEndNode().getInstructions()));
        }
        final CCodeNode combinedNode = view.getContent().createCodeNode(getParentFunction(inlinedNodes.getStartNode()), instructions);
        combinedNode.setColor(inlinedNodes.getStartNode().getColor());
        combinedNode.setBorderColor(inlinedNodes.getStartNode().getBorderColor());
        removeTextNodes(view, inlinedNodes.getInlinedNodes());
        view.getContent().deleteNodes(inlinedNodes.getInlinedNodes());
        for (final INaviEdge incomingEdge : inlinedNodes.getStartNode().getIncomingEdges()) {
            view.getContent().createEdge(incomingEdge.getSource(), combinedNode, incomingEdge.getType());
        }
        if (mergeBlocks) {
            for (final INaviEdge outgoingEdge : inlinedNodes.getEndNode().getOutgoingEdges()) {
                view.getContent().createEdge(combinedNode, outgoingEdge.getTarget(), outgoingEdge.getType());
            }
        } else {
            view.getContent().createEdge(combinedNode, inlinedNodes.getEndNode(), EdgeType.JUMP_UNCONDITIONAL);
        }
        view.getContent().deleteNode(inlinedNodes.getStartNode());
        if (mergeBlocks) {
            view.getContent().deleteNode(inlinedNodes.getEndNode());
        }
        return true;
    } catch (final IllegalStateException exception) {
        CUtilityFunctions.logException(exception);
        return false;
    }
}
Also used : CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)38 Test (org.junit.Test)23 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)16 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)13 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)13 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)12 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)11 ArrayList (java.util.ArrayList)11 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)10 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)9 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)8 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)7 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)7 MockCodeNodeProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider)6 CCodeNodeParser (com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser)6 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)6