Search in sources :

Example 36 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 37 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)

Example 38 with CCodeNode

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

the class CViewContent method createCodeNode.

@Override
public CCodeNode createCodeNode(final INaviFunction parentFunction, final List<? extends INaviInstruction> instructions) {
    Preconditions.checkNotNull(instructions, "IE00286: Instructions argument can not be null");
    if ((parentFunction != null) && !parentFunction.inSameDatabase(provider)) {
        throw new IllegalArgumentException("IE00287: Parent function and view are not in the same database");
    }
    for (final INaviInstruction instruction : instructions) {
        Preconditions.checkNotNull(instruction, "IE00288: Instruction list contains a null-instruction");
        Preconditions.checkArgument(instruction.inSameDatabase(provider), "IE00289: Instruction and view are not in the same database");
    }
    final CCodeNode codeNode = new CCodeNode(-1, 0, 0, 0, 0, Color.WHITE, Color.BLACK, false, true, null, parentFunction, new HashSet<CTag>(), provider);
    for (final INaviInstruction instruction : instructions) {
        codeNode.addInstruction(instruction, null);
    }
    addNode(codeNode);
    updateGraphType(codeNode);
    codeNode.addListener(m_internalNodeListener);
    m_reilFunction = null;
    return codeNode;
}
Also used : CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) 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