Search in sources :

Example 61 with BreakpointAddress

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

the class CBreakpointManagerTest method testRemoveRegularBreakpoint.

@Test
public void testRemoveRegularBreakpoint() {
    // Error condition: Null argument
    try {
        m_manager.removeBreakpoints(BreakpointType.REGULAR, null);
        fail("Exception not raised");
    } catch (final NullPointerException ex) {
    }
    assertEquals(3, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    m_manager.removeBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x123)))));
    assertEquals(2, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    m_manager.removeBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x456)))));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    m_manager.removeBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x789)))));
    assertEquals(0, m_manager.getNumberOfBreakpoints(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 62 with BreakpointAddress

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

the class CBreakpointManagerTest method setUp.

@Before
public void setUp() {
    m_manager = new BreakpointManager();
    m_manager.addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
    m_manager.addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x456)))));
    m_manager.addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x789)))));
    m_manager.addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x111)))));
    m_manager.addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x222)))));
    m_manager.addBreakpoints(BreakpointType.STEP, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x1000)))));
}
Also used : UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Before(org.junit.Before)

Example 63 with BreakpointAddress

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

the class CBreakpointManagerTest method testBreakpointOverwriting.

@Test
public void testBreakpointOverwriting() {
    final MockBreakpointManagerListener listener = new MockBreakpointManagerListener();
    m_manager.addListener(listener);
    // Echo breakpoints can not overwrite regular breakpoints.
    m_manager.addBreakpoints(BreakpointType.ECHO, CommonTestObjects.BP_ADDRESS_123_SET);
    assertEquals(0, listener.size());
    assertEquals(3, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(2, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
    // Echo breakpoints can not overwrite stepping breakpoints
    m_manager.addBreakpoints(BreakpointType.ECHO, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x1000)))));
    assertEquals(0, listener.size());
    assertEquals(3, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(2, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
    // Stepping breakpoints can not overwrite regular breakpoints
    m_manager.addBreakpoints(BreakpointType.STEP, CommonTestObjects.BP_ADDRESS_123_SET);
    assertEquals(0, listener.size());
    assertEquals(3, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(2, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
    // Stepping breakpoints can overwrite echo breakpoints
    m_manager.addBreakpoints(BreakpointType.STEP, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x111)))));
    assertEquals(2, listener.size());
    assertEquals("Remove: 00000111", listener.getEvent(0));
    assertEquals("Add: 00000111", listener.getEvent(1));
    assertEquals(3, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(2, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
    // Regular breakpoints can overwrite stepping breakpoints
    m_manager.addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x1000)))));
    assertEquals(4, listener.size());
    assertEquals("Remove: 00001000", listener.getEvent(2));
    assertEquals("Add: 00001000", listener.getEvent(3));
    assertEquals(4, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
    // Regular breakpoints can overwrite echo breakpoints
    m_manager.addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(m_module, new UnrelocatedAddress(new CAddress(0x222)))));
    assertEquals(6, listener.size());
    assertEquals("Remove: 00000222", listener.getEvent(4));
    assertEquals("Add: 00000222", listener.getEvent(5));
    assertEquals(5, m_manager.getNumberOfBreakpoints(BreakpointType.REGULAR));
    assertEquals(0, m_manager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals(1, m_manager.getNumberOfBreakpoints(BreakpointType.STEP));
}
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 64 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress 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 65 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress 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)

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