Search in sources :

Example 36 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLProviderTest method testInsertTag.

@Test
public void testInsertTag() throws CouldntLoadDataException, CouldntSaveDataException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    final CTag newTag = getProvider().insertTag(tagManager.getRootTag(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    assertEquals("Tag Name", newTag.getName());
    assertEquals("Tag Description", newTag.getDescription());
    assertEquals(TagType.VIEW_TAG, newTag.getType());
    getProvider().createTag(newTag, "Tag Name", "Tag Description", TagType.VIEW_TAG);
    // Create more tags for the delete test later
    getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    final CTag tag4 = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    getProvider().createTag(tag4, "Tag Name", "Tag Description", TagType.VIEW_TAG);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 37 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLProviderTest method testSetDescription1.

@Test
public void testSetDescription1() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final INaviProject project = getProvider().loadProjects().get(0);
    final CAddressSpace addressSpace = getProvider().createAddressSpace(project, "SOME_OTHER_ADDRESS_SPACE");
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    final CFunction function = (CFunction) module.getContent().getFunctionContainer().getFunctions().get(0);
    final CView view = (CView) module.getContent().getViewContainer().getViews().get(0);
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    final ITreeNode<CTag> tag = tagManager.getRootTag().getChildren().get(0);
    getProvider().setDescription(addressSpace, "New Description");
    getProvider().setDescription(function, "New Description");
    getProvider().setDescription(module, "New Description");
    getProvider().setDescription(project, "New Description");
    getProvider().setDescription(tag.getObject(), "New Description");
    getProvider().setDescription(module.getContent().getTraceContainer().getTraces().get(0), "New Description");
    getProvider().setDescription(view, "New Description");
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 38 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLProviderTestSetup method testCreateTag.

@Test
public void testCreateTag() throws CouldntSaveDataException, CouldntLoadDataException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    final CTag newTag = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    assertEquals("Tag Name", newTag.getName());
    assertEquals("Tag Description", newTag.getDescription());
    assertEquals(TagType.VIEW_TAG, newTag.getType());
    getProvider().createTag(newTag, "Tag Name", "Tag Description", TagType.VIEW_TAG);
    // Create more tags for the delete test later
    getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    final CTag tag4 = getProvider().createTag(tagManager.getRootTag().getObject(), "Tag Name", "Tag Description", TagType.VIEW_TAG);
    getProvider().createTag(tag4, "Tag Name", "Tag Description", TagType.VIEW_TAG);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 39 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLViewCreator method createView.

/**
   * Inserts a new view in the database by copying an existing view.
   * 
   * @param provider The connection to the database.
   * @param containerId The ID of the container where the view is created.
   * @param view The view to be copied.
   * @param name The name of the new view.
   * @param description The description of the new view.
   * @param containerTable Name of the view container table.
   * @param viewContainerTable Name of the view container views table.
   * @param generator Generates the view.
   * @return The created view.
   * @throws CouldntSaveDataException Thrown if the view could not be created.
   */
private static CView createView(final AbstractSQLProvider provider, final int containerId, final INaviView view, final String name, final String description, final String containerTable, final String viewContainerTable, final ViewGenerator generator) throws CouldntSaveDataException {
    final CConnection connection = provider.getConnection();
    try {
        PostgreSQLHelpers.beginTransaction(connection);
        final int viewId = insertView(connection, name, description);
        // Mark the view as a module view
        connection.executeUpdate("INSERT INTO " + viewContainerTable + " VALUES(" + containerId + ", " + viewId + ")", true);
        final List<INaviViewNode> nodes = view.getGraph().getNodes();
        final List<INaviEdge> edges = view.getGraph().getEdges();
        // Store all nodes
        PostgreSQLNodeSaver.writeNodes(provider, viewId, nodes);
        // Store all edges
        PostgreSQLEdgeSaver.writeEdges(provider, edges);
        PostgreSQLHelpers.endTransaction(connection);
        final String query = "SELECT creation_date, modification_date FROM " + CTableNames.VIEWS_TABLE + " WHERE id = " + viewId;
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final Timestamp creationDate = resultSet.getTimestamp("creation_date");
                final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
                PostgreSQLHelpers.updateModificationDate(connection, containerTable, containerId);
                return generator.generate(viewId, name, description, ViewType.NonNative, view.getGraphType(), creationDate, modificationDate, view.getNodeCount(), view.getEdgeCount(), new HashSet<CTag>(), new HashSet<CTag>(), false);
            }
            throw new CouldntSaveDataException("Error: Couldnt't load the created view");
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        CUtilityFunctions.logException(exception);
        try {
            PostgreSQLHelpers.rollback(connection);
        } catch (final SQLException e) {
            CUtilityFunctions.logException(e);
        }
        throw new CouldntSaveDataException(exception);
    }
}
Also used : SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Timestamp(java.sql.Timestamp) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 40 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class TagManager method clone.

/**
   * Converts an internal tag tree into an API tag tree.
   * 
   * @param currentNode The internal tag tree node to convert.
   * @param parentExpression Parent of the converted API tag tree node.
   * 
   * @return The converted API tag tree node.
   */
private Tag clone(final ITreeNode<CTag> currentNode, final Tag parentExpression) {
    final Tag childExpression = new Tag(currentNode);
    m_allTags.put(currentNode, childExpression);
    if (parentExpression != null) {
        Tag.link(parentExpression, childExpression);
    }
    for (final ITreeNode<CTag> child : currentNode.getChildren()) {
        clone(child, childExpression);
    }
    return childExpression;
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Aggregations

CTag (com.google.security.zynamics.binnavi.Tagging.CTag)113 Test (org.junit.Test)55 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)42 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)35 Date (java.util.Date)28 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)24 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)21 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)20 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)18 ArrayList (java.util.ArrayList)17 Tree (com.google.security.zynamics.zylib.types.trees.Tree)15 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)14 TreeNode (com.google.security.zynamics.zylib.types.trees.TreeNode)14 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)13 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)13 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)13 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12