Search in sources :

Example 6 with Instruction

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

the class InstructionFinders method findInstruction.

/**
   * Searches for an instruction in a basic block.
   *
   * @param block The basic block to search through.
   * @param searchInstruction The instruction to search for.
   *
   * @return The API instruction object that wraps the search instruction.
   */
public static Instruction findInstruction(final BasicBlock block, final IInstruction searchInstruction) {
    Preconditions.checkNotNull(block, "IE02005: Block argument can not be null");
    Preconditions.checkNotNull(searchInstruction, "IE02012: Instruction argument can not be null");
    for (final Instruction instruction : block.getInstructions()) {
        if (instruction.getNative() == searchInstruction) {
            return instruction;
        }
    }
    throw new IllegalStateException("IE01272: Could not determine what instruction could not be translated");
}
Also used : Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction)

Example 7 with Instruction

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

the class InstructionFinders method findInstruction.

/**
   * Searches for an instruction in a view.
   *
   * @param view The view to search through.
   * @param searchInstruction The instruction to search for.
   *
   * @return The API instruction object that wraps the search instruction.
   */
public static Instruction findInstruction(final View view, final IInstruction searchInstruction) {
    Preconditions.checkNotNull(view, "IE02056: View argument can not be null");
    Preconditions.checkNotNull(searchInstruction, "IE02060: Instruction argument can not be null");
    for (final ViewNode node : view.getGraph().getNodes()) {
        if (node instanceof CodeNode) {
            final CodeNode codeNode = (CodeNode) node;
            for (final Instruction instruction : codeNode.getInstructions()) {
                if (instruction.getNative() == searchInstruction) {
                    return instruction;
                }
            }
        }
    }
    throw new IllegalStateException("IE01275: Could not determine what instruction could not be translated");
}
Also used : CodeNode(com.google.security.zynamics.binnavi.API.disassembly.CodeNode) ViewNode(com.google.security.zynamics.binnavi.API.disassembly.ViewNode) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction)

Example 8 with Instruction

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

the class PathFinder method splitBlock.

/**
   * Splits a code node into two nodes at a function call. If the input node really is split, it is
   * removed from the view. If the input node is not split (because the calling instruction is the
   * last instruction of the code node) then the view nodes remain unchanged.
   *
   * @param view The view the code node belongs to.
   * @param function The function the code node belongs to.
   * @param node The node to split.
   * @param instruction The calling instruction after which the node is split.
   *
   * @return A node pair that contains the two new nodes or the input node and null if the input
   *         node was not split.
   */
private static NodePair splitBlock(final View view, final Function function, final CodeNode node, final Instruction instruction) {
    boolean before = true;
    final List<Instruction> beforeInstructions = new ArrayList<Instruction>();
    final List<Instruction> afterInstructions = new ArrayList<Instruction>();
    for (final Instruction nodeInstruction : node.getInstructions()) {
        if (before) {
            beforeInstructions.add(nodeInstruction);
        } else {
            afterInstructions.add(nodeInstruction);
        }
        if (nodeInstruction == instruction) {
            before = false;
        }
    }
    if (afterInstructions.isEmpty()) {
        return new NodePair(node, null);
    } else {
        final CodeNode firstNode = view.createCodeNode(function, beforeInstructions);
        final CodeNode secondNode = view.createCodeNode(function, afterInstructions);
        firstNode.setColor(node.getColor());
        secondNode.setColor(DEFAULT_BLOCK_COLOR);
        for (final ViewEdge edge : node.getIncomingEdges()) {
            final ViewEdge newEdge = view.createEdge(edge.getSource(), firstNode, edge.getType());
            newEdge.setColor(edge.getColor());
        }
        for (final ViewEdge edge : node.getOutgoingEdges()) {
            final ViewEdge newEdge = view.createEdge(secondNode, edge.getTarget(), edge.getType());
            newEdge.setColor(edge.getColor());
        }
        view.deleteNode(node);
        return new NodePair(firstNode, secondNode);
    }
}
Also used : CodeNode(com.google.security.zynamics.binnavi.API.disassembly.CodeNode) ArrayList(java.util.ArrayList) ViewEdge(com.google.security.zynamics.binnavi.API.disassembly.ViewEdge) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction)

Aggregations

Instruction (com.google.security.zynamics.binnavi.API.disassembly.Instruction)8 IInstruction (com.google.security.zynamics.zylib.disassembly.IInstruction)4 CodeNode (com.google.security.zynamics.binnavi.API.disassembly.CodeNode)3 Function (com.google.security.zynamics.binnavi.API.disassembly.Function)2 ViewEdge (com.google.security.zynamics.binnavi.API.disassembly.ViewEdge)2 ViewNode (com.google.security.zynamics.binnavi.API.disassembly.ViewNode)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 ArrayList (java.util.ArrayList)2 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)1 BasicBlock (com.google.security.zynamics.binnavi.API.disassembly.BasicBlock)1 Database (com.google.security.zynamics.binnavi.API.disassembly.Database)1 FunctionBlock (com.google.security.zynamics.binnavi.API.disassembly.FunctionBlock)1 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)1 TagManager (com.google.security.zynamics.binnavi.API.disassembly.TagManager)1 View (com.google.security.zynamics.binnavi.API.disassembly.View)1 ViewContainer (com.google.security.zynamics.binnavi.API.disassembly.ViewContainer)1 CDatabase (com.google.security.zynamics.binnavi.Database.CDatabase)1 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)1