Search in sources :

Example 6 with ITreeNode

use of com.google.security.zynamics.zylib.types.trees.ITreeNode in project binnavi by google.

the class ViewNodeTest method setUp.

@Before
public void setUp() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final MockSqlProvider provider = new MockSqlProvider();
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final CTagManager mockTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Root", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider);
    m_nodeTagManager = new TagManager(mockTagManager);
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final Function function = new Function(ModuleFactory.get(), parentFunction);
    final Module module = new Module(database, internalModule, m_nodeTagManager, viewTagManager) {

        @Override
        public Function getFunction(final INaviFunction internalFunction) {
            return function;
        }

        @Override
        public boolean isLoaded() {
            return true;
        }
    };
    final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "", "", "", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final ITreeNode<CTag> tag = mockTagManager.addTag(mockTagManager.getRootTag(), "Initial Tag");
    m_initialTag = m_nodeTagManager.getRootTags().get(0);
    final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
    final CFunctionNode node = internalView.getContent().createFunctionNode(internalFunction);
    node.setColor(Color.MAGENTA);
    node.setX(10);
    node.setY(20);
    node.tagNode(tag.getObject());
    m_view = module.getViews().get(2);
    m_node = (FunctionNode) m_view.getGraph().getNodes().get(0);
    final CFunctionNode node2 = internalView.getContent().createFunctionNode(internalFunction);
    internalView.getContent().createEdge(node, node2, EdgeType.INTER_MODULE);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 7 with ITreeNode

use of com.google.security.zynamics.zylib.types.trees.ITreeNode in project binnavi by google.

the class CTagManagerTest method testTags.

@Test
public void testTags() throws CouldntSaveDataException, CouldntDeleteException {
    final MockSqlProvider sql = new MockSqlProvider();
    final CTagManager manager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, sql))), TagType.VIEW_TAG, sql);
    final MockTagManagerListener listener = new MockTagManagerListener();
    // ----------------------------------------- ADDING TAGS ---------------------------------------
    manager.addListener(listener);
    try {
        manager.addTag(null, "Tag I");
        fail();
    } catch (final NullPointerException exception) {
    }
    assertEquals("", listener.eventList);
    try {
        manager.addTag(manager.getRootTag(), null);
        fail();
    } catch (final NullPointerException exception) {
    }
    assertEquals("", listener.eventList);
    final ITreeNode<CTag> tag1 = manager.addTag(manager.getRootTag(), "Tag I");
    // Check listener events
    assertEquals("addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    final ITreeNode<CTag> tag2 = manager.addTag(manager.getRootTag(), "Tag II");
    // Check listener events
    assertEquals("addedTag/addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    final ITreeNode<CTag> tag3 = manager.addTag(tag2, "Tag III");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    try {
        manager.insertTag(null, "Foo");
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.insertTag(manager.getRootTag(), null);
        fail();
    } catch (final NullPointerException exception) {
    }
    final ITreeNode<CTag> tag4 = manager.insertTag(manager.getRootTag(), "Tag IV");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    final ITreeNode<CTag> tag5 = manager.insertTag(tag3, "Tag V");
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertEquals(tag3, tag5.getParent());
    assertTrue(tag3.getChildren().contains(tag5));
    try {
        manager.deleteTag(null);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.deleteTag(manager.getRootTag());
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    manager.deleteTag(tag5);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag5.getParent());
    assertFalse(tag3.getChildren().contains(tag5));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 5));
    manager.deleteTag(tag4);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(manager.getRootTag(), tag1.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag1));
    assertEquals(manager.getRootTag(), tag2.getParent());
    assertTrue(manager.getRootTag().getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag4.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag4));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 4));
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Test(org.junit.Test)

Example 8 with ITreeNode

use of com.google.security.zynamics.zylib.types.trees.ITreeNode in project binnavi by google.

the class CTagManagerTest method testTags2.

@Test
public void testTags2() throws CouldntSaveDataException, CouldntDeleteException {
    final MockSqlProvider sql = new MockSqlProvider();
    final CTagManager manager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Foo", "Bar", TagType.VIEW_TAG, sql))), TagType.VIEW_TAG, sql);
    final MockTagManagerListener listener = new MockTagManagerListener();
    manager.addListener(listener);
    // ----------------------------------------- ADDING TAGS ---------------------------------------
    final ITreeNode<CTag> tag1 = manager.addTag(manager.getRootTag(), "Tag I");
    final ITreeNode<CTag> tag2 = manager.addTag(manager.getRootTag(), "Tag II");
    final ITreeNode<CTag> tag3 = manager.addTag(tag2, "Tag III");
    // ------------------------------------------- INSERT TAGS
    // ---------------------------------------------------
    final ITreeNode<CTag> tag4 = manager.insertTag(manager.getRootTag(), "Tag IV");
    final ITreeNode<CTag> tag5 = manager.insertTag(tag3, "Tag V");
    try {
        manager.deleteTagSubTree(null);
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        manager.deleteTagSubTree(manager.getRootTag());
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    manager.deleteTagSubTree(tag5);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/", listener.eventList);
    // Check tag
    assertEquals(4, DepthFirstSorter.getSortedList(manager.getRootTag()).size());
    assertEquals(tag4, tag1.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag1));
    assertTrue(tag4.getChildren().contains(tag1));
    assertEquals(tag4, tag2.getParent());
    assertFalse(manager.getRootTag().getChildren().contains(tag2));
    assertTrue(tag4.getChildren().contains(tag2));
    assertEquals(tag2, tag3.getParent());
    assertTrue(tag2.getChildren().contains(tag3));
    assertNull(tag5.getParent());
    assertFalse(tag3.getChildren().contains(tag5));
    assertNull(CTagHelpers.findTag(manager.getRootTag(), 5));
    manager.deleteTagSubTree(tag4);
    // Check listener events
    assertEquals("addedTag/addedTag/addedTag/insertedTag/insertedTag/deletedTag/deletedSubtree/", listener.eventList);
    // Check tag
    assertEquals(0, DepthFirstSorter.getSortedList(manager.getRootTag()).size());
}
Also used : MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) Test(org.junit.Test)

Example 9 with ITreeNode

use of com.google.security.zynamics.zylib.types.trees.ITreeNode in project binnavi by google.

the class MockTagManager method addTag.

@Override
public ITreeNode<CTag> addTag(final ITreeNode<CTag> parent, final String name) {
    final TreeNode<CTag> node = new TreeNode<CTag>(new CTag(1, name, "", m_type, new MockSqlProvider()));
    parent.addChild(node);
    node.setParent(parent);
    return node;
}
Also used : TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 10 with ITreeNode

use of com.google.security.zynamics.zylib.types.trees.ITreeNode in project binnavi by google.

the class CTagNode method createChildren.

@Override
protected void createChildren() {
    if (m_database.isLoaded()) {
        final List<ITreeNode<CTag>> children = m_tag.getChildren();
        Collections.sort(children, new TagComparator());
        for (final ITreeNode<CTag> tag : children) {
            add(new CTagNode(getProjectTree(), m_database, (TreeNode<CTag>) tag));
        }
    }
}
Also used : ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CProjectTreeNode(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.CProjectTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) TagComparator(com.google.security.zynamics.binnavi.Tagging.TagComparator)

Aggregations

CTag (com.google.security.zynamics.binnavi.Tagging.CTag)10 ITreeNode (com.google.security.zynamics.zylib.types.trees.ITreeNode)10 TreeNode (com.google.security.zynamics.zylib.types.trees.TreeNode)10 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)7 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 Before (org.junit.Before)4 TagManager (com.google.security.zynamics.binnavi.API.disassembly.TagManager)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)3 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)3 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)3 Tree (com.google.security.zynamics.zylib.types.trees.Tree)3 Date (java.util.Date)3 Database (com.google.security.zynamics.binnavi.API.disassembly.Database)2 Module (com.google.security.zynamics.binnavi.API.disassembly.Module)2 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)2 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)2 CProjectTreeNode (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.CProjectTreeNode)2 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)2 TagComparator (com.google.security.zynamics.binnavi.Tagging.TagComparator)2