Search in sources :

Example 21 with CAddressSpace

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

the class CProject method load.

@Override
public void load() throws CouldntLoadDataException, LoadCancelledException {
    synchronized (m_loadReporter) {
        if (isLoaded()) {
            return;
        }
        m_isLoading = true;
        try {
            if (!m_loadReporter.report(ProjectLoadEvents.Starting)) {
                throw new LoadCancelledException();
            }
            if (!m_loadReporter.report(ProjectLoadEvents.LoadingAddressSpaces)) {
                throw new LoadCancelledException();
            }
            final List<CAddressSpace> addressSpaces = m_provider.loadAddressSpaces(this);
            for (final CAddressSpace space : addressSpaces) {
                space.load();
            }
            if (!m_loadReporter.report(ProjectLoadEvents.LoadingCallgraphViews)) {
                throw new LoadCancelledException();
            }
            final List<ICallgraphView> userCallgraphs = m_provider.loadCallgraphViews(this);
            if (!m_loadReporter.report(ProjectLoadEvents.LoadingFlowgraphViews)) {
                throw new LoadCancelledException();
            }
            final List<IFlowgraphView> userFlowgraphs = m_provider.loadFlowgraphs(this);
            if (!m_loadReporter.report(ProjectLoadEvents.LoadingMixedgraphViews)) {
                throw new LoadCancelledException();
            }
            final List<INaviView> userMixedgraphs = m_provider.loadMixedgraphs(this);
            if (!m_loadReporter.report(ProjectLoadEvents.LoadingTraces)) {
                throw new LoadCancelledException();
            }
            final List<TraceList> traces = m_provider.loadTraces(this);
            final ArrayList<INaviView> views = new ArrayList<INaviView>(userCallgraphs);
            views.addAll(userFlowgraphs);
            views.addAll(userMixedgraphs);
            m_content = new CProjectContent(this, m_listeners, m_provider, addressSpaces, views, new FilledList<TraceList>(traces));
        } catch (CouldntLoadDataException | LoadCancelledException e) {
            m_isLoading = false;
            throw e;
        } finally {
            m_loadReporter.report(ProjectLoadEvents.Finished);
        }
        for (final IProjectListener listener : m_listeners) {
            try {
                listener.loadedProject(this);
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
            }
        }
        m_isLoading = false;
    }
}
Also used : FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)

Example 22 with CAddressSpace

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

the class PostgreSQLProjectFunctions method readAddressSpace.

/**
 * Loads an address space from the database.
 *
 * The address space ID must belong to an address space in the database connected to by the
 * provider argument.
 *
 * @param provider The connection to the database.
 * @param addressSpaceId The ID of the address space to load.
 * @param project The optional project for the address space.
 * @return The loaded address space.
 *
 * @throws SQLException Thrown if loading the address space failed.
 */
public static CAddressSpace readAddressSpace(final AbstractSQLProvider provider, final int addressSpaceId, final INaviProject project) throws SQLException {
    final String query = "SELECT name, description, creation_date, modification_date " + " FROM " + CTableNames.ADDRESS_SPACES_TABLE + " WHERE id = " + addressSpaceId;
    final ResultSet resultSet = provider.getConnection().executeQuery(query, true);
    try {
        while (resultSet.next()) {
            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");
            return new CAddressSpace(addressSpaceId, name, description == null ? "" : description, creationDate, modificationDate, new HashMap<INaviModule, IAddress>(), null, provider, project);
        }
    } finally {
        resultSet.close();
    }
    return null;
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 23 with CAddressSpace

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

the class CProjectFunctions method addAddressSpace.

/**
 * Adds a new address space with a default name to a given project.
 *
 * @param parent Parent window used for dialogs.
 * @param project The project where the new address space is added.
 * @param updater Updates the project tree after the execution is complete.
 */
public static void addAddressSpace(final Window parent, final INaviProject project, final INodeSelectionUpdater updater) {
    new Thread() {

        @Override
        public void run() {
            final CDefaultProgressOperation operation = new CDefaultProgressOperation("", false, true);
            operation.getProgressPanel().setMaximum(2);
            try {
                operation.getProgressPanel().setText("Creating new address space");
                operation.getProgressPanel().next();
                final CAddressSpace addressSpace = project.getContent().createAddressSpace("New Address Space");
                operation.getProgressPanel().setText("Loading new address space");
                addressSpace.load();
                operation.getProgressPanel().next();
                operation.stop();
                updater.setObject(addressSpace);
                updater.update();
            } catch (final CouldntSaveDataException exception) {
                CUtilityFunctions.logException(exception);
                final String innerMessage = "E00136: " + "Could not add address space";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("It was not possible to add a new address space to the project '%s'.", project.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The address space was not created." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, exception);
            } catch (final CouldntLoadDataException exception) {
                CUtilityFunctions.logException(exception);
                final String innerMessage = "E00137: " + "Could not load the new address space";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The new address space in project '%s' was created but it could not be loaded.", project.getConfiguration().getName()), new String[] { "There was a problem with the database connection." }, new String[] { "The address space was created but not loaded." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, exception);
            } catch (final LoadCancelledException e) {
            // Do nothing
            }
        }
    }.start();
}
Also used : CDefaultProgressOperation(com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) CAddressSpace(com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)

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