Search in sources :

Example 51 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule in project binnavi by google.

the class DebuggerTest method testRelocation1.

@Test
public void testRelocation1() {
    final INaviModule nativeModule = new MockModule();
    mockDebugger.setAddressTranslator(nativeModule, new CAddress(100), new CAddress(200));
    final Module module = ModuleFactory.get(nativeModule);
    assertEquals(250, debugger.toImagebase(module, new Address(150)).toLong());
    assertEquals(150, debugger.toFilebase(module, new Address(250)).toLong());
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 52 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule in project binnavi by google.

the class CEventListTableModelTest method test2056.

/**
   * This test makes sure that the listener issue described in Case 2056 does not happen again.
   * 
   * @throws CouldntLoadDataException
   * @throws LoadCancelledException
   * @throws CouldntSaveDataException
   */
@Test
public void test2056() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    final INaviModule module = new MockModule(false);
    module.getContent().getTraceContainer().createTrace("foo", "bar");
    final ITraceListProvider traceListProvider = new ModuleTraceProvider(module);
    final CEventListTableModel model = new CEventListTableModel(traceListProvider);
    module.load();
    model.delete();
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) ITraceListProvider(com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceListProvider) ModuleTraceProvider(com.google.security.zynamics.binnavi.debug.models.trace.ModuleTraceProvider) CEventListTableModel(com.google.security.zynamics.binnavi.Gui.Debug.EventLists.CEventListTableModel) Test(org.junit.Test)

Example 53 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule in project binnavi by google.

the class CEventValueTableModelTest method foo.

@Test
public void foo() {
    final CEventValueTableModel model = new CEventValueTableModel();
    final INaviModule mockModule = new MockModule();
    final TraceEvent event = new TraceEvent(77, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x123))), TraceEventType.REGULAR_BREAKPOINT, Lists.newArrayList(new TraceRegister("eax", new CAddress(0x123), new byte[] { 05, 06, 07 })));
    assertEquals(0, model.getRowCount());
    model.setEvent(event);
    assertEquals(1, model.getRowCount());
    assertEquals("eax", model.getValueAt(0, 0));
    assertEquals("00000123", model.getValueAt(0, 1));
    assertEquals("05 06 07", model.getValueAt(0, 2));
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) TraceRegister(com.google.security.zynamics.binnavi.debug.models.trace.TraceRegister) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) CEventValueTableModel(com.google.security.zynamics.binnavi.Gui.Debug.EventLists.CEventValueTableModel) TraceEvent(com.google.security.zynamics.binnavi.debug.models.trace.TraceEvent) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 54 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule 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 55 with MockModule

use of com.google.security.zynamics.binnavi.disassembly.Modules.MockModule 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

MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)98 Test (org.junit.Test)90 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)45 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)32 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)26 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)24 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)14 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)14 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)13 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)13 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)12 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 CCodeBookmarkManager (com.google.security.zynamics.binnavi.models.Bookmarks.code.CCodeBookmarkManager)12 MockAddress (com.google.security.zynamics.zylib.disassembly.MockAddress)12 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)11 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)11 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)10 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)10 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)9