Search in sources :

Example 1 with MutableDirectedGraph

use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.

the class CGraphInliner method inlineAll.

/**
   * Inlines all function calls of a given graph.
   * 
   * @param parent Parent window used for dialogs.
   * @param container Contains the functions to be inlined.
   * @param graph Graph where the inline operation takes place.
   */
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
    Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
    Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
    Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
    final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
    final List<INaviViewNode> nodes = mutableGraph.getNodes();
    final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
    for (final INaviViewNode iNaviViewNode : nodes) {
        if (iNaviViewNode instanceof INaviCodeNode) {
            instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
        }
    }
    for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
        INaviCodeNode updatedNode = null;
        for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
            final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
            if (codeNode.hasInstruction(iNaviInstruction)) {
                updatedNode = codeNode;
            }
        }
        if (updatedNode != null) {
            inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
        } else {
            throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) HashMap(java.util.HashMap) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 2 with MutableDirectedGraph

use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.

the class PostgreSQLViewLoader method loadView.

/**
   * Loads the graph of a view from the database.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param view The view to load.
   * @param list A list of all modules that are part of the database.
   * @param nodeTagManager Node tag manager of the database.
   * 
   * @return The graph of the view.
   * 
   * @throws CouldntLoadDataException Thrown if the graph of view could not be loaded.
   * @throws CPartialLoadException Thrown if the graph could not be loaded because not all required
   *         modules are loaded.
   */
public static MutableDirectedGraph<INaviViewNode, INaviEdge> loadView(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> list, final CTagManager nodeTagManager) throws CouldntLoadDataException, CPartialLoadException {
    checkArguments(provider, view, list, nodeTagManager);
    try {
        final List<INaviViewNode> nodes = PostgreSQLNodeLoader.loadNodes(provider, view, list, nodeTagManager);
        NodeCache.get(provider).addNodes(nodes);
        final List<INaviEdge> edges = PostgreSQLEdgeLoader.loadEdges(provider, view, nodes);
        EdgeCache.get(provider).addEdges(edges);
        return new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph)

Example 3 with MutableDirectedGraph

use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.

the class CViewTest method testConstructor16.

@Test
public void testConstructor16() {
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(new ArrayList<INaviViewNode>(), new ArrayList<INaviEdge>());
    final Set<CTag> tags = new HashSet<CTag>();
    final MockSqlProvider provider = new MockSqlProvider();
    final MockModule module = new MockModule();
    final CView view = new CView(2, module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
    assertEquals(2, view.getConfiguration().getId());
    assertEquals("View", view.getName());
    assertEquals("Description", view.getConfiguration().getDescription());
    assertEquals(ViewType.Native, view.getType());
    assertEquals(0, view.getNodeCount());
    assertEquals(0, view.getEdgeCount());
    try {
        new CView(-2, module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), (CModule) null, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, null, "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "Description", null, ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", null, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, null, new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), null, graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), null, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), graph, null, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    try {
        new CView(new BigInteger(31, random).intValue(), module, "stuuf", "Description", ViewType.Native, new Date(12345), new Date(12345), graph, tags, false, null);
        fail();
    } catch (final NullPointerException e) {
    }
    final CTag tag1 = new CTag(1, "Tag1", "Tag1 Tag1", TagType.VIEW_TAG, provider);
    final CTag tag2 = new CTag(2, "Tag2", "Tag2 Tag2", TagType.VIEW_TAG, provider);
    final CTag tag3 = new CTag(3, "Tag3", "Tag3 Tag3", TagType.VIEW_TAG, provider);
    final CTag tag4 = new CTag(4, "Tag4", "Tag4 Tag4", TagType.VIEW_TAG, provider);
    tags.add(tag1);
    tags.add(tag2);
    tags.add(tag3);
    tags.add(tag4);
    new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
    tags.add(null);
    try {
        new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final NullPointerException e) {
    }
    tags.clear();
    tags.add(tag1);
    tags.add(tag2);
    tags.add(tag3);
    tags.add(tag4);
    final CTag tag5 = new CTag(5, "Tag1", "Tag1 Tag1", TagType.NODE_TAG, provider);
    tags.add(tag5);
    try {
        new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final IllegalArgumentException e) {
    }
    tags.clear();
    final CTag tagWrongDB = new CTag(new BigInteger(31, random).intValue(), "Tag4", "Tag4 Tag4", TagType.VIEW_TAG, new MockSqlProvider());
    tags.add(tagWrongDB);
    try {
        new CView(new BigInteger(31, random).intValue(), module, "View", "Description", ViewType.Native, new Date(1234), new Date(12345), graph, tags, false, provider);
        fail();
    } catch (final IllegalArgumentException e) {
    }
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) BigInteger(java.math.BigInteger) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with MutableDirectedGraph

use of com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph in project binnavi by google.

the class ViewTest method testGraph.

@Test
public void testGraph() {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    final int viewId = new BigInteger(31, new SecureRandom()).intValue();
    final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
    final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
    final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
    final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
    @SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
    @SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
    internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final MockViewListener listener = new MockViewListener();
    final View view = new View(module, internalView, tagManager, m_viewTagManager);
    view.addListener(listener);
    assertEquals(4, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
    assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
Also used : ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) SecureRandom(java.security.SecureRandom) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) Test(org.junit.Test)

Aggregations

MutableDirectedGraph (com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph)4 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)2 BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)1 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)1 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)1 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)1 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)1 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)1 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)1 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)1 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)1 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)1