Search in sources :

Example 6 with TraceList

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

the class CPostgreSQLModuleContentTest method testDeleteTrace.

@Test
public void testDeleteTrace() throws LoadCancelledException, CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final CModule module = (CModule) getDatabase().getContent().getModules().get(0);
    module.load();
    final CModuleContent moduleContent1 = module.getContent();
    assertNotNull(moduleContent1);
    final CView view = moduleContent1.getViewContainer().createView("name", "desc");
    assertNotNull(view);
    final TraceList trace = moduleContent1.getTraceContainer().createTrace("name2", "desc2");
    assertNotNull(trace);
    moduleContent1.getTraceContainer().deleteTrace(trace);
    try {
        moduleContent1.getTraceContainer().deleteTrace(null);
    } catch (final NullPointerException e) {
    }
}
Also used : CView(com.google.security.zynamics.binnavi.disassembly.views.CView) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 7 with TraceList

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

the class CTraceContainerTest method testTraces.

/**
   * Tests trace creation.
   */
@Test
public void testTraces() throws CouldntSaveDataException, CouldntDeleteException {
    assertEquals(0, m_content.getTraceCount());
    try {
        m_content.createTrace(null, "New Trace Description");
        fail();
    } catch (final NullPointerException exception) {
    }
    try {
        m_content.createTrace("New Trace", null);
        fail();
    } catch (final NullPointerException exception) {
    }
    final TraceList newTrace = m_content.createTrace("New Trace", "New Trace Description");
    // Check listener events
    assertEquals("addedTrace/", m_listener.eventList);
    assertEquals(newTrace, m_listener.addedTraces.get(0));
    // Check module
    assertEquals(1, m_content.getTraceCount());
    assertEquals(newTrace, m_content.getTraces().get(0));
    // Check trace
    assertEquals("New Trace", newTrace.getName());
    assertEquals("New Trace Description", newTrace.getDescription());
    final TraceList newTrace2 = m_content.createTrace("New Trace II", "New Trace Description II");
    // Check listener events
    assertEquals("addedTrace/addedTrace/", m_listener.eventList);
    assertEquals(newTrace2, m_listener.addedTraces.get(1));
    // Check module
    assertEquals(2, m_content.getTraceCount());
    assertEquals(newTrace, m_content.getTraces().get(0));
    assertEquals(newTrace2, m_content.getTraces().get(1));
    // Check trace
    assertEquals("New Trace II", newTrace2.getName());
    assertEquals("New Trace Description II", newTrace2.getDescription());
    // ----------------------------------------- Delete the traces again
    // ------------------------------------------------
    m_content.deleteTrace(newTrace);
    // Check listener events
    assertEquals("addedTrace/addedTrace/deletedTrace/", m_listener.eventList);
    assertEquals(newTrace, m_listener.deletedTraces.get(0));
    // Check module
    assertEquals(1, m_content.getTraceCount());
    assertEquals(newTrace2, m_content.getTraces().get(0));
    m_content.deleteTrace(newTrace2);
    // Check listener events
    assertEquals("addedTrace/addedTrace/deletedTrace/deletedTrace/", m_listener.eventList);
    assertEquals(newTrace2, m_listener.deletedTraces.get(1));
    // Check module
    assertEquals(0, m_content.getTraceCount());
    try {
        m_content.deleteTrace(newTrace2);
        fail();
    } catch (final IllegalArgumentException exception) {
    }
    try {
        m_content.deleteTrace(null);
        fail();
    } catch (final NullPointerException exception) {
    }
}
Also used : TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) Test(org.junit.Test)

Example 8 with TraceList

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

the class PostgreSQLTraceFunctions method createTrace.

/**
   * Creates a new trace list object in the database.
   *
   * @param provider The connection to the database.
   * @param tracesTable The traces table where the trace is added.
   * @param tracesColumn Identifies the view container column for which the trace is created.
   * @param containerTable Identifies the view container table.
   * @param containerId ID of the view container for which the trace is created.
   * @param name The name of the new trace.
   * @param description The description of the new trace.
   *
   * @return The created trace list.
   *
   * @throws CouldntSaveDataException Thrown if the trace list could not be created.
   */
// ESCA-JAVA0138:
private static TraceList createTrace(final AbstractSQLProvider provider, final String tracesTable, final String tracesColumn, final String containerTable, final int containerId, final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00568: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00569: Description argument can not be null");
    final CConnection connection = provider.getConnection();
    final String query = "INSERT INTO " + CTableNames.TRACES_TABLE + "(view_id, name, description) VALUES(?, ?, ?) RETURNING id";
    try {
        final PreparedStatement statement = connection.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        Integer listId = null;
        try {
            statement.setInt(1, 0);
            statement.setString(2, name);
            statement.setString(3, description);
            final ResultSet resultSet = statement.executeQuery();
            try {
                while (resultSet.next()) {
                    if (resultSet.isFirst()) {
                        listId = resultSet.getInt(1);
                    }
                }
            } finally {
                resultSet.close();
            }
        } finally {
            statement.close();
        }
        connection.executeUpdate("INSERT INTO " + tracesTable + "(" + tracesColumn + ", trace_id) " + " VALUES(" + containerId + ", " + listId + ")", true);
        PostgreSQLHelpers.updateModificationDate(connection, containerTable, containerId);
        return new TraceList(listId, name, description, provider);
    } catch (final SQLException exception) {
        throw new CouldntSaveDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) SQLException(java.sql.SQLException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) ResultSet(java.sql.ResultSet) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) PreparedStatement(java.sql.PreparedStatement)

Example 9 with TraceList

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

the class CTraceContainer method createTrace.

/**
   * Creates a new debug trace for the module.
   *
   * @param name The name of the new debug trace.
   * @param description The description of the new debug trace.
   *
   * @return The new debug trace object.
   *
   * @throws CouldntSaveDataException Thrown if the new debug trace could not be saved to the
   *         database.
   */
public TraceList createTrace(final String name, final String description) throws CouldntSaveDataException {
    Preconditions.checkNotNull(name, "IE00157: Name argument can not be null");
    Preconditions.checkNotNull(description, "IE00158: Description argument can not be null");
    final TraceList trace = m_provider.createTrace(m_module, name, description);
    m_traces.add(trace);
    for (final ITraceContainerListener listener : m_listeners) {
        try {
            listener.addedTrace(this, trace);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    m_module.getConfiguration().updateModificationDate();
    return trace;
}
Also used : TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 10 with TraceList

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

the class CTraceCombinationFunctions method differenceTraces.

/**
   * Creates a new trace that contains exactly those events that appear in the first trace but not
   * in the second trace.
   *
   * @param parent Parent window used for dialogs.
   * @param provider Creates the new trace.
   * @param trace1 The first input trace.
   * @param trace2 The second input trace.
   */
public static void differenceTraces(final JFrame parent, final ITraceListProvider provider, final TraceList trace1, final TraceList trace2) {
    new Thread() {

        @Override
        public void run() {
            try {
                final CDefaultProgressOperation operation = new CDefaultProgressOperation("", false, true);
                operation.getProgressPanel().setMaximum(3);
                operation.getProgressPanel().setText(String.format("Creating trace difference between '%s' and '%s'", trace1.getName(), trace2.getName()));
                final TraceList newTrace = provider.createTrace("Combined Trace", String.format("%s - %s", trace1.getName(), trace2.getName()));
                operation.getProgressPanel().next();
                createCombinedTrace(newTrace, Lists.newArrayList(trace1, trace2), getDifferenceAddresses(trace1, trace2));
                operation.getProgressPanel().next();
                newTrace.save();
                operation.getProgressPanel().next();
                operation.stop();
            } catch (final CouldntSaveDataException e) {
                CUtilityFunctions.logException(e);
                final String innerMessage = "E00191: " + "Could not combine debug traces";
                final String innerDescription = CUtilityFunctions.createDescription("The selected traces could not be combined into a larger trace.", new String[] { "There was a problem with the database connection." }, new String[] { "The trace list was not created. You could try to combine the lists again once the connection problem was resolved." });
                NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
            }
        }
    }.start();
}
Also used : CDefaultProgressOperation(com.google.security.zynamics.binnavi.Gui.Progress.CDefaultProgressOperation) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList)

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