Search in sources :

Example 71 with INaviInstruction

use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction 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 72 with INaviInstruction

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

the class CCodeNodeParser method parse.

/**
 * Takes the information from the components passed into the constructor and creates a list of
 * nodes from that information.
 *
 * @return The list of nodes created by the parser.
 *
 * @throws ParserException Thrown if the instruction data could not be loaded.
 * @throws CPartialLoadException Thrown if not all necessary modules are loaded.
 */
public List<CCodeNode> parse() throws ParserException, CPartialLoadException {
    // it to point to the proper data.
    if (!dataProvider.next()) {
        return new ArrayList<CCodeNode>();
    }
    // Generate the nodes from the raw data.
    while (true) {
        if (dataProvider.isAfterLast()) {
            if (currentNode != null) {
                nodes.add(currentNode);
            }
            break;
        }
        nodes.add(extractNode(dataProvider));
    }
    final HashSet<Integer> allComments = Sets.newHashSet();
    allComments.addAll(localCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToInstruction.keySet());
    allComments.addAll(localCommentIdToInstruction.keySet());
    try {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = sqlProvider.loadMultipleCommentsById(allComments);
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            if (localCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                localCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeLocalCodeNodeComment(commentIdToComment.getValue());
            }
            if (globalCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeGlobalCodeNodeComment(commentIdToComment.getValue());
            }
            if (localCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                final Pair<INaviInstruction, INaviCodeNode> instructionToCodeNode = localCommentIdToInstruction.get(commentIdToComment.getKey());
                instructionToCodeNode.second().getComments().initializeLocalInstructionComment(instructionToCodeNode.first(), commentIdToComment.getValue());
            }
            if (globalCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToInstruction.get(commentIdToComment.getKey()).initializeGlobalComment(commentIdToComment.getValue());
            }
        }
    } catch (final CouldntLoadDataException exception) {
        throw new CPartialLoadException("Error: Comments could not be loaded.", null);
    }
    return nodes;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 73 with INaviInstruction

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

the class CCodeNodeParser method addInstruction.

/**
 * Adds an instruction to a code node.
 *
 * @param node The code node where the instruction is added.
 * @param line The raw instruction data to add.
 */
private void addInstruction(final CCodeNode node, final InstructionLine line) {
    final CInstruction instruction = InstructionConverter.createInstruction(line, sqlProvider);
    InstructionCache.get(sqlProvider).addInstruction(instruction);
    localCommentIdToInstruction.put(line.getLocalInstructionCommentId(), new Pair<INaviInstruction, INaviCodeNode>(instruction, node));
    globalCommentIdToInstruction.put(line.getGlobalInstructionComment(), instruction);
    localCommentIdToCodeNode.put(line.getLocalNodeCommentId(), node);
    globalCommentIdToCodeNode.put(line.getGlobalNodeCommentId(), node);
    node.addInstruction(instruction, null);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 74 with INaviInstruction

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

the class View method createNode.

// ! Clones an existing node.
/**
 * Creates a new view node by cloning an existing view node.
 *
 * @param node The node to clone.
 *
 * @return The cloned node.
 */
public ViewNode createNode(final ViewNode node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    if (node instanceof CodeNode) {
        final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
        for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
            Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
            instructionsList.add(instruction.getNative());
        }
        CCodeNode newNode;
        try {
            newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
        } catch (final MaybeNullException e) {
            newNode = naviView.getContent().createCodeNode(null, instructionsList);
        }
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof FunctionNode) {
        final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof TextNode) {
        final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof GroupNode) {
        throw new IllegalStateException("Group nodes can not be cloned");
    } else {
        throw new IllegalStateException("Error: Unknown node type");
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 75 with INaviInstruction

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

the class CStepEndHelper method getEndAddresses.

/**
 * Returns the addresses of all final instructions of a graph.
 *
 * @param graph The graph whose final addresses are returned.
 *
 * @return The final addresses of the graph.
 */
public static Set<BreakpointAddress> getEndAddresses(final ZyGraph graph) {
    final Set<BreakpointAddress> instructions = new HashSet<BreakpointAddress>();
    graph.iterate(new INodeCallback<NaviNode>() {

        @Override
        public IterationMode next(final NaviNode node) {
            if ((node.getRawNode() instanceof INaviCodeNode) && node.getChildren().isEmpty()) {
                final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
                final INaviInstruction lastInstruction = Iterables.getLast(cnode.getInstructions());
                instructions.add(new BreakpointAddress(lastInstruction.getModule(), new UnrelocatedAddress(lastInstruction.getAddress())));
            }
            return IterationMode.CONTINUE;
        }
    });
    return instructions;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) IterationMode(com.google.security.zynamics.zylib.types.common.IterationMode) HashSet(java.util.HashSet) 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