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();
}
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());
}
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);
}
}
}
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());
}
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);
}
}
}
}
}
}
}
Aggregations