Search in sources :

Example 16 with MemoryModule

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule 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 17 with MemoryModule

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule 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 18 with MemoryModule

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule in project binnavi by google.

the class CCodeNodeUpdater method generateContent.

@Override
public void generateContent(final IZyNodeRealizer realizer, final ZyLabelContent content) {
    ZyCodeNodeBuilder.buildContent(content, codeNode, graph.getSettings(), nodeModifier);
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        final INaviModule module = instruction.getModule();
        if ((provider != null) && (provider.getDebugger(module) != null) && graph.getSettings().getDisplaySettings().getShowMemoryAddresses(provider.getDebugger(module))) {
            final int line = CCodeNodeHelpers.instructionToLine(codeNode, instruction);
            if (line != -1) {
                final ZyLineContent lineContent = this.realizer.getNodeContent().getLineContent(line);
                // TODO(timkornau) x64
                lineContent.setTextColor(0, 8, Color.RED);
            }
        }
    }
    // Set highlighting for breakpoints and the instruction pointer.
    final INaviInstruction instruction = codeNode.getInstructions().iterator().next();
    if (instruction != null) {
        final INaviModule module = instruction.getModule();
        final IDebugger debugger = provider.getDebugger(module);
        if (debugger == null) {
            return;
        }
        final BreakpointManager manager = debugger.getBreakpointManager();
        CBreakpointPainter.paintBreakpoints(manager, node, codeNode);
        if (debugger.getProcessManager().getActiveThread() != null) {
            final RelocatedAddress instructionPointer = debugger.getProcessManager().getActiveThread().getCurrentAddress();
            final MemoryModule memoryModule = debugger.getProcessManager().getModule(instructionPointer);
            final UnrelocatedAddress unrelocatedIP = new DefaultAddressConverter(memoryModule.getBaseAddress().getAddress(), module.getConfiguration().getFileBase()).memoryToFile(instructionPointer);
            CDebuggerPainter.updateSingleNodeDebuggerHighlighting(graph, unrelocatedIP, node);
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DefaultAddressConverter(com.google.security.zynamics.binnavi.debug.debugger.DefaultAddressConverter) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 19 with MemoryModule

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule in project binnavi by google.

the class CDebuggerSynchronizerTest method testModuleLifecycle.

/**
   * This test makes sure that the memory module lifecycle (Module Loaded -> Module Unloaded) is
   * working and that the process manager of the debugger is updated correctly.
   *
   * @throws DebugExceptionWrapper
   */
@Test
public void testModuleLifecycle() throws DebugExceptionWrapper {
    assertTrue(mockDebugger.getProcessManager().getModules().isEmpty());
    mockDebugger.connect();
    mockDebugger.getProcessManager().getThreads().clear();
    debuggerSynchronizer.receivedEvent(new ThreadCreatedReply(0, 0, 1000, ThreadState.RUNNING));
    final MemoryModule module = new MemoryModule("hannes.dll", "C:\\hannes.dll", new RelocatedAddress(new CAddress(0x1000000)), 1000);
    debuggerSynchronizer.receivedEvent(new ModuleLoadedReply(0, 0, module, new TargetProcessThread(1000, ThreadState.RUNNING)));
    mockDebugger.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)));
    assertTrue(mockDebugger.getProcessManager().getModules().size() == 1);
    assertTrue(mockDebugger.getProcessManager().getModules().get(0) == module);
    debuggerSynchronizer.receivedEvent(new ModuleUnloadedReply(0, 0, module));
    assertTrue(mockDebugger.getProcessManager().getModules().isEmpty());
}
Also used : ModuleUnloadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ThreadCreatedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadCreatedReply) 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) Test(org.junit.Test)

Example 20 with MemoryModule

use of com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule in project binnavi by google.

the class CRelocationNotifier method checkBaseAddresses.

/**
   * Tests the correctness of the base addresses of memory modules and displays corrected base
   * addresses to the user.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The active debugger.
   * @param viewContainer The view container that is being debugged.
   * @param memoryModules The modules whose base addresses are checked.
   */
public static void checkBaseAddresses(final JFrame parent, final IDebugger debugger, final IViewContainer viewContainer, final List<MemoryModule> memoryModules) {
    final List<Pair<INaviModule, MemoryModule>> wronglyPlacedModules = collectWronglyPlacedModules(debugger, viewContainer, memoryModules);
    if (!wronglyPlacedModules.isEmpty()) {
        for (final Pair<INaviModule, MemoryModule> pair : wronglyPlacedModules) {
            final INaviModule module = pair.first();
            final MemoryModule memoryModule = pair.second();
            final List<INaviAddressSpace> addressSpaces = viewContainer.getAddressSpaces();
            if (addressSpaces == null) {
                try {
                    module.getConfiguration().setImageBase(memoryModule.getBaseAddress().getAddress());
                } catch (final CouldntSaveDataException e) {
                    CUtilityFunctions.logException(e);
                }
            } else {
                for (final INaviAddressSpace addressSpace : addressSpaces) {
                    if (addressSpace.getContent().getModules().contains(module)) {
                        try {
                            addressSpace.getContent().setImageBase(module, memoryModule.getBaseAddress().getAddress());
                        } catch (final CouldntSaveDataException e) {
                            CUtilityFunctions.logException(e);
                        }
                    }
                }
            }
        }
    }
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) Pair(com.google.security.zynamics.zylib.general.Pair) INaviAddressSpace(com.google.security.zynamics.binnavi.disassembly.INaviAddressSpace)

Aggregations

MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)21 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)15 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)13 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)12 Test (org.junit.Test)12 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)10 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)9 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)9 ArrayList (java.util.ArrayList)8 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)7 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)7 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)7 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)6 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)6 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)6 ProcessStart (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessStart)5 DebuggerException (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException)5 ModuleLoadedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleLoadedReply)4 ModuleUnloadedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply)4 ProcessStartReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ProcessStartReply)3