Search in sources :

Example 1 with INaviCodeNode

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

the class OpenInLastWindowAndZoomToAddressAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent event) {
    final FutureCallback<Boolean> callBack = new FutureCallback<Boolean>() {

        @Override
        public void onFailure(final Throwable t) {
            CUtilityFunctions.logException(t);
        }

        @Override
        public void onSuccess(final Boolean result) {
            ZyGraph graph = null;
            final List<CGraphWindow> windows = CWindowManager.instance().getOpenWindows();
            for (final CGraphWindow graphContainer : windows) {
                for (final IGraphPanel window : graphContainer) {
                    if (reference.getView().equals(window.getModel().getGraph().getRawView())) {
                        graph = window.getModel().getGraph();
                    }
                }
            }
            for (final NaviNode node : graph.getNodes()) {
                if (node.getRawNode() instanceof INaviCodeNode) {
                    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
                    for (final INaviInstruction instruction : codeNode.getInstructions()) {
                        if (instruction.getAddress().equals(reference.getAddress())) {
                            ZyZoomHelpers.zoomToAddress(graph, reference.getAddress());
                            CrossReferencePainter.paintCrossReference(node, codeNode, reference, instruction);
                        }
                    }
                }
            }
        }
    };
    CShowViewFunctions.showViewsAndPerformCallBack(m_parent, m_container, m_views, CWindowManager.instance().getLastWindow(), callBack);
}
Also used : CGraphWindow(com.google.security.zynamics.binnavi.Gui.GraphWindows.CGraphWindow) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) IGraphPanel(com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphPanel) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) FutureCallback(com.google.common.util.concurrent.FutureCallback) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 2 with INaviCodeNode

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

the class CViewContent method updateGraphType.

/**
 * Calculates the new graph type of the view from the current state of the view graph.
 */
private void updateGraphType() {
    boolean hasCodeNode = false;
    boolean hasFunctionNode = false;
    for (final INaviViewNode node : graph.getNodes()) {
        if (node instanceof INaviFunctionNode) {
            hasFunctionNode = true;
            if (hasCodeNode) {
                setGraphType(GraphType.MIXED_GRAPH);
                return;
            }
        } else if (node instanceof INaviCodeNode) {
            hasCodeNode = true;
            if (hasFunctionNode) {
                setGraphType(GraphType.MIXED_GRAPH);
                return;
            }
        }
    }
    if (hasCodeNode) {
        setGraphType(GraphType.FLOWGRAPH);
    } else if (hasFunctionNode) {
        setGraphType(GraphType.CALLGRAPH);
    } else {
        setGraphType(GraphType.MIXED_GRAPH);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)

Example 3 with INaviCodeNode

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

the class CDataflowViewCreator method create.

/**
 * Creates a new dataflow view.
 *
 * @param container The container in which the dataflow view is created.
 * @param view The normal view that provides the control-flow information.
 *
 * @return The created dataflow view.
 *
 * @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
 */
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
    Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
    Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
    final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
    for (final CCodeNode codeNode : view.getBasicBlocks()) {
        for (final INaviInstruction instruction : codeNode.getInstructions()) {
            instructions.put(instruction.getAddress(), instruction);
        }
    }
    final ReilFunction function = view.getContent().getReilCode();
    final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
    final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
    final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
    final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
    for (final OperandGraphNode operandGraphNode : operandGraph) {
        final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
        final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
        if (instructionMap.containsKey(instruction)) {
            nodeMap.put(operandGraphNode, instructionMap.get(instruction));
            continue;
        }
        final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
        codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
        nodeMap.put(operandGraphNode, codeNode);
        instructionMap.put(instruction, codeNode);
    }
    for (final OperandGraphEdge edge : operandGraph.getEdges()) {
        final INaviCodeNode source = nodeMap.get(edge.getSource());
        final INaviCodeNode target = nodeMap.get(edge.getTarget());
        if (source.equals(target)) {
            continue;
        }
        dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
    }
    return dfView;
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) HashMap(java.util.HashMap) ReilFunction(com.google.security.zynamics.reil.ReilFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) OperandGraph(com.google.security.zynamics.reil.algorithms.mono.OperandGraph) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) OperandGraphEdge(com.google.security.zynamics.reil.algorithms.mono.OperandGraphEdge) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) OperandGraphNode(com.google.security.zynamics.reil.algorithms.mono.OperandGraphNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 4 with INaviCodeNode

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

the class CUnInliner method getInlinedNodes.

/**
 * Determines inlining information starting with a given node.
 * TODO(thomasdullien): This code is pretty thoroughly broken for any form of
 * nested inlining and needs to be rewritten.
 *
 * @param node The start node.
 *
 * @return Information about the inlining boundaries.
 */
public static CInlinedNodes getInlinedNodes(final INaviCodeNode node) {
    Preconditions.checkNotNull(node, "IE02750: node argument can not be null");
    // Performs a recursive backward search upward in the graph until it finds
    // an 'enter inlined function' edge, then returns it's source node. This
    // will usually be "a function layer up" from the function that is about to
    // be uninlined. Please note that if, while searching up, it enters a
    // different inlined subfunction, this function will return a wrong node.
    final INaviCodeNode startNode = searchForSourceNodeOfEnterInlinedEdge(node);
    // Performs a recursive forward search downward in the graph until it finds
    // a 'leave inlined function' edge whose source node is in the same function
    // as 'node'. Returns the target of this edge. Please note that if, while
    // searching down a second nested inlined version of the current function is
    // found, this code will return the wrong node.
    final INaviCodeNode endNode = getEndNode(node);
    if (startNode == null || endNode == null) {
        return null;
    }
    // to simply carry on for now until the above functions can be fixed.
    if (hasDifferentParentFunctions(startNode, endNode)) {
        NaviLogger.info("Uninlining yielded almost certainly incorrect results.");
    }
    final Set<INaviViewNode> preds = GraphAlgorithms.getPredecessorsUpToNode(endNode, startNode);
    final Set<INaviViewNode> succs = GraphAlgorithms.getSuccessorsDownToNode(startNode, endNode);
    preds.retainAll(succs);
    return new CInlinedNodes(startNode, endNode, ImmutableList.copyOf(preds));
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 5 with INaviCodeNode

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

the class CViewInserter method insertCodeNode.

/**
 * Clones a source node and inserts the cloned node into the target view.
 *
 * @param target The target view where the node is inserted.
 * @param node Node from the source view that is cloned.
 *
 * @return The cloned code node.
 */
private static INaviCodeNode insertCodeNode(final INaviView target, final INaviCodeNode node) {
    // TODO: cloning the node is a bad solution since this just fixes the symptoms: instructions are
    // closed two times
    final INaviCodeNode sourceNode = (INaviCodeNode) node.cloneNode();
    final Iterable<INaviInstruction> instructions = sourceNode.getInstructions();
    final ArrayList<INaviInstruction> instructionList = Lists.newArrayList(instructions);
    CCodeNode codeNode;
    try {
        codeNode = target.getContent().createCodeNode(sourceNode.getParentFunction(), instructionList);
    } catch (final MaybeNullException e) {
        codeNode = target.getContent().createCodeNode(null, instructionList);
    }
    if (sourceNode.getComments().getGlobalCodeNodeComment() != null) {
        codeNode.getComments().initializeGlobalCodeNodeComment(sourceNode.getComments().getGlobalCodeNodeComment());
    }
    if (sourceNode.getComments().getLocalCodeNodeComment() != null) {
        codeNode.getComments().initializeLocalCodeNodeComment(sourceNode.getComments().getLocalCodeNodeComment());
    }
    final Iterable<INaviInstruction> newInstructions = codeNode.getInstructions();
    for (int i = 0; i < Iterables.size(instructions); i++) {
        codeNode.getComments().initializeLocalInstructionComment(Iterables.get(newInstructions, i), sourceNode.getComments().getLocalInstructionComment(Iterables.get(instructions, i)));
    }
    return codeNode;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

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