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");
}
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");
}
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);
}
}
Aggregations