Search in sources :

Example 46 with MockDebugger

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

the class CMemorySectionPanelSynchronizerTest method testSwitchDebugger.

@Test
public void testSwitchDebugger() throws DebugExceptionWrapper {
    final MemorySection section1 = new MemorySection(new CAddress(0x100), new CAddress(0x1FF));
    final MemorySection section2 = new MemorySection(new CAddress(0x300), new CAddress(0x3FF));
    final MemoryMap memoryMap = new MemoryMap(Lists.newArrayList(section1, section2));
    final TargetProcessThread thread = new TargetProcessThread(0x666, ThreadState.RUNNING);
    final MemoryModule module = new MemoryModule("narf.exe", "C:\\zort\\narf.exe", new RelocatedAddress(new CAddress(0x1000)), 123345);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, true, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    debugger.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 0, memoryMap));
    debugger.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    final MockDebugger debugger2 = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger2.connect();
    debugger2.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    debugger2.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 0, memoryMap));
    debugger2.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    m_model.setActiveDebugger(debugger);
    assertTrue(m_sectionBox.isEnabled());
    m_model.setActiveDebugger(debugger2);
    assertFalse(m_sectionBox.isEnabled());
    m_synchronizer.dispose();
    debugger.close();
    debugger2.close();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) ProcessStart(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessStart) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MemoryMapReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ProcessStartReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ProcessStartReply) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) Test(org.junit.Test)

Example 47 with MockDebugger

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

the class CMemorySectionPanelSynchronizerTest method testDetach.

@Test
public void testDetach() throws DebugExceptionWrapper {
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    final TargetProcessThread thread = new TargetProcessThread(1, ThreadState.SUSPENDED);
    debugger.getProcessManager().addThread(thread);
    debugger.getProcessManager().setActiveThread(thread);
    debugger.connect();
    m_model.setActiveDebugger(debugger);
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, true, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    final MemorySection section1 = new MemorySection(new CAddress(0x100), new CAddress(0x1FF));
    final MemorySection section2 = new MemorySection(new CAddress(0x300), new CAddress(0x3FF));
    final MemoryMap memoryMap = new MemoryMap(Lists.newArrayList(section1, section2));
    debugger.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 0, memoryMap));
    assertEquals(2, m_sectionBox.getItemCount());
    assertEquals(section1, m_sectionBox.getItemAt(0).getObject());
    assertEquals(section2, m_sectionBox.getItemAt(1).getObject());
    assertTrue(m_sectionBox.isEnabled());
    debugger.connection.m_synchronizer.receivedEvent(new DetachReply(0, 0));
    assertEquals(0, m_sectionBox.getItemCount());
    assertFalse(m_sectionBox.isEnabled());
    m_synchronizer.dispose();
    debugger.close();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) MemoryMapReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) 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) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) DetachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) Test(org.junit.Test)

Example 48 with MockDebugger

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

the class CModulesPanelTest method testLifeCycle.

@Test
public void testLifeCycle() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    final CDebugPerspectiveModel model = new CDebugPerspectiveModel(new MockGraphModel());
    model.setActiveDebugger(debugger);
    final CModulesPanel panel = new CModulesPanel(model);
    panel.dispose();
    final LinkedHashSet<?> debuggerListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "synchronizer"), "listeners"), "m_listeners");
    final LinkedHashSet<?> processListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "processManager"), "listeners"), "m_listeners");
    // The debugger only has one internal memory synchronizer
    assertEquals(1, debuggerListeners.size());
    // The process manager only has one thread state synchronizer
    assertEquals(1, processListeners.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) AbstractDebugger(com.google.security.zynamics.binnavi.debug.debugger.AbstractDebugger) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MockGraphModel(com.google.security.zynamics.binnavi.Gui.GraphWindows.MockGraphModel) Test(org.junit.Test)

Example 49 with MockDebugger

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

the class CModulesTableModelSynchronizerTest method testModuleLifecycle.

@Test
public void testModuleLifecycle() throws DebugExceptionWrapper, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    m_model.setActiveDebugger(debugger);
    assertEquals(0, m_tableModel.getRowCount());
    final MemoryModule module = new MemoryModule("Hannes", "C:\\Hannes.dll", new RelocatedAddress(new CAddress(0x100)), 0x200);
    debugger.connection.m_synchronizer.receivedEvent(new ModuleLoadedReply(0, 0, module, new TargetProcessThread(123, ThreadState.SUSPENDED)));
    assertEquals(1, m_tableModel.getRowCount());
    assertEquals("Hannes", m_tableModel.getValueAt(0, 0));
    assertEquals("00000100", m_tableModel.getValueAt(0, 1));
    assertEquals(0x200L, m_tableModel.getValueAt(0, 2));
    debugger.getProcessManager().setTargetInformation(new TargetInformation(5, Lists.newArrayList(new RegisterDescription("eax", 4, true), new RegisterDescription("ebx", 4, false)), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 12, 0, new ArrayList<DebuggerException>(), false, false, false)));
    debugger.connection.m_synchronizer.receivedEvent(new ModuleUnloadedReply(0, 0, module));
    assertEquals(0, m_tableModel.getRowCount());
    m_synchronizer.dispose();
    debugger.close();
    final LinkedHashSet<?> debuggerListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "synchronizer"), "listeners"), "m_listeners");
    final LinkedHashSet<?> processListeners = (LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ReflectionHelpers.getField(AbstractDebugger.class, debugger, "processManager"), "listeners"), "m_listeners");
    // The debugger only has one internal memory synchronizer
    assertEquals(1, debuggerListeners.size());
    // The process manager only has one thread state synchronizer
    assertEquals(1, processListeners.size());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) ModuleLoadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleLoadedReply) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) ModuleUnloadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) AbstractDebugger(com.google.security.zynamics.binnavi.debug.debugger.AbstractDebugger) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) Test(org.junit.Test)

Example 50 with MockDebugger

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

the class CStackViewSynchronizerTest method testNewThread.

/**
   * This test makes sure that freshly created threads have listeners attached.
   *
   * Test for 2035: Listener issue in the stack view synchronizer
   *
   * @throws DebugExceptionWrapper
   */
@Test
public void testNewThread() throws DebugExceptionWrapper {
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    debugger.getProcessManager().setAttached(true);
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, true, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    final MemorySection section1 = new MemorySection(new CAddress(0x100), new CAddress(0x1FF));
    final MemorySection section2 = new MemorySection(new CAddress(0x300), new CAddress(0x3FF));
    final MemoryMap memoryMap = new MemoryMap(Lists.newArrayList(section1, section2));
    debugger.connection.m_synchronizer.receivedEvent(new MemoryMapReply(0, 0, memoryMap));
    m_model.setActiveDebugger(debugger);
    final TargetProcessThread thread = new TargetProcessThread(1, ThreadState.RUNNING);
    debugger.getProcessManager().addThread(thread);
    m_synchronizer.dispose();
    debugger.close();
}
Also used : MemoryMap(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MemoryMapReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) 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) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) 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