use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class PostgreSQLProviderTest method testInstructionFunctionsCreateInstruction1.
@Test
public void testInstructionFunctionsCreateInstruction1() throws SQLException, CouldntLoadDataException, LoadCancelledException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final String mnemonic = "burzel";
final IAddress iAddress = new CAddress(0x1234);
final COperandTreeNode rootNode = module.createOperandExpression("eax", ExpressionType.REGISTER);
final COperandTree tree = new COperandTree(rootNode, getProvider(), module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final List<COperandTree> operands = new ArrayList<COperandTree>();
operands.add(tree);
final byte[] data = { 0xF };
final String architecture = "x86-32";
final INaviInstruction instruction = module.createInstruction(iAddress, mnemonic, operands, data, architecture);
PostgreSQLInstructionFunctions.createInstructions(getProvider(), Lists.newArrayList(instruction));
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class View method createCodeNode.
// ! Creates a new code node.
/**
* Creates a code node in the view.
*
* @param function The parent function of the code node. This argument is optional can can be
* null.
* @param instructions The instructions that should be displayed in the code node.
*
* @return The created code node.
*/
public CodeNode createCodeNode(final Function function, final List<Instruction> instructions) {
Preconditions.checkNotNull(instructions, "Error: Instructions argument can't be null");
final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
for (final Instruction instruction : instructions) {
Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
instructionsList.add(instruction.getNative());
}
assert !instructions.isEmpty();
final CCodeNode newCodenode = naviView.getContent().createCodeNode(function == null ? null : function.getNative(), instructionsList);
newCodenode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
return (CodeNode) cachedNodes.get(newCodenode);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CReilInstructionDialog method show.
/**
* Shows an instruction dialog.
*
* @param parent Parent window used for dialogs.
* @param instruction The instruction whose REIL code is shown.
*
* @throws InternalTranslationException Thrown if the instruction could not be converted to REIL
* code.
*/
public static void show(final Window parent, final INaviInstruction instruction) throws InternalTranslationException {
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
final ReilGraph reilGraph = translator.translate(new StandardEnvironment(), instruction);
final String text = reilGraphToText(reilGraph);
final String title = String.format("REIL code of '%s'", instruction.toString());
final CReilInstructionDialog dialog = new CReilInstructionDialog(parent, title, text);
GuiHelper.centerChildToParent(parent, dialog, true);
dialog.setVisible(true);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class COperandsDeterminer method getRegisters.
/**
* Returns the registers read and written by a native instruction.
*
* @param instruction The instruction whose accessed registers are returned.
*
* @return The read and written registers of the instruction.
*
* @throws InternalTranslationException Thrown if the instruction could not be translated to REIL.
*/
public static Pair<Set<String>, Set<String>> getRegisters(final INaviInstruction instruction) throws InternalTranslationException {
final Set<String> inSet = new HashSet<String>();
final Set<String> outSet = new HashSet<String>();
final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
final DirectedGraph<ReilBlock, ReilEdge> reilCode = translator.translate(new StandardEnvironment(), instruction);
final boolean translatingReil = instruction.getArchitecture().equals("REIL");
for (final ReilBlock reilBlock : reilCode) {
for (final ReilInstruction reilInstruction : reilBlock) {
if (writesThirdOperand(reilInstruction, translatingReil)) {
outSet.add(reilInstruction.getThirdOperand().getValue());
}
if (!writesThirdOperand(reilInstruction, translatingReil) && isRegister(reilInstruction.getThirdOperand(), translatingReil)) {
// JCC + STM
inSet.add(reilInstruction.getThirdOperand().getValue());
}
if (isRegister(reilInstruction.getFirstOperand(), translatingReil)) {
inSet.add(reilInstruction.getFirstOperand().getValue());
}
if (isRegister(reilInstruction.getSecondOperand(), translatingReil)) {
inSet.add(reilInstruction.getSecondOperand().getValue());
}
}
}
return new Pair<Set<String>, Set<String>>(inSet, outSet);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviInstruction in project binnavi by google.
the class CReilViewCreator method create.
/**
* Creates a REIL view object from a REIL graph.
*
* @param container The container in which the new REIL view is created.
* @param graph The graph that contains the REIL code to be shown in the view.
*
* @return The created REIL code view.
*/
public static INaviView create(final INaviModule container, final ReilGraph graph) {
Preconditions.checkNotNull(container, "IE01809: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE01815: Graph argument can not be null");
final INaviView view = container.getContent().getViewContainer().createView("REIL View", "");
final Map<ReilBlock, CCodeNode> nodeMap = new HashMap<ReilBlock, CCodeNode>();
for (final ReilBlock block : graph) {
final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
for (final ReilInstruction reilInstruction : block) {
final List<COperandTree> operands = new ArrayList<COperandTree>();
if (reilInstruction.getFirstOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getFirstOperand()));
}
if (reilInstruction.getSecondOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getSecondOperand()));
}
if (reilInstruction.getThirdOperand().getType() == OperandType.EMPTY) {
operands.add(getEmptyOperand(container));
} else {
operands.add(convert(container, reilInstruction.getThirdOperand()));
}
final INaviInstruction convertedInstruction = container.createInstruction(reilInstruction.getAddress(), reilInstruction.getMnemonic(), operands, new byte[0], "REIL");
instructions.add(convertedInstruction);
}
final CCodeNode node = view.getContent().createCodeNode(null, instructions);
node.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
nodeMap.put(block, node);
}
for (final ReilEdge edge : graph.getEdges()) {
final CNaviViewEdge reilEdge = view.getContent().createEdge(nodeMap.get(edge.getSource()), nodeMap.get(edge.getTarget()), edge.getType());
EdgeInitializer.adjustColor(reilEdge);
}
return view;
}
Aggregations