Search in sources :

Example 1 with CAddressSpace

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

the class PostgreSQLAddressSpaceLoader method loadAddressSpaces.

/**
 * Loads the address spaces of a project.
 *
 * The project, the debugger manager, and all modules in the module list must be stored in the
 * database connected to by the provider argument.
 *
 * @param provider The SQL provider that provides the connection.
 * @param project The parent project of the address spaces to load.
 * @param debuggerManager Debugger manager of the database.
 * @param list A list of all modules that belong to the database.
 *
 * @return A list that contains the address spaces of the project.
 *
 * @throws CouldntLoadDataException Thrown if the address spaces could not be loaded.
 */
public static List<CAddressSpace> loadAddressSpaces(final AbstractSQLProvider provider, final INaviProject project, final DebuggerTemplateManager debuggerManager, final List<INaviModule> list) throws CouldntLoadDataException {
    checkArguments(provider, project);
    Preconditions.checkNotNull(debuggerManager, "IE01543: Debugger provider argument can not be null");
    Preconditions.checkNotNull(list, "IE01545: Modules argument can not be null");
    NaviLogger.info("Loading address spaces of project %s", project.getConfiguration().getName());
    final CConnection connection = provider.getConnection();
    final List<CAddressSpace> addressSpaces = new ArrayList<CAddressSpace>();
    final String query = "SELECT id, name, description, creation_date, modification_date, debugger_id " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE project_id = " + project.getConfiguration().getId();
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final int addressSpaceId = resultSet.getInt("id");
                final Map<INaviModule, IAddress> imageBases = loadImageBases(connection, addressSpaceId, list);
                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 DebuggerTemplate debuggerDescription = debuggerManager.findDebugger(resultSet.getInt("debugger_id"));
                addressSpaces.add(new CAddressSpace(addressSpaceId, name, description, creationDate, modificationDate, imageBases, debuggerDescription, provider, project));
            }
            return addressSpaces;
        } finally {
            resultSet.close();
        }
    } catch (final SQLException e) {
        throw new CouldntLoadDataException(e);
    }
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ResultSet(java.sql.ResultSet) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)

Example 2 with CAddressSpace

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

the class PostgreSQLProviderTest method testSetImageBase1.

@Test
public void testSetImageBase1() throws CouldntSaveDataException, CouldntLoadDataException {
    final CProject project = getProvider().createProject("SOME_TEST_PROJECT");
    getProvider().createAddressSpace(project, "SOME_ADDRESS_SPACE");
    final CAddressSpace addressSpace = getProvider().loadAddressSpaces(project).get(0);
    final INaviModule module = getProvider().loadModules().get(0);
    getProvider().setImageBase(addressSpace, module, new CAddress(BigInteger.valueOf(0)));
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) 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)

Example 3 with CAddressSpace

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

the class PostgreSQLProviderTest method testSetNameAddressSpace1.

@Test
public void testSetNameAddressSpace1() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviProject project = getProvider().loadProjects().get(0);
    getProvider().createAddressSpace(project, "SEPPEL");
    final CAddressSpace addressSpace = getProvider().loadAddressSpaces(getProvider().loadProjects().get(0)).get(0);
    getProvider().setName(addressSpace, "New Name");
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 4 with CAddressSpace

use of com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace 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");
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 5 with CAddressSpace

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

the class PostgreSQLProviderTest method testAddModule1.

@Test
public void testAddModule1() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException {
    final INaviModule module = getProvider().loadModules().get(0);
    final CProject project = getProvider().createProject("FOOBAR_PROJECT");
    getProvider().createAddressSpace(project, "FOOBAR_ADDRESS_SPACE");
    final CAddressSpace as = getProvider().loadAddressSpaces(project).get(0);
    getProvider().addModule(as, module);
    try {
        getProvider().addModule(as, module);
        fail();
    } catch (final CouldntSaveDataException exception) {
        getProvider().removeModule(as, module);
    }
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)23 Test (org.junit.Test)17 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)9 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)8 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)6 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)5 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)4 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)4 CProject (com.google.security.zynamics.binnavi.disassembly.CProject)4 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)4 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)4 CProjectNode (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Project.CProjectNode)3 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)3 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)3 MockProject (com.google.security.zynamics.binnavi.disassembly.MockProject)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3