Search in sources :

Example 1 with ITraceLoggerListener

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

use of com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceLoggerListener 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)2 ITraceLoggerListener (com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceLoggerListener)2 HashSet (java.util.HashSet)2