Search in sources :

Example 41 with ModuleTargetSettings

use of com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings in project binnavi by google.

the class CHistoryStringBuilderTest method setUp.

@Before
public void setUp() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    m_debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
    m_debugger.setAddressTranslator(mockModule, mockFileBase, mockImageBase.getAddress());
    m_breakpointManager = m_debugger.getBreakpointManager();
    m_synchronizer = new DebuggerSynchronizer(m_debugger);
    m_synchronizer.addListener(m_listener);
    // assign the synchronizer to the internally used one by the debugger so we can test the
    // synchronizer itself
    // as well as the combination of synchronizer and debugger
    final Field synchronizerField = AbstractDebugger.class.getDeclaredField("synchronizer");
    synchronizerField.setAccessible(true);
    synchronizerField.set(m_debugger, m_synchronizer);
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) DebuggerSynchronizer(com.google.security.zynamics.binnavi.debug.debugger.synchronizers.DebuggerSynchronizer) Field(java.lang.reflect.Field) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) Before(org.junit.Before)

Example 42 with ModuleTargetSettings

use of com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings in project binnavi by google.

the class CMemoryViewerSynchronizerTest method testSwitchDebuggers.

@Test
public void testSwitchDebuggers() throws DebugExceptionWrapper {
    m_debugger.connect();
    m_debugger.getProcessManager().setAttached(true);
    m_debugger.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x100), new CAddress(0x1FF)))));
    m_model.setActiveMemoryAddress(new CAddress(0x100), false);
    assertEquals(0x100, m_hexView.getCurrentOffset());
    assertEquals(0x100, m_hexView.getData().getDataLength());
    final IDebugger debugger2 = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger2.connect();
    debugger2.getProcessManager().setMemoryMap(new MemoryMap(Lists.newArrayList(new MemorySection(new CAddress(0x10), new CAddress(0x50)))));
    m_model.setActiveDebugger(debugger2);
    assertEquals(0x10, m_hexView.getCurrentOffset());
    assertEquals(0x41, m_hexView.getData().getDataLength());
    m_debugger.getProcessManager().setAttached(false);
    m_synchronizer.dispose();
    debugger2.close();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 43 with ModuleTargetSettings

use of com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings in project binnavi by google.

the class CTraceLoggerTest method testAllBreakpointsBlocked.

@Test
public void testAllBreakpointsBlocked() throws DebugExceptionWrapper {
    // Scenario: All given addresses are already blocked by regular breakpoints
    final ITraceListProvider provider = new MockTraceListProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(module));
    debugger.setAddressTranslator(module, new CAddress(0), new CAddress(0x1000));
    debugger.connect();
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(0x100)))));
    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);
    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 44 with ModuleTargetSettings

use of com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings in project binnavi by google.

the class CTraceLoggerTest method testHitEchoBreakpoint.

@Test
public void testHitEchoBreakpoint() throws DebugExceptionWrapper, MessageParserException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // Scenario: All echo breakpoints are hit
    final ITraceListProvider provider = new MockTraceListProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(module));
    final MockModule module = new MockModule();
    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, 3);
    final DebuggerSynchronizer m_synchronizer = (DebuggerSynchronizer) ReflectionHelpers.getField(AbstractDebugger.class, debugger, "synchronizer");
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1100))));
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1200))));
    assertEquals(2, trace.getEventCount());
    assertEquals("++", listener.events);
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1100))));
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1200))));
    assertEquals(4, trace.getEventCount());
    assertEquals("++", listener.events);
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1100))));
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1200))));
    assertEquals(6, trace.getEventCount());
    assertEquals("++--!", listener.events);
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1100))));
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1200))));
    assertEquals(6, trace.getEventCount());
    assertEquals("++--!", listener.events);
    logger.stop();
    assertEquals(6, trace.getEventCount());
    assertEquals("++--!", listener.events);
    logger.start(trace, addresses, 1);
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1100))));
    m_synchronizer.receivedEvent(DebuggerMessageBuilder.buildEchoBreakpointHit(new RelocatedAddress(new CAddress(0x1200))));
    logger.stop();
    assertEquals(8, trace.getEventCount());
    debugger.close();
}
Also used : DebuggerSynchronizer(com.google.security.zynamics.binnavi.debug.debugger.synchronizers.DebuggerSynchronizer) ITraceListProvider(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceListProvider) TraceLogger(com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) 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) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) AbstractDebugger(com.google.security.zynamics.binnavi.debug.debugger.AbstractDebugger) 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 45 with ModuleTargetSettings

use of com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings in project binnavi by google.

the class CTraceLoggerTest method testCase1637.

@Test
public void testCase1637() throws DebugExceptionWrapper, InterruptedException {
    // This test tries to check for a race condition that happens like this:
    //
    // 1. Trace mode is stopping
    // 2. Stopping trace mode removes listeners of hit breakpoint before breakpoint is hit
    // 3. Echo breakpoint is hit => listener is removed again
    //
    // Result: Crash
    final ITraceListProvider provider = new MockTraceListProvider();
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(module));
    debugger.connect();
    final MockModule module = new MockModule();
    debugger.setAddressTranslator(module, new CAddress(0), new CAddress(0x1000));
    final Set<BreakpointAddress> addresses = new HashSet<BreakpointAddress>();
    for (int i = 0; i < 1000; i++) {
        addresses.add(new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(i))));
    }
    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);
    logger.start(trace, addresses, 1);
    final Breakpoint breakpoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.ECHO, new BreakpointAddress(module, new UnrelocatedAddress(new CAddress(999))));
    new Thread() {

        @Override
        public void run() {
            logger.stop();
        }
    }.start();
    new Thread() {

        @Override
        public void run() {
            debugger.getBreakpointManager().setBreakpointStatus(Sets.newHashSet(breakpoint.getAddress()), breakpoint.getType(), BreakpointStatus.BREAKPOINT_HIT);
        }
    }.start();
    while (logger.activeEchoBreakpointCount() != 0) {
        Thread.sleep(100);
    }
}
Also used : Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) 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) Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) 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)

Aggregations

ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)73 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)65 Test (org.junit.Test)63 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)51 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)21 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)20 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)20 ArrayList (java.util.ArrayList)19 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)18 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)18 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)17 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)17 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)17 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)16 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)15 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)15 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)14 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)11 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10