Search in sources :

Example 31 with INaviFunction

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

the class PostgreSQLProviderTest method testSave.

@Test
public void testSave() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException, CPartialLoadException, InternalTranslationException, LoadCancelledException, MaybeNullException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.NODE_TAG);
    tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
    tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
    final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
    final ITreeNode<CTag> tag2 = tagManager.getRootTag().getChildren().get(1);
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final CView view = module.getContent().getViewContainer().createView("Save View", "Save View Description");
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction("sub_1002B87");
    function.load();
    final List<COperandTree> operands = new ArrayList<COperandTree>();
    final COperandTreeNode root1 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
    final COperandTreeNode child1 = module.createOperandExpression("eax", ExpressionType.REGISTER);
    COperandTreeNode.link(root1, child1);
    final COperandTreeNode root2 = module.createOperandExpression("dword", ExpressionType.SIZE_PREFIX);
    final COperandTreeNode child2 = module.createOperandExpression("16", ExpressionType.IMMEDIATE_INTEGER);
    COperandTreeNode.link(root2, child2);
    final COperandTree operand1 = module.createOperand(root1);
    final COperandTree operand2 = module.createOperand(root2);
    operands.add(operand1);
    operands.add(operand2);
    final Iterable<INaviInstruction> instructions = function.getBasicBlocks().get(0).getInstructions();
    final Iterable<INaviInstruction> instructions2 = function.getBasicBlocks().get(1).getInstructions();
    final CCodeNode codeNode = view.getContent().createCodeNode(function, Lists.newArrayList(instructions));
    codeNode.tagNode(tag1.getObject());
    codeNode.getComments().appendLocalCodeNodeComment("XXX");
    codeNode.getComments().appendLocalInstructionComment(Iterables.getLast(codeNode.getInstructions()), "YYY");
    Iterables.getLast(codeNode.getInstructions()).appendGlobalComment(" GLOBAL INSTRUCTION COMMENT ");
    @SuppressWarnings("unused") final CCodeNode codeNode2 = view.getContent().createCodeNode(null, Lists.newArrayList(instructions2));
    final CFunctionNode functionNode = view.getContent().createFunctionNode(function);
    functionNode.tagNode(tag2.getObject());
    functionNode.appendLocalFunctionComment("ZZZ");
    @SuppressWarnings("unused") final CNaviViewEdge edge = view.getContent().createEdge(codeNode, functionNode, EdgeType.JUMP_UNCONDITIONAL);
    view.save();
    view.close();
    view.load();
    assertEquals(3, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    assertTrue(view.getGraph().getNodes().get(0).isTagged(tag1.getObject()));
    assertTrue(view.getGraph().getNodes().get(2).isTagged(tag2.getObject()));
    final CCodeNode loadedCodeNode = (CCodeNode) view.getGraph().getNodes().get(0);
    final CCodeNode loadedCodeNode2 = (CCodeNode) view.getGraph().getNodes().get(1);
    assertEquals("XXX", loadedCodeNode.getComments().getLocalCodeNodeComment().get(0).getComment());
    final INaviInstruction customInstruction = Iterables.getLast(loadedCodeNode.getInstructions());
    assertEquals(" GLOBAL INSTRUCTION COMMENT ", customInstruction.getGlobalComment().get(0).getComment());
    assertEquals("YYY", loadedCodeNode.getComments().getLocalInstructionComment(customInstruction).get(0).getComment());
    final ReilTranslator<INaviInstruction> translator = new ReilTranslator<INaviInstruction>();
    translator.translate(new StandardEnvironment(), loadedCodeNode);
    translator.translate(new StandardEnvironment(), loadedCodeNode2);
    final CFunctionNode loadedFunctionNode = (CFunctionNode) view.getGraph().getNodes().get(2);
    assertEquals("ZZZ", loadedFunctionNode.getLocalFunctionComment().get(0).getComment());
    tagManager.deleteTag(tag1);
    tagManager.deleteTag(tag2);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) ReilTranslator(com.google.security.zynamics.reil.translators.ReilTranslator) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) StandardEnvironment(com.google.security.zynamics.reil.translators.StandardEnvironment) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 32 with INaviFunction

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

the class PostgreSQLProviderTest method testFunctionFunctionsResolveFunction1.

@Test
public void testFunctionFunctionsResolveFunction1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final INaviFunction function1 = module.getContent().getFunctionContainer().getFunctions().get(0);
    final INaviFunction function2 = module.getContent().getFunctionContainer().getFunctions().get(1);
    PostgreSQLFunctionFunctions.resolveFunction((AbstractSQLProvider) getProvider(), function1, function2);
    PostgreSQLFunctionFunctions.resolveFunction((AbstractSQLProvider) getProvider(), function1, null);
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 33 with INaviFunction

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

the class PostgreSQLProviderTest method testInstructionFunctionsAddReference6.

@Test(expected = CouldntSaveDataException.class)
public void testInstructionFunctionsAddReference6() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final INaviModule module = getProvider().loadModules().get(1);
    module.load();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(1800);
    function.load();
    final IBlockNode basicBlock = function.getBasicBlocks().get(0);
    final INaviInstruction instruction = Iterables.get(basicBlock.getInstructions(), 1);
    final COperandTree tree = instruction.getOperands().get(0);
    final INaviOperandTreeNode node = tree.getRootNode();
    final IAddress address = instruction.getAddress();
    final ReferenceType type = ReferenceType.DATA;
    PostgreSQLInstructionFunctions.addReference(getProvider(), node, address, type);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) IBlockNode(com.google.security.zynamics.binnavi.disassembly.IBlockNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ReferenceType(com.google.security.zynamics.zylib.disassembly.ReferenceType) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 34 with INaviFunction

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

the class Module method createCallgraph.

/**
   * Creates the native call graph.
   */
private void createCallgraph() {
    final DirectedGraph<ICallgraphNode, ICallgraphEdge> graph = m_module.getContent().getNativeCallgraph();
    final List<FunctionBlock> blocks = new ArrayList<FunctionBlock>();
    final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();
    final HashMap<ICallgraphNode, FunctionBlock> blockMap = new HashMap<ICallgraphNode, FunctionBlock>();
    final HashMap<INaviFunction, Function> functionMap = new HashMap<INaviFunction, Function>();
    for (final Function function : m_functions) {
        functionMap.put(function.getNative(), function);
    }
    for (final ICallgraphNode block : graph.getNodes()) {
        final FunctionBlock newBlock = new FunctionBlock(functionMap.get(block.getFunction()));
        blockMap.put(block, newBlock);
        blocks.add(newBlock);
    }
    for (final ICallgraphEdge edge : graph.getEdges()) {
        final FunctionBlock source = blockMap.get(edge.getSource());
        final FunctionBlock target = blockMap.get(edge.getTarget());
        edges.add(new FunctionEdge(source, target));
    }
    m_callgraph = new Callgraph(blocks, edges);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICallgraphEdge(com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge) ICallgraphNode(com.google.security.zynamics.binnavi.disassembly.ICallgraphNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 35 with INaviFunction

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

the class CCodeNodeParser method createLine.

/**
   * Creates raw instruction data from a code node provider.
   *
   * @param instructionSet Provides the raw data.
   *
   * @return The generated raw data object.
   *
   * @throws ParserException Thrown if not all instruction data could be read.
   */
private InstructionLine createLine(final ICodeNodeProvider instructionSet) throws ParserException {
    final InstructionLine row = new InstructionLine();
    row.setBasicBlock(instructionSet.getNodeId());
    row.setAddress(instructionSet.getInstructionAddress());
    row.setMnemonic(instructionSet.getMnemonic());
    row.setArchitecture(instructionSet.getInstructionArchitecture());
    final int moduleId = instructionSet.getModule();
    final IAddress parentFunction = instructionSet.getParentFunction();
    final INaviModule module = modules.get(moduleId);
    if (module == null) {
        throw new ParserException(String.format("Instruction with ID %d has unknown module with ID %d", row.getId(), moduleId));
    }
    final INaviFunction function = parentFunction == null ? null : module.getContent().getFunctionContainer().getFunction(parentFunction);
    row.setParentFunction(function);
    if ((parentFunction != null) && (function == null)) {
        throw new ParserException(String.format("Instruction with ID %d has unknown parent function with address %s", row.getId(), parentFunction.toHexString()));
    }
    row.setX(instructionSet.getX());
    row.setY(instructionSet.getY());
    row.setColor(new Color(instructionSet.getColor()));
    row.setBorderColor(new Color(instructionSet.getBorderColor()));
    row.setSelected(instructionSet.isSelected());
    row.setVisible(instructionSet.isVisible());
    row.setLocalNodeCommentId(instructionSet.getLocalNodeCommentId());
    row.setGlobalNodeComment(instructionSet.getGlobalNodeCommentId());
    row.setGlobalInstructionComment(instructionSet.getGlobalInstructionCommentId());
    row.setLocalInstructionComment(instructionSet.getLocalInstructionCommentId());
    row.setData(instructionSet.getData());
    row.setModule(module);
    return row;
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Color(java.awt.Color) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Aggregations

INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)94 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)39 Test (org.junit.Test)38 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)26 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)16 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)16 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12 ArrayList (java.util.ArrayList)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)9 HashMap (java.util.HashMap)9 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)8 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)8