Search in sources :

Example 41 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag 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 project The project 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 INaviProject project, 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(), project, 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 CProjectViewGenerator generator = new CProjectViewGenerator(provider, project);
            views.add(generator.generate(viewId, name, description, viewType, graphType, creationDate, modificationDate, nodeCount, edgeCount, viewTags, nodeTags, starState));
        }
        return views;
    } finally {
        resultSet.close();
    }
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CProjectViewGenerator(com.google.security.zynamics.binnavi.Database.CProjectViewGenerator) Timestamp(java.sql.Timestamp)

Example 42 with CTag

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

the class PostgreSQLNodeSaver method saveTags.

/**
   *
   * TODO (timkornau): this code here has serious issues and is in no way anything that we want to
   * keep.
   *
   * Saves the node tags to the database.
   *
   * @param connection The connection to the database.
   * @param nodes The nodes to save.
   * @param firstNode Database index of the first node.
   *
   * @throws SQLException Thrown if saving the tags failed.
   */
protected static void saveTags(final CConnection connection, final List<INaviViewNode> nodes, final int firstNode) throws SQLException {
    int counter = firstNode;
    final String deleteStatement = "DELETE FROM " + CTableNames.TAGGED_NODES_TABLE + " WHERE node_id IN (%s)";
    final String insertStatement = "INSERT INTO " + CTableNames.TAGGED_NODES_TABLE + " VALUES %s ";
    boolean isFirst = true;
    final StringBuilder range = new StringBuilder();
    for (int i = 0; i < nodes.size(); i++) {
        if (isFirst) {
            range.append(counter);
            isFirst = false;
            continue;
        }
        range.append(", ");
        range.append(counter);
        ++counter;
    }
    if (range.length() != 0) {
        connection.executeUpdate(String.format(deleteStatement, range.toString()), true);
    }
    counter = firstNode;
    final StringBuilder insert = new StringBuilder();
    isFirst = true;
    for (final INaviViewNode node : nodes) {
        final Iterator<CTag> it = node.getTagsIterator();
        while (it.hasNext()) {
            final CTag tag = it.next();
            insert.append(isFirst ? "" : ",");
            insert.append('(');
            insert.append(counter);
            insert.append(", ");
            insert.append(tag.getId());
            insert.append(')');
            isFirst = false;
        }
        ++counter;
    }
    if (insert.length() != 0) {
        connection.executeUpdate(String.format(insertStatement, insert.toString()), true);
    }
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode)

Example 43 with CTag

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

the class CCodeNodeUpdater method initializeListeners.

/**
   * Initializes the listeners that are responsible for updating the code node.
   */
private void initializeListeners() {
    try {
        codeNode.getParentFunction().addListener(functionUpdater);
        codeNode.getParentFunction().getModule().addListener(moduleUpdater);
    } catch (final MaybeNullException exception) {
    // The code nodes does not have a parent function, therefore the information
    // about the parent function is not shown in the code and does not have to
    // be processed when updating.
    }
    final HashMap<INaviInstruction, INaviFunction> referenceMap = CReferenceFinder.getCodeReferenceMap(codeNode);
    for (final INaviFunction functionReference : Sets.newHashSet(referenceMap.values())) {
        functionReference.addListener(functionUpdater);
    }
    codeNode.addListener(codeNodeListener);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        instruction.addListener(instructionUpdater);
        for (final COperandTree tree : instruction.getOperands()) {
            for (final INaviOperandTreeNode currentNode : tree.getNodes()) {
                currentNode.addListener(operandTreeUpdater);
            }
        }
    }
    final Iterator<CTag> it = codeNode.getTagsIterator();
    while (it.hasNext()) {
        it.next().addListener(tagUpdater);
    }
    for (final IDebugger debugger : provider.getDebuggers()) {
        debugger.getProcessManager().addListener(debuggerUpdater);
    }
    provider.addListener(debuggerProviderListener);
    graph.getSettings().getDisplaySettings().addListener(settingsUpdater);
    try {
        codeNode.getParentFunction().getModule().getTypeManager().addListener(substitutionsUpdater);
    } catch (final MaybeNullException exception) {
    // If the code node doesn't have a a parent function, it is not in the database and therefore
    // cannot receive type substitutions.
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 44 with CTag

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

the class PostgreSQLProviderTest method testPostgreSQLTagFunctionsSetName3.

@Test(expected = NullPointerException.class)
public void testPostgreSQLTagFunctionsSetName3() throws CouldntSaveDataException, CouldntLoadDataException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
    tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
    tagManager.addTag(tagManager.getRootTag().getChildren().get(0), "Node Tag III");
    final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
    PostgreSQLTagFunctions.setName((AbstractSQLProvider) getProvider(), tag1.getObject(), null);
}
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 45 with CTag

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

the class PostgreSQLProviderTest method testCTagFunctionsSetName.

@Test
public void testCTagFunctionsSetName() throws CouldntLoadDataException, CouldntSaveDataException, LoadCancelledException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
    tagManager.addTag(tagManager.getRootTag(), "Node Tag II");
    tagManager.addTag(tagManager.getRootTag().getChildren().get(0), "Node Tag III");
    final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    PostgreSQLTagFunctions.setName((AbstractSQLProvider) getProvider(), tag1.getObject(), "foobar");
    module.close();
    final INaviModule module2 = getProvider().loadModules().get(0);
    module2.load();
    final CTagManager tagManager1 = getProvider().loadTagManager(TagType.VIEW_TAG);
    assertEquals("foobar", tagManager1.getRootTag().getChildren().get(0).getObject().getName());
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) 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)

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