Search in sources :

Example 26 with INaviInstruction

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));
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) ArrayList(java.util.ArrayList) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 27 with INaviInstruction

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);
}
Also used : CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) ArrayList(java.util.ArrayList) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 28 with INaviInstruction

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);
}
Also used : ReilGraph(com.google.security.zynamics.reil.ReilGraph) ReilTranslator(com.google.security.zynamics.reil.translators.ReilTranslator) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment)

Example 29 with INaviInstruction

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);
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) ReilEdge(com.google.security.zynamics.reil.ReilEdge) ReilBlock(com.google.security.zynamics.reil.ReilBlock) ReilTranslator(com.google.security.zynamics.reil.translators.ReilTranslator) HashSet(java.util.HashSet) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 30 with INaviInstruction

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;
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) HashMap(java.util.HashMap) ReilEdge(com.google.security.zynamics.reil.ReilEdge) ReilBlock(com.google.security.zynamics.reil.ReilBlock) ArrayList(java.util.ArrayList) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) 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