Search in sources :

Example 21 with TraceList

use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.

the class PostgreSQLTracesLoader method loadTraces.

/**
   * Loads all traces of a view container.
   *
   * @param provider The connection to the database.
   * @param tableName The table name of the view container.
   * @param columnName The column name of the view container.
   * @param containerId The ID of the view container.
   * @param modules List of all modules stored in the database.
   *
   * @return The loaded traces.
   *
   * @throws CouldntLoadDataException Thrown if loading the traces failed.
   */
public static IFilledList<TraceList> loadTraces(final AbstractSQLProvider provider, final String tableName, final String columnName, final int containerId, final List<? extends INaviModule> modules) throws CouldntLoadDataException {
    Preconditions.checkNotNull(provider, "IE00590: Provider argument can not be null");
    Preconditions.checkNotNull(tableName, "IE00591: Table name argument can not be null");
    Preconditions.checkNotNull(columnName, "IE00592: Column name argument can not be null");
    final String query = "select id, name, description from " + CTableNames.TRACES_TABLE + " join " + tableName + " on " + tableName + ".trace_id = " + CTableNames.TRACES_TABLE + ".id where " + tableName + "." + columnName + " = " + containerId;
    final CConnection connection = provider.getConnection();
    final IFilledList<TraceList> traces = new FilledList<TraceList>();
    try {
        final ResultSet resultSet = connection.executeQuery(query, true);
        try {
            while (resultSet.next()) {
                final int traceId = resultSet.getInt("id");
                final String name = PostgreSQLHelpers.readString(resultSet, "name");
                final String description = PostgreSQLHelpers.readString(resultSet, "description");
                final TraceList traceList = new TraceList(traceId, name, description, provider);
                loadTraceEvents(connection, traceList, modules);
                traces.add(traceList);
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
    return traces;
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ResultSet(java.sql.ResultSet) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList)

Example 22 with TraceList

use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.

the class PostgreSQLTracesLoader method loadTraceEvents.

/**
   * Loads the trace events of a trace list from the database.
   *
   * @param connection The connection to the database.
   * @param traceList The trace list whose events are loaded.
   * @param modules List of all modules stored in the database.
   *
   * @throws SQLException Thrown if the trace events could not be loaded.
   */
private static void loadTraceEvents(final CConnection connection, final TraceList traceList, final List<? extends INaviModule> modules) throws SQLException {
    final List<List<TraceRegister>> values = loadTraceEventValues(connection, traceList);
    final String query = "select tid, module_id, address, type from " + CTableNames.TRACE_EVENT_TABLE + " where trace_id = " + traceList.getId() + " order by position asc";
    final ResultSet resultSet = connection.executeQuery(query, true);
    int counter = 0;
    try {
        while (resultSet.next()) {
            final long tid = resultSet.getLong("tid");
            final int moduleId = resultSet.getInt("module_id");
            final INaviModule module = resultSet.wasNull() ? null : findModule(modules, moduleId);
            final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(PostgreSQLHelpers.loadAddress(resultSet, "address")));
            final int event = resultSet.getInt("type");
            traceList.addEvent(new TraceEvent(tid, address, TraceEventType.parseInt(event), values.isEmpty() ? new ArrayList<TraceRegister>() : values.get(counter)));
            counter++;
        }
    } finally {
        resultSet.close();
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) TraceRegister(com.google.security.zynamics.binnavi.debug.models.trace.TraceRegister) ResultSet(java.sql.ResultSet) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ArrayList(java.util.ArrayList) List(java.util.List) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) TraceEvent(com.google.security.zynamics.binnavi.debug.models.trace.TraceEvent)

Example 23 with TraceList

use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList 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 24 with TraceList

use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.

the class PostgreSQLProviderTestSetup method testCreateTraceProject4.

@Test
public void testCreateTraceProject4() throws CouldntSaveDataException {
    final INaviProject project = loadProject();
    final TraceList trace = getProvider().createTrace(project, "Trace Name", "Trace Description");
    assertEquals("Trace Name", trace.getName());
    assertEquals("Trace Description", trace.getDescription());
    assertEquals(0, trace.getEventCount());
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 25 with TraceList

use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.

the class PostgreSQLProviderTest method testTraceFunctionsSetDescription1.

@Test
public void testTraceFunctionsSetDescription1() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final INaviProject project = getProvider().createProject("SOME_PROJECT");
    getProvider().createTrace(project, "SOME_TRACE", "SOME_TRACE_DESCRIPTION");
    project.load();
    final TraceList trace = project.getContent().getTraces().get(0);
    assertEquals("SOME_TRACE_DESCRIPTION", project.getContent().getTraces().get(0).getDescription());
    final String description = "boing boing";
    PostgreSQLTraceFunctions.setDescription((AbstractSQLProvider) getProvider(), trace, description);
    project.close();
    INaviProject project2 = null;
    for (final INaviProject cProject : getProvider().loadProjects()) {
        if (cProject.getConfiguration().getId() == project.getConfiguration().getId()) {
            project2 = cProject;
        }
    }
    getProvider().createTrace(project2, "SOME_TRACE_2", "SOME_TRACE_DESCRIPTION_2");
    project2.load();
    final TraceList trace2 = project2.getContent().getTraces().get(0);
    assertEquals(description, trace2.getDescription());
}
Also used : INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)46 Test (org.junit.Test)26 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)14 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)11 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)10 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)10 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)10 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)9 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)7 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7 ITraceListProvider (com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceListProvider)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)6 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)6 Trace (com.google.security.zynamics.binnavi.API.disassembly.Trace)5 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)5 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)5 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)4