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));
}
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();
}
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();
}
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();
}
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;
}
Aggregations