Search in sources :

Example 16 with CProject

use of com.google.security.zynamics.binnavi.disassembly.CProject in project binnavi by google.

the class CAddressSpaceNodeComponentTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, CouldntSaveDataException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, LoadCancelledException {
    final JTree tree = new JTree();
    m_database = new MockDatabase(m_provider);
    m_project = new CProject(1, "Mock Project", "Mock Project Description", new Date(), new Date(), 0, new ArrayList<DebuggerTemplate>(), m_provider);
    m_project.load();
    m_addressSpace = m_project.getContent().createAddressSpace("Address Space");
    m_component = new CAddressSpaceNodeComponent(tree, m_database, m_project, m_addressSpace);
    m_saveButton = (JButton) ReflectionHelpers.getField(m_component, "m_saveButton");
    m_editPanel = (CStandardEditPanel) ReflectionHelpers.getField(m_component, "m_stdEditPanel");
    m_titledBorder = (TitledBorder) ReflectionHelpers.getField(m_component, "m_titledBorder");
    m_debuggerCombo = (CDebuggerComboBox) ReflectionHelpers.getField(m_component, "m_debuggerCombo");
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) JTree(javax.swing.JTree) ArrayList(java.util.ArrayList) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Date(java.util.Date) Before(org.junit.Before)

Example 17 with CProject

use of com.google.security.zynamics.binnavi.disassembly.CProject in project binnavi by google.

the class CDatabaseContent method addProject.

/**
   * Adds a new project to the database.
   * 
   * This function is guaranteed to be thread-safe. If the new project could not be saved to the
   * database, the state of the database object remains unchanged.
   * 
   * @param name The name of the new project.
   * 
   * @return The added project.
   * 
   * @throws IllegalArgumentException Thrown if the name of the new project is null.
   * @throws CouldntSaveDataException Thrown if the new project could not be saved to the database.
   */
@Override
public INaviProject addProject(final String name) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00661: Project name can not be null");
    Preconditions.checkArgument(m_database.isConnected(), "IE00662: Database must be connected before a project can be added");
    Preconditions.checkArgument(m_database.isLoaded(), "IE00663: Database must be loaded before a project can be added");
    final CProject newProject = m_provider.createProject(name);
    m_projects.add(newProject);
    for (final IDatabaseListener listener : m_listeners) {
        try {
            listener.addedProject(m_database, newProject);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return newProject;
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) IDatabaseListener(com.google.security.zynamics.binnavi.Database.Interfaces.IDatabaseListener) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 18 with CProject

use of com.google.security.zynamics.binnavi.disassembly.CProject in project binnavi by google.

the class PostgreSQLProjectCreator method loadProject.

/**
   * Loads a project from the database.
   * 
   * @param provider The connection to the database.
   * @param projectId The ID of the project to load.
   * 
   * @return The loaded project.
   * 
   * @throws SQLException Thrown if the project could not be loaded.
   */
protected static CProject loadProject(final AbstractSQLProvider provider, final int projectId) throws SQLException {
    final String query = "select id, name, description, creation_date, modification_date from " + CTableNames.PROJECTS_TABLE + " where id = " + projectId;
    try (ResultSet resultSet = provider.getConnection().executeQuery(query, true)) {
        while (resultSet.next()) {
            final String name = PostgreSQLHelpers.readString(resultSet, "name");
            final String description = PostgreSQLHelpers.readString(resultSet, "description");
            final int addressSpaceCount = 0;
            final Timestamp creationDate = resultSet.getTimestamp("creation_date");
            final Timestamp modificationDate = resultSet.getTimestamp("modification_date");
            return new CProject(projectId, name, description, creationDate, modificationDate, addressSpaceCount, new ArrayList<DebuggerTemplate>(), provider);
        }
    }
    return null;
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp)

Example 19 with CProject

use of com.google.security.zynamics.binnavi.disassembly.CProject in project binnavi by google.

the class PostgreSQLProviderTest method testGetModificationDate1.

@Test
public void testGetModificationDate1() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final CProject project = getProvider().createProject("TEST_PROJECT");
    getProvider().createAddressSpace(project, "SOME_ADDRESS_SPACE_12455");
    assertNotNull(getProvider().getModificationDate(getProvider().loadAddressSpaces(project).get(0)));
    assertNotNull(getProvider().getModificationDate(getProvider().loadModules().get(0)));
    assertNotNull(getProvider().getModificationDate(getProvider().loadProjects().get(0)));
    final INaviModule module = getProvider().loadModules().get(0);
    module.load();
    assertNotNull(getProvider().getModificationDate(module.getContent().getViewContainer().getViews().get(0)));
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 20 with CProject

use of com.google.security.zynamics.binnavi.disassembly.CProject in project binnavi by google.

the class PostgreSQLProviderTest method testCAddressSpaceLoaderLoadAddressSpaces1.

@Test
public void testCAddressSpaceLoaderLoadAddressSpaces1() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final DebuggerTemplateManager debuggerManager = new DebuggerTemplateManager(getProvider());
    final CProject project = getProvider().createProject("PROJECT_234");
    getProvider().createAddressSpace(project, "ADDRESS_SPACE_234");
    final List<INaviModule> modules = getProvider().loadModules();
    final List<INaviModule> convertedModules = new ArrayList<INaviModule>();
    convertedModules.add(modules.get(0));
    final List<CAddressSpace> addressSpaces = PostgreSQLAddressSpaceLoader.loadAddressSpaces((AbstractSQLProvider) getProvider(), project, debuggerManager, convertedModules);
    final CAddressSpace addressSpace = addressSpaces.get(0);
    addressSpace.load();
    addressSpace.getContent().addModule(modules.get(0));
    addressSpace.getContent().setImageBase(modules.get(0), new CAddress(0x1234));
    @SuppressWarnings("unused") final List<CAddressSpace> addressSpaces2 = PostgreSQLAddressSpaceLoader.loadAddressSpaces((AbstractSQLProvider) getProvider(), project, debuggerManager, convertedModules);
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ArrayList(java.util.ArrayList) DebuggerTemplateManager(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplateManager) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

CProject (com.google.security.zynamics.binnavi.disassembly.CProject)28 Test (org.junit.Test)15 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)12 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)8 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)8 Before (org.junit.Before)8 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)5 CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)3 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)3 CProjectTreeModel (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.CProjectTreeModel)3 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)2 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)2 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)2