Search in sources :

Example 6 with MockDebugger

use of com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger in project binnavi by google.

the class CThreadInformationPanelTest method test3.

/**
   * This test makes sure that going from no debugger to a debugger to more threads works fine.
   */
@Test
public void test3() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // CGraphModelFactory.get(database,
    final IGraphModel graphModel = new MockGraphModel();
    // viewContainer);
    final CDebugPerspectiveModel model = CDebugPerspectiveModelFactory.get(graphModel);
    final CThreadInformationPanel panel = new CThreadInformationPanel(model);
    final IDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    final LinkedHashSet<?> perspectiveListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(model, "m_listeners"), "m_listeners");
    final LinkedHashSet<?> debuggerListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "processManager"), "listeners"), "m_listeners");
    assertEquals(1, perspectiveListeners.size());
    assertEquals(1, debuggerListeners.size());
    model.setActiveDebugger(debugger);
    final TargetProcessThread thread = new TargetProcessThread(0, ThreadState.RUNNING);
    debugger.getProcessManager().addThread(thread);
    final LinkedHashSet<?> threadListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(thread, "listeners"), "m_listeners");
    assertEquals(2, threadListeners.size());
    assertEquals(2, threadListeners.size());
    assertEquals(2, debuggerListeners.size());
    debugger.getProcessManager().removeThread(thread);
    assertEquals(0, threadListeners.size());
    panel.dispose();
    assertEquals(0, threadListeners.size());
    assertEquals(1, debuggerListeners.size());
    assertEquals(0, perspectiveListeners.size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) AbstractDebugger(com.google.security.zynamics.binnavi.debug.debugger.AbstractDebugger) IGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphModel) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MockGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) Test(org.junit.Test)

Example 7 with MockDebugger

use of com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger in project binnavi by google.

the class CThreadInformationPanelTest method test.

/**
   * This test makes sure that going from no debugger to a debugger works fine.
   */
@Test
public void test() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    // CGraphModelFactory.get(database,
    final IGraphModel graphModel = new MockGraphModel();
    // viewContainer);
    final CDebugPerspectiveModel model = CDebugPerspectiveModelFactory.get(graphModel);
    final CThreadInformationPanel panel = new CThreadInformationPanel(model);
    final IDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    final TargetProcessThread thread = new TargetProcessThread(0, ThreadState.RUNNING);
    debugger.getProcessManager().addThread(thread);
    final LinkedHashSet<?> perspectiveListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(model, "m_listeners"), "m_listeners");
    final LinkedHashSet<?> debuggerListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "processManager"), "listeners"), "m_listeners");
    final LinkedHashSet<?> threadListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(thread, "listeners"), "m_listeners");
    assertEquals(1, perspectiveListeners.size());
    assertEquals(1, debuggerListeners.size());
    assertEquals(1, threadListeners.size());
    model.setActiveDebugger(debugger);
    assertEquals(2, threadListeners.size());
    assertEquals(2, debuggerListeners.size());
    panel.dispose();
    assertEquals(1, threadListeners.size());
    assertEquals(1, debuggerListeners.size());
    assertEquals(0, perspectiveListeners.size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDebugPerspectiveModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.Panels.CDebugPerspectiveModel) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) AbstractDebugger(com.google.security.zynamics.binnavi.debug.debugger.AbstractDebugger) IGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.IGraphModel) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MockGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) Test(org.junit.Test)

Example 8 with MockDebugger

use of com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger in project binnavi by google.

the class CBookmarksTableModelTest method test2getValueAt.

@Test
public void test2getValueAt() {
    final DebugTargetSettings target = new ModuleTargetSettings(CommonTestObjects.MODULE);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    final CBookmarkTableModel model = new CBookmarkTableModel(debuggerProvider);
    final IAddress address = new MockAddress();
    final CBookmark bookmark = new CBookmark(address, "foo");
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_0_SET);
    debuggerProvider.addDebugger(debugger);
    final BookmarkManager bookmarkManager = debugger.getBookmarkManager();
    bookmarkManager.addBookmark(bookmark);
    assertEquals(1, bookmarkManager.getNumberOfBookmarks());
    assertEquals("foo", model.getValueAt(0, 2));
    assertEquals(address.toHexString(), model.getValueAt(0, 1));
    assertEquals(debugger.getPrintableString(), model.getValueAt(0, 0));
    final int[] rows = { 0 };
    CBookmarkFunctions.deleteBookmarks(debuggerProvider, rows);
    assertEquals(0, bookmarkManager.getNumberOfBookmarks());
    model.dispose();
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CBookmark(com.google.security.zynamics.binnavi.models.Bookmarks.memory.CBookmark) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) CBookmarkTableModel(com.google.security.zynamics.binnavi.Gui.Debug.Bookmarks.CBookmarkTableModel) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MockAddress(com.google.security.zynamics.zylib.disassembly.MockAddress) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) BookmarkManager(com.google.security.zynamics.binnavi.models.Bookmarks.memory.BookmarkManager) Test(org.junit.Test)

Example 9 with MockDebugger

use of com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger in project binnavi by google.

the class CAbstractConnectionTest method reconnect.

@Test
public void reconnect() throws DebugExceptionWrapper {
    // This test makes sure that consecutive runs of the debugger still receive messages
    final DebugCommand command = new DebugCommand(DebugCommandType.RESP_INFO, 0);
    command.addArgument(new DebugMessageRawArgument("<info><registers></registers><size>32</size><options></options></info>".getBytes()));
    final MockDebugger debugger = new MockDebugger(new byte[][] { "NAVI".getBytes(), command.toByteArray() });
    final MockEventListener listener = new MockEventListener();
    debugger.addListener(listener);
    debugger.connect();
    debugger.connection.m_reader.next();
    debugger.connection.m_reader.next();
    debugger.close();
    assertEquals("RECEIVED_TARGET_INFORMATION;", listener.events);
    debugger.connect();
    debugger.connection.m_reader.next();
    debugger.connection.m_reader.next();
    debugger.close();
    assertEquals("RECEIVED_TARGET_INFORMATION;RECEIVED_TARGET_INFORMATION;", listener.events);
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) DebugMessageRawArgument(com.google.security.zynamics.binnavi.debug.connection.packets.arguments.DebugMessageRawArgument) MockEventListener(com.google.security.zynamics.binnavi.Debug.Debugger.MockEventListener) DebugCommand(com.google.security.zynamics.binnavi.debug.connection.packets.commands.DebugCommand) Test(org.junit.Test)

Example 10 with MockDebugger

use of com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger 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();
}
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)

Aggregations

MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)67 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)65 Test (org.junit.Test)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)47 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)20 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)18 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)18 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)17 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)16 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)16 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)16 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)16 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)16 ArrayList (java.util.ArrayList)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 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)11 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)10 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)9