Search in sources :

Example 16 with CTag

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

the class PostgreSQLTagFunctions method deleteTagSubtree.

/**
   * Deletes a tag and all of its subtrees.
   * 
   * @param provider The connection to the database.
   * @param tag The root tag of the subtree to delete.
   * 
   * @throws CouldntDeleteException Thrown if the subtree could not be deleted.
   */
public static void deleteTagSubtree(final AbstractSQLProvider provider, final ITreeNode<CTag> tag) throws CouldntDeleteException {
    checkArguments(provider, tag);
    Preconditions.checkNotNull(tag.getParent(), "IE00559: Can not delete the root tag");
    final CConnection connection = provider.getConnection();
    try {
        final StringBuilder query = new StringBuilder(String.format("delete from %s where id = %d", CTableNames.TAGS_TABLE, tag.getObject().getId()));
        final List<Integer> idsToDelete = new ArrayList<>();
        for (final ITreeNode<CTag> child : DepthFirstSorter.getSortedList(tag)) {
            idsToDelete.add(child.getObject().getId());
            query.append(" or id = " + tag.getObject().getId());
        }
        connection.executeUpdate(query.toString(), true);
    } catch (final SQLException e) {
        throw new CouldntDeleteException(e);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 17 with CTag

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

the class CProjectContent method createView.

/**
   * Creates a new empty view with the given name and description in the project. The new view is
   * not stored in the database until INaviView::save is called.
   * 
   * @param name The name of the new view.
   * @param description The description of the new view.
   * 
   * @return The new view that was created in the project.
   */
public INaviView createView(final String name, final String description) {
    final Date date = new Date();
    final CProjectViewGenerator generator = new CProjectViewGenerator(m_provider, m_project);
    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) {
        // This can not happen; new views with ID -1 do not access the database
        // when they are loaded.
        CUtilityFunctions.logException(e);
    }
    addView(view);
    return view;
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) 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) CProjectViewGenerator(com.google.security.zynamics.binnavi.Database.CProjectViewGenerator) Date(java.util.Date)

Example 18 with CTag

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

the class CViewContent method createFunctionNode.

@Override
public CFunctionNode createFunctionNode(final INaviFunction function) {
    Preconditions.checkNotNull(function, "IE00294: Function argument can not be null");
    Preconditions.checkArgument(function.inSameDatabase(provider), "IE00295: Function and view are not in the same database");
    final CFunctionNode functionNode = new CFunctionNode(-1, function, 0, 0, 0, 0, CFunctionNodeColorizer.getFunctionColor(function.getType()), false, true, null, new HashSet<CTag>(), provider);
    addNode(functionNode);
    updateGraphType(functionNode);
    functionNode.addListener(m_internalNodeListener);
    return functionNode;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 19 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag 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 20 with CTag

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

the class TraceLoggerTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, InvalidDatabaseVersionException {
    final SQLProvider mockProvider = new MockSqlProvider();
    // CDatabase("", "", "", "", "", false,
    final IDatabase internalDatabase = new MockDatabase();
    // false);
    final Database database = new Database(internalDatabase);
    database.load();
    final MockProject mockProject = new MockProject();
    final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
    final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
    final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
    final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
    final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
    final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final Project project = new Project(database, mockProject, nodeTagManager, viewTagManager);
    m_mockModule = new Module(database, mockModule, viewTagManager, nodeTagManager);
    m_debugSettings = new ModuleTargetSettings(m_mockModule.getNative());
    m_mockDebugger = new MockDebugger(m_debugSettings);
    m_mockDebugger.setAddressTranslator(mockModule, new CAddress(0), new CAddress(0x1000));
    final Debugger debugger = new Debugger(m_mockDebugger);
    m_logger = new TraceLogger(debugger, module);
    m_projectLogger = new TraceLogger(debugger, project);
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) IDatabase(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabase) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockProject(com.google.security.zynamics.binnavi.disassembly.MockProject) MockProject(com.google.security.zynamics.binnavi.disassembly.MockProject) Project(com.google.security.zynamics.binnavi.API.disassembly.Project) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IDatabase(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) Before(org.junit.Before)

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