Search in sources :

Example 6 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CBreakpointManagerTest method testGetBreakpoint2.

@Test
public void testGetBreakpoint2() {
    assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_manager.getBreakpointStatus(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x123))), BreakpointType.REGULAR));
    assertEquals(BreakpointStatus.BREAKPOINT_INACTIVE, m_manager.getBreakpointStatus(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x456))), BreakpointType.REGULAR));
    assertEquals(null, m_manager.getBreakpointStatus(null, BreakpointType.REGULAR));
    assertEquals(null, m_manager.getBreakpointStatus(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0))), BreakpointType.REGULAR));
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 7 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CTraceLoggerTest method testOverwrittenEchoBreakpoint.

@Test
public void testOverwrittenEchoBreakpoint() throws DebugExceptionWrapper {
    // Scenario: Echo breakpoint of the trace is overwritten by a regular breakpoint
    final ITraceListProvider provider = new MockTraceListProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(module));
    debugger.setAddressTranslator(module, new CAddress(0), new CAddress(0x1000));
    debugger.connect();
    final TraceLogger logger = new TraceLogger(provider, debugger);
    final MockTraceLoggerListener listener = new MockTraceLoggerListener();
    logger.addListener(listener);
    final MockSqlProvider sqlProvider = new MockSqlProvider();
    final TraceList trace = new TraceList(1, "Foo", "Bar", sqlProvider);
    final Set<BreakpointAddress> addresses = new HashSet<BreakpointAddress>();
    addresses.add(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x100))));
    addresses.add(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x200))));
    logger.start(trace, addresses, 1);
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x100)))));
    assertEquals("++-", listener.events);
    logger.stop();
    assertEquals("++--!", listener.events);
    // Start the trace mode again to make sure all resources were cleaned
    // up in the previous run.
    logger.start(trace, addresses, 1);
    logger.stop();
    debugger.close();
}
Also used : ITraceListProvider(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceListProvider) TraceLogger(com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CTraceLoggerTest method testTargetClosed.

@Test
public void testTargetClosed() throws DebugExceptionWrapper {
    final ITraceListProvider provider = new MockTraceListProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(module));
    debugger.setAddressTranslator(module, new CAddress(0), new CAddress(0x1000));
    debugger.connect();
    final TraceLogger logger = new TraceLogger(provider, debugger);
    final MockTraceLoggerListener listener = new MockTraceLoggerListener();
    logger.addListener(listener);
    final MockSqlProvider sqlProvider = new MockSqlProvider();
    final TraceList trace = new TraceList(1, "Foo", "Bar", sqlProvider);
    final Set<BreakpointAddress> addresses = new HashSet<BreakpointAddress>();
    addresses.add(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x100))));
    logger.start(trace, addresses, 1);
    debugger.getProcessManager().setAttached(false);
    assertEquals("+!", listener.events);
    logger.stop();
    // assertEquals(0, debugger.getBreakpointManager().getNumberOfBreakpoints(BreakpointType.ECHO));
    // Start the trace mode again to make sure all resources were cleaned
    // up in the previous run.
    logger.start(trace, addresses, 1);
    logger.stop();
    debugger.close();
}
Also used : ITraceListProvider(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceListProvider) TraceLogger(com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TraceList(com.google.security.zynamics.binnavi.debug.models.trace.TraceList) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class TraceLogger method start.

/**
   * Starts an event trace.
   *
   * @param trace Trace list where the recorded events are stored.
   * @param relocatedAddresses List of addresses where echo breakpoints are put
   * @param maximumHits Maximum number of hits before an echo breakpoint is removed.
   */
public void start(final TraceList trace, final Set<BreakpointAddress> relocatedAddresses, final int maximumHits) {
    Preconditions.checkNotNull(relocatedAddresses, "IE00762: Address list can not be null");
    Preconditions.checkArgument(!relocatedAddresses.isEmpty(), "IE00787: Address list can not be empty");
    for (final BreakpointAddress address : relocatedAddresses) {
        Preconditions.checkNotNull(address, "IE00788: Address list contains invalid elements");
    }
    // Lock required because while breakpoints are added, previously set breakpoints
    lock.lock();
    // can be hit => Comodification exception.
    eventList = trace;
    // The trace logger must handle debug events
    debugger.addListener(m_debuggerListener);
    debugger.getProcessManager().addListener(m_processListener);
    breakpointManager.addListener(m_breakpointManagerListener);
    NaviLogger.info("Starting new event list with name %s", trace.getName());
    final Set<BreakpointAddress> collectedAddresses = new HashSet<BreakpointAddress>();
    for (final BreakpointAddress address : relocatedAddresses) {
        if (EchoBreakpointCollector.isBlocked(breakpointManager, address)) {
            continue;
        }
        if (!debugger.isConnected()) {
            lock.unlock();
            return;
        }
        collectedAddresses.add(address);
    }
    breakpointManager.addBreakpoints(BreakpointType.ECHO, collectedAddresses);
    for (final BreakpointAddress address : collectedAddresses) {
        try {
            // Add the echo breakpoint to the list of active echo breakpoints
            activeEchoBreakpoints.put(address, maximumHits);
            for (final ITraceLoggerListener listener : listeners) {
                listener.addedBreakpoint();
            }
        } catch (final IllegalArgumentException exception) {
            // This is possible in case of the following race condition:
            //
            // 1. m_bpManager.hasEchoBreakpoint(address) => false
            // 2. Echo breakpoint is set at address by another thread
            // 3. This thread tries to set an echo breakpoint at address
            CUtilityFunctions.logException(exception);
        }
    }
    if (activeEchoBreakpoints.isEmpty()) {
        // Can happen if all given addresses are blocked
        removeListeners();
    }
    lock.unlock();
}
Also used : ITraceLoggerListener(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceLoggerListener) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet)

Example 10 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class TraceLogger method stop.

/**
   * Stops the trace mode.
   *
   * @return The echo breakpoints that were removed.
   */
public Set<BreakpointAddress> stop() {
    NaviLogger.info("Finalizing event list %s with %d events", eventList.getName(), eventList.getEventCount());
    // Nothing to do if all echo breakpoints were hit.
    if (activeEchoBreakpointCount() == 0) {
        return new HashSet<BreakpointAddress>();
    }
    lock.lock();
    // No more events please
    removeListeners();
    // Remove all echo breakpoints which were not hit.
    // Copy is necessary to avoid a ConcurrentModificationException
    final Set<BreakpointAddress> ebps = new HashSet<>(activeEchoBreakpoints.keySet());
    breakpointManager.removeBreakpoints(BreakpointType.ECHO, ebps);
    try {
        for (final ITraceLoggerListener listener : listeners) {
            listener.removedBreakpoint();
        }
    } catch (final IllegalArgumentException exception) {
    // This can happen if the debugger quits while
    // we are removing echo breakpoints.
    }
    activeEchoBreakpoints.clear();
    lock.unlock();
    for (final ITraceLoggerListener listener : listeners) {
        try {
            listener.finished(eventList);
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return ebps;
}
Also used : ITraceLoggerListener(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceLoggerListener) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet)

Aggregations

BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)87 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)49 Test (org.junit.Test)39 HashSet (java.util.HashSet)24 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)22 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)15 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)15 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)13 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)11 BreakpointManager (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager)11 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)11 ArrayList (java.util.ArrayList)9 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)8 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)8 CBreakpointTableModel (com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7 ITraceEvent (com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceEvent)7