Search in sources :

Example 1 with CNaviViewEdge

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

the class CViewContent method createEdge.

@Override
public CNaviViewEdge createEdge(final INaviViewNode source, final INaviViewNode target, final EdgeType edgeType) {
    Preconditions.checkNotNull(source, "IE00290: Source argument can not be null");
    Preconditions.checkNotNull(target, "IE00291: Target argument can not be null");
    Preconditions.checkNotNull(edgeType, "IE00292: Edge type argument can not be null");
    Preconditions.checkArgument(source.inSameDatabase(provider), "IE00187: Source node is not in the same database");
    Preconditions.checkArgument(target.inSameDatabase(provider), "IE00189: Target node is not in the same database");
    final CNaviViewEdge edge = new CNaviViewEdge(-1, source, target, edgeType, 0, 0, 0, 0, Color.BLACK, false, true, null, new ArrayList<CBend>(), provider);
    source.addOutgoingEdge(edge);
    target.addIncomingEdge(edge);
    edge.addListener(m_internalEdgeListener);
    graph.addEdge(edge);
    for (final INaviViewListener listener : listeners) {
        try {
            listener.addedEdge(view, edge);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return edge;
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) InternalTranslationException(com.google.security.zynamics.reil.translators.InternalTranslationException)

Example 2 with CNaviViewEdge

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

the class CViewInserter method createEdges.

/**
   * Clones the edges of the source view and inserts them into the target view.
   *
   * @param target The target view where the cloned edges are inserted.
   * @param edges The source edges that are cloned.
   * @param nodeMap Maps between the source nodes and their cloned counterparts.
   */
private static void createEdges(final INaviView target, final List<INaviEdge> edges, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    for (final INaviEdge edge : edges) {
        final INaviViewNode sourceNode = nodeMap.get(edge.getSource());
        final INaviViewNode targetNode = nodeMap.get(edge.getTarget());
        final CNaviViewEdge newEdge = target.getContent().createEdge(sourceNode, targetNode, edge.getType());
        newEdge.setColor(edge.getColor());
        newEdge.setX1(edge.getX1());
        newEdge.setY1(edge.getY1());
        newEdge.setX2(edge.getX2());
        newEdge.setY2(edge.getY2());
        for (final CBend bend : edge.getBends()) {
            newEdge.addBend(bend.getX(), bend.getY());
        }
    }
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Example 3 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge 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 4 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge 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)

Example 5 with CNaviViewEdge

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

the class CUnInlinerTest method testUninlineSingleBlock.

@Test
public void testUninlineSingleBlock() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x123);
    final MockInstruction mi2 = new MockInstruction(0x124);
    final MockInstruction mi3 = new MockInstruction(0x125);
    final CCodeNode upperNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CTextNode textNode = new CTextNode(0, 0, 0, 0, 0, Color.RED, false, true, new HashSet<CTag>(), null, m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(textNode);
    nodes.add(lowerNode);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(0, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge leavingEdge = new CNaviViewEdge(0, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge textEdge = new CNaviViewEdge(0, textNode, inlinedNode, EdgeType.TEXTNODE_EDGE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(textEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(textNode, inlinedNode, textEdge);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(1, view.getNodeCount());
    assertEquals(0, view.getEdgeCount());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(0);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Aggregations

CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)18 Test (org.junit.Test)11 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)8 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)7 CBend (com.google.security.zynamics.zylib.gui.zygraph.edges.CBend)7 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)5 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)5 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)5 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)4 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)3 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)3 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)3 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)3 ArrayList (java.util.ArrayList)3 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)2