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();
}
}
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);
}
}
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.
}
}
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);
}
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());
}
Aggregations