Search in sources :

Example 1 with CModuleViewGenerator

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

the class ViewTest method setUp.

@SuppressWarnings("deprecation")
@Before
public void setUp() throws LoadCancelledException, com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException, FileReadException, CouldntLoadDataException {
    ConfigManager.instance().read();
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final CTagManager internalTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, m_provider))), TagType.VIEW_TAG, m_provider);
    m_viewTagManager = new TagManager(internalTagManager);
    final Database database = new Database(new MockDatabase());
    internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, m_provider);
    internalModule.load();
    module = new Module(database, internalModule, tagManager, m_viewTagManager);
    final Calendar cal = Calendar.getInstance();
    cal.setTime(module.getModificationDate());
    cal.add(Calendar.DATE, 1);
    m_modificationDate = cal.getTime();
    m_creationDate = new Date();
    final ITreeNode<CTag> tag = internalTagManager.addTag(internalTagManager.getRootTag(), "foo");
    final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, internalModule);
    final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, m_creationDate, m_modificationDate, 1, 2, Sets.newHashSet(tag.getObject()), new HashSet<CTag>(), false);
    m_view = new View(module, internalView, tagManager, m_viewTagManager);
}
Also used : CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) Calendar(java.util.Calendar) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) 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) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) 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) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) 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) Before(org.junit.Before)

Example 2 with CModuleViewGenerator

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

the class CViewContainer method createView.

/**
   * Creates a new empty view in the module.
   *
   * @param name The name of the new view.
   * @param description The description of the new view.
   *
   * @return The new view.
   */
public CView createView(final String name, final String description) {
    Preconditions.checkNotNull(name, "IE00164: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00165: Name description can not be null");
    final Date date = new Date();
    final CModuleViewGenerator generator = new CModuleViewGenerator(m_provider, m_module);
    final CView view = generator.generate(-1, name, description, ViewType.NonNative, GraphType.MIXED_GRAPH, date, date, 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    try {
        view.load();
    } catch (CouldntLoadDataException | CPartialLoadException | LoadCancelledException e) {
        CUtilityFunctions.logException(e);
    }
    addView(view);
    return view;
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) Date(java.util.Date)

Example 3 with CModuleViewGenerator

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

the class GroupNodeTest method testElements.

@Test
public void testElements() throws CouldntLoadDataException, PartialLoadException {
    final Database database = new Database(new MockDatabase());
    final SQLProvider mockProvider = new MockSqlProvider();
    final CModule mockModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final INaviView mockView = generator.generate(1, "", "", ViewType.NonNative, GraphType.FLOWGRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    view.load();
    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, mockProvider);
    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, mockProvider);
    final CodeNode codeNode = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
    final CodeNode codeNode2 = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
    final GroupNode node = view.createGroupNode("", Lists.newArrayList((ViewNode) codeNode2));
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    final MockViewNodeListener listener2 = new MockViewNodeListener();
    node.addListener(listener);
    codeNode.addListener(listener2);
    node.addNode(codeNode);
    assertEquals(2, node.getElements().size());
    assertEquals(codeNode, node.getElements().get(1));
    assertEquals(node, codeNode.getParentGroup());
    assertEquals("addedElement;", listener.events);
    assertEquals("changedParentGroup;", listener2.events);
    node.removeNode(codeNode);
    assertEquals(1, node.getElements().size());
    assertEquals(null, codeNode.getParentGroup());
    assertEquals("addedElement;removedElement;", listener.events);
    assertEquals("changedParentGroup;changedParentGroup;", listener2.events);
    node.removeListener(listener);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) 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) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 4 with CModuleViewGenerator

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

the class PostgreSQLViewsLoader method processQueryResults.

/**
   * Processes the results of a view loading query.
   * 
   * @param resultSet Contains the results of the SQL query.
   * @param module The module the views were loaded for.
   * @param tags Map that contains the tags the views are tagged with.
   * @param nodeTagManager Provides the node tags.
   * @param provider The connection to the database.
   * @param views The loaded views are stored in this list.
   * @param viewType View type of the loaded views.
   * @param graphType Graph type of the loaded views.
   * 
   * @return The loaded views.
   * 
   * @throws SQLException Thrown if the views could not be loaded.
   */
protected static final List<CView> processQueryResults(final ResultSet resultSet, final INaviModule module, final Map<Integer, Set<CTag>> tags, final ITagManager nodeTagManager, final SQLProvider provider, final List<CView> views, final ViewType viewType, final GraphType graphType) throws SQLException {
    final Map<Integer, Set<CTag>> nodeTagMap = getNodeTags(provider.getConnection(), module, nodeTagManager);
    try {
        while (resultSet.next()) {
            final int viewId = resultSet.getInt("view_id");
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            final boolean starState = resultSet.getBoolean("stared");
            final int nodeCount = resultSet.getInt("bbcount");
            final int edgeCount = resultSet.getInt("edgecount");
            final Set<CTag> viewTags = tags.containsKey(viewId) ? tags.get(viewId) : new HashSet<CTag>();
            final Set<CTag> nodeTags = nodeTagMap.containsKey(viewId) ? nodeTagMap.get(viewId) : new HashSet<CTag>();
            final CModuleViewGenerator generator = new CModuleViewGenerator(provider, module);
            views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
        }
        return views;
    } finally {
        resultSet.close();
    }
}
Also used : CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) Timestamp(java.sql.Timestamp)

Example 5 with CModuleViewGenerator

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

the class PostgreSQLViewCreator method createView.

/**
   * Creates a new view by copying an existing view.
   * 
   * @param provider The connection to the database.
   * @param module The module the view is added to.
   * @param view The view to be copied.
   * @param name The name of the new view.
   * @param description The description of the new view.
   * @return The new view.
   * @throws CouldntSaveDataException Thrown if the view could not be saved.
   */
public static CView createView(final AbstractSQLProvider provider, final INaviModule module, final INaviView view, final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(provider, "IE02268: Provider argument can not be null");
    Preconditions.checkNotNull(module, "IE02269: Module argument can not be null");
    Preconditions.checkNotNull(view, "IE02270: View argument can not be null");
    Preconditions.checkNotNull(name, "IE02271: Name argument can not be null");
    Preconditions.checkState(module.inSameDatabase(provider), "Error: Module is not part of this database");
    Preconditions.checkState(view.inSameDatabase(provider), "Error: View is not part of this database");
    return createView(provider, module.getConfiguration().getId(), view, name, description, "" + CTableNames.MODULES_TABLE + "", "" + CTableNames.MODULE_VIEWS_TABLE + "", new CModuleViewGenerator(provider, module));
}
Also used : CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator)

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