Search in sources :

Example 56 with RelocatedAddress

use of com.google.security.zynamics.binnavi.disassembly.RelocatedAddress in project binnavi by google.

the class CDebuggerFunctions method stepOver.

/**
   * Lets the debugger step over the next instruction.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps over the next instruction.
   * @param graph The graph where the step operation happens.
   */
public static void stepOver(final JFrame parent, final IDebugger debugger, final ZyGraph graph) {
    checkArguments(parent, debugger, graph);
    if (!debugger.isConnected()) {
        return;
    }
    final TargetProcessThread activeThread = debugger.getProcessManager().getActiveThread();
    if (activeThread == null) {
        return;
    }
    final RelocatedAddress currentAddress = activeThread.getCurrentAddress();
    if (currentAddress == null) {
        CMessageBox.showError(parent, "Could not step because the selected thread is not suspended");
        return;
    }
    final UnrelocatedAddress oldAddress = debugger.memoryToFile(currentAddress);
    final Set<BreakpointAddress> relocatedAddresses = CStepOverHelper.getNextInstructions(graph, oldAddress);
    if (relocatedAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step over the current instruction");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            // TODO: Step breakpoints should be removed at this point
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00087: " + "Could not send step over command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step over command to the debug client.", new String[] { "There was a problem with the connection to the debug client." }, new String[] { "The state of the debugged process remains unchanged." });
            NaviErrorDialog.show(parent, innerMessage, innerDescription, e);
        }
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Example 57 with RelocatedAddress

use of com.google.security.zynamics.binnavi.disassembly.RelocatedAddress in project binnavi by google.

the class CRelocationNotifier method collectWronglyPlacedModules.

/**
   * Finds wrongly relocated modules by comparing a snapshot of the modules in an address space
   * being reported by the debug client with those configured in
   * com.google.security.zynamics.binnavi.
   *
   * @param debugger The active debugger.
   * @param viewContainer The view container that is being debugged.
   * @param memoryModules The modules whose base addresses are checked.
   *
   * @return A list of wrongly relocated modules.
   */
private static List<Pair<INaviModule, MemoryModule>> collectWronglyPlacedModules(final IDebugger debugger, final IViewContainer viewContainer, final List<MemoryModule> memoryModules) {
    final List<Pair<INaviModule, MemoryModule>> wronglyPlacedModules = new ArrayList<Pair<INaviModule, MemoryModule>>();
    final List<INaviModule> modules = viewContainer.getModules();
    for (final INaviModule module : modules) {
        for (final MemoryModule memoryModule : memoryModules) {
            if (module.getConfiguration().getName().equalsIgnoreCase(memoryModule.getName())) {
                final RelocatedAddress assumedAddress = debugger.fileToMemory(module, new UnrelocatedAddress(module.getConfiguration().getFileBase()));
                final IAddress memoryAddress = memoryModule.getBaseAddress().getAddress();
                if (!assumedAddress.getAddress().equals(memoryAddress)) {
                    wronglyPlacedModules.add(new Pair<INaviModule, MemoryModule>(module, memoryModule));
                }
            }
        }
    }
    return wronglyPlacedModules;
}
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) ArrayList(java.util.ArrayList) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 58 with RelocatedAddress

use of com.google.security.zynamics.binnavi.disassembly.RelocatedAddress in project binnavi by google.

the class CRegisterMenuProvider method getRegisterMenu.

@Override
public JPopupMenu getRegisterMenu(final int registerNumber) {
    final IDebugger debugger = m_debugPerspectiveModel.getCurrentSelectedDebugger();
    if (debugger == null) {
        return null;
    }
    final JPopupMenu menu = new JPopupMenu();
    final BigInteger value = m_dataProvider.getRegisterInformation(registerNumber).getValue();
    menu.add(CActionProxy.proxy(new CCopyRegisterValueAction(value.toString(16).toUpperCase())));
    final MemorySection section = ProcessHelpers.getSectionWith(debugger.getProcessManager().getMemoryMap(), new CAddress(value));
    final JMenuItem gotoAddress = menu.add(CActionProxy.proxy(new CGotoOffsetAction(m_debugPerspectiveModel, new CAddress(value))));
    gotoAddress.setEnabled(section != null);
    if (containsAddress(m_debugPerspectiveModel.getGraphModel().getGraph().getRawView(), value.longValue())) {
        menu.add(CActionProxy.proxy(new CZoomToAddressAction(m_debugPerspectiveModel.getGraphModel().getGraph(), new CAddress(value), debugger.getModule(new RelocatedAddress(new CAddress(value))))));
    } else {
        final IViewContainer container = m_debugPerspectiveModel.getGraphModel().getViewContainer();
        menu.add(CActionProxy.proxy(new CSearchAction(m_debugPerspectiveModel.getGraphModel().getParent(), container, new CAddress(value))));
    }
    return menu;
}
Also used : CZoomToAddressAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CZoomToAddressAction) CCopyRegisterValueAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CCopyRegisterValueAction) IViewContainer(com.google.security.zynamics.binnavi.disassembly.views.IViewContainer) MemorySection(com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection) CGotoOffsetAction(com.google.security.zynamics.binnavi.Gui.Debug.RegisterPanel.Actions.CGotoOffsetAction) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BigInteger(java.math.BigInteger) CSearchAction(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CSearchAction) JMenuItem(javax.swing.JMenuItem) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) JPopupMenu(javax.swing.JPopupMenu) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 59 with RelocatedAddress

use of com.google.security.zynamics.binnavi.disassembly.RelocatedAddress in project binnavi by google.

the class CThreadEventSynchronizer method paintProgramCounter.

/**
   * Paints the program counter of a given thread into the graph.
   *
   * @param thread The graph whose PC is painted into the graph.
   */
private void paintProgramCounter(final TargetProcessThread thread) {
    if (thread == null) {
        CDebuggerPainter.clearDebuggerHighlighting(m_graph);
    } else {
        final RelocatedAddress address = thread.getCurrentAddress();
        if (address == null) {
            return;
        }
        CDebuggerPainter.updateDebuggerHighlighting(m_graph, m_debugger.memoryToFile(address), m_debugger.getModule(address));
    }
}
Also used : RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)

Aggregations

RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)59 Test (org.junit.Test)32 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)25 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)22 BigInteger (java.math.BigInteger)20 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)15 ArrayList (java.util.ArrayList)13 EchoBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply)12 EchoBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply)10 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)10 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)10 BreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointsRemovedReply)9 StepBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply)9 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)9 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)9 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)9 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)9 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)8 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)8 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)7