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