Search in sources :

Example 6 with CModuleViewGenerator

use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 7 with CModuleViewGenerator

use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.

the class CViewTest method testLifeCycle.

@Test
public void testLifeCycle() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
    final MockSqlProvider sql = new MockSqlProvider();
    final Set<CTag> tags = new HashSet<CTag>();
    tags.add(new CTag(1, "", "", TagType.VIEW_TAG, sql));
    final CModuleViewGenerator generator = new CModuleViewGenerator(sql, m_module);
    final CView view = generator.generate(1, "New View", "New View Description", ViewType.Native, GraphType.FLOWGRAPH, new Date(), new Date(), 33, 44, tags, new HashSet<CTag>(), false);
    final MockViewListener listener = new MockViewListener();
    view.addListener(listener);
    view.load();
    listener.m_closing = false;
    view.close();
    assertTrue(view.isLoaded());
    listener.m_closing = true;
    view.close();
    assertFalse(view.isLoaded());
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with CModuleViewGenerator

use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.

the class ViewGraphHelpersTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, PartialLoadException {
    final MockSqlProvider provider = new MockSqlProvider();
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final Module module = new Module(database, internalModule, tagManager, viewTagManager);
    final CModuleViewGenerator generator = new CModuleViewGenerator(provider, internalModule);
    final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 1, 2, new HashSet<CTag>(), new HashSet<CTag>(), false);
    m_view = new View(module, internalView, tagManager, viewTagManager);
    m_view.load();
    final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x125), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    final INaviCodeNode codeNode = internalView.getContent().createCodeNode(null, instructions);
    final List<INaviViewNode> nodes1 = new ArrayList<INaviViewNode>();
    nodes1.add(codeNode);
    final List<INaviEdge> edges1 = new ArrayList<INaviEdge>();
    final CFunction internalFunction = new CFunction(internalModule, new MockView(nodes1, edges1, provider), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    internalFunction.load();
    final Function function = new Function(module, internalFunction);
    final CFunctionNode functionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), provider);
    m_codeNode = new CodeNode(m_view, codeNode, tagManager);
    m_functionNode = new FunctionNode(m_view, functionNode, function, tagManager);
    m_textNode = new TextNode(m_view, new MockTextNode(), tagManager);
    final List<ViewNode> nodes = Lists.newArrayList(m_codeNode, m_functionNode, m_textNode);
    final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
    m_graph = new ViewGraph(nodes, edges);
}
Also used : MockEdge(com.google.security.zynamics.binnavi.disassembly.MockEdge) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) 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) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Before(org.junit.Before)

Example 9 with CModuleViewGenerator

use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.

the class ViewGraphTest method testConstructor.

@Test
public void testConstructor() throws CouldntLoadDataException, LoadCancelledException {
    final MockSqlProvider provider = new MockSqlProvider();
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final Module module = new Module(database, internalModule, tagManager, viewTagManager);
    final CModuleViewGenerator generator = new CModuleViewGenerator(provider, internalModule);
    final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 1, 2, new HashSet<CTag>(), new HashSet<CTag>(), false);
    final View view = new View(module, internalView, tagManager, viewTagManager);
    final List<ViewNode> nodes = Lists.newArrayList((ViewNode) new TextNode(view, new MockTextNode(), tagManager));
    final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
    final ViewGraph graph = new ViewGraph(nodes, edges);
    assertEquals(1, graph.getNodes().size());
    assertEquals(nodes.get(0), graph.getNodes().get(0));
    assertEquals(1, graph.getEdges().size());
    assertEquals(edges.get(0), graph.getEdges().get(0));
    assertEquals("View Graph [1 nodes, 1 edges]", graph.toString());
}
Also used : MockEdge(com.google.security.zynamics.binnavi.disassembly.MockEdge) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Date(java.util.Date) 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) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 10 with CModuleViewGenerator

use of com.google.security.zynamics.binnavi.Database.CModuleViewGenerator in project binnavi by google.

the class PostgreSQLViewNotificationParser method informModuleNotification.

/**
   * The inform function for notifications from the bn_module_views table. This function is used
   * when a module view is created or deleted.
   *
   * @param moduleViewNotificationContainer The {@link ViewNotificationContainer} to use as data
   *        source.
   * @param provider The {@link SQLProvider} to access the database.
   * @throws CouldntLoadDataException if the information could not be loaded from the database.
   */
private void informModuleNotification(final ViewNotificationContainer moduleViewNotificationContainer, final SQLProvider provider) throws CouldntLoadDataException {
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("INSERT")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final ImmutableNaviViewConfiguration databaseViewConfiguration = provider.loadFlowGraphInformation(module, viewId);
        final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
        final INaviView view = generator.generate(databaseViewConfiguration, GraphType.FLOWGRAPH);
        module.getContent().getViewContainer().addView(view);
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("UPDATE")) {
        // updates will not happen as this is only a mapping of id to id.
        return;
    }
    if (moduleViewNotificationContainer.getDatabaseOperation().equals("DELETE")) {
        final INaviModule module = moduleViewNotificationContainer.getNotificationModule().get();
        if (!module.isLoaded()) {
            return;
        }
        final Integer viewId = moduleViewNotificationContainer.getViewId();
        final INaviView view = ViewManager.get(provider).getView(viewId);
        module.getContent().getViewContainer().deleteViewInternal(view);
    }
}
Also used : ImmutableNaviViewConfiguration(com.google.security.zynamics.binnavi.disassembly.views.ImmutableNaviViewConfiguration) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule)

Aggregations

CModuleViewGenerator (com.google.security.zynamics.binnavi.Database.CModuleViewGenerator)10 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)8 Date (java.util.Date)7 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)4 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)4 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)4 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 Test (org.junit.Test)4 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)3 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)3 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)2 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)2 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)2 MockEdge (com.google.security.zynamics.binnavi.disassembly.MockEdge)2 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)2