Search in sources :

Example 36 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CGraphDebugger method removeBreakpoint.

/**
   * Removes a breakpoint from the given address.
   *
   * @param manager The breakpoint manager that sets the breakpoint.
   * @param module The module where the breakpoint was set.
   * @param unrelocatedAddress The unrelocated address of the breakpoint.
   */
public static void removeBreakpoint(final BreakpointManager manager, final INaviModule module, final UnrelocatedAddress unrelocatedAddress) {
    Preconditions.checkNotNull(manager, "IE01710: Breakpoint manager argument can not be null");
    Preconditions.checkNotNull(module, "IE01711: Module argument can not be null");
    Preconditions.checkNotNull(unrelocatedAddress, "IE01712: Address argument can not be null");
    final BreakpointAddress address = new BreakpointAddress(module, unrelocatedAddress);
    if (manager.hasBreakpoint(BreakpointType.REGULAR, address)) {
        removeBreakpoints(Sets.newHashSet(address), manager);
    }
}
Also used : BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)

Example 37 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CGraphDebugger method removeBreakpoints.

/**
   * Removes a breakpoint from a breakpoint manager.
   *
   * @param addresses The address of the breakpoint to remove.
   * @param manager The breakpoint manager from where the breakpoint is removed.
   */
public static void removeBreakpoints(final Set<BreakpointAddress> addresses, final BreakpointManager manager) {
    Preconditions.checkNotNull(manager, "IE01708: Manager argument can not be null");
    Preconditions.checkNotNull(addresses, "IE01709: Address argument can not be null");
    final Set<BreakpointAddress> addressesToRemoveFromManager = new HashSet<BreakpointAddress>();
    final Set<BreakpointAddress> addressesToRemoveFromDebugger = new HashSet<BreakpointAddress>();
    for (final BreakpointAddress address : addresses) {
        final BreakpointStatus status = manager.getBreakpointStatus(address, BreakpointType.REGULAR);
        if ((status == BreakpointStatus.BREAKPOINT_DISABLED) || (status == BreakpointStatus.BREAKPOINT_INACTIVE)) {
            addressesToRemoveFromManager.add(address);
        }
        if (status != BreakpointStatus.BREAKPOINT_DELETING) {
            addressesToRemoveFromDebugger.add(address);
        }
    }
    if (addressesToRemoveFromManager.size() != 0) {
        manager.removeBreakpoints(BreakpointType.REGULAR, addressesToRemoveFromManager);
    }
    if (addressesToRemoveFromDebugger.size() != 0) {
        manager.setBreakpointStatus(addressesToRemoveFromDebugger, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_DELETING);
    }
}
Also used : BreakpointStatus(com.google.security.zynamics.binnavi.debug.models.breakpoints.enums.BreakpointStatus) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) HashSet(java.util.HashSet)

Example 38 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CDebuggerFunctions method stepEnd.

/**
   * Lets the debugger step to the end of the function.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps to the end of the function.
   * @param graph The graph where the step operation happens.
   */
public static void stepEnd(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 Set<BreakpointAddress> relocatedBlockAddresses = CStepEndHelper.getEndAddresses(graph);
    if (relocatedBlockAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step to the end of the function");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
        try {
            debugger.resume();
        } catch (final DebugExceptionWrapper e) {
            debugger.getBreakpointManager().removeBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
            debugger.getProcessManager().setActiveThread(activeThread);
            CUtilityFunctions.logException(e);
            final String innerMessage = "E00086: " + "Could not send step end command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step end 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) 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 39 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CSteppingHelper method getAddress.

/**
   * Determines the start address of a node.
   *
   * @param node Node whose address is determined.
   *
   * @return The start address of the given node or null if the node does not have an address.
   */
private static BreakpointAddress getAddress(final INaviViewNode node) {
    if (node instanceof INaviCodeNode) {
        final INaviCodeNode ccnode = (INaviCodeNode) node;
        final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
        return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
    } else if (node instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node).getFunction();
        final INaviModule module = function.getModule();
        return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
    } else {
        // Node types we can not step to
        return null;
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 40 with BreakpointAddress

use of com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress in project binnavi by google.

the class CBreakpointFunctionsTest method test6removeFunctions.

@Test
public void test6removeFunctions() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
    final MockFunction mockFunction = new MockFunction();
    final INaviModule mockModule = mockFunction.getModule();
    CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), mockFunction);
    final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
    debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234)))));
    @SuppressWarnings("unused") final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234))));
    debuggerProvider.addDebugger(debugger);
    final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
    assertEquals(1, tableModel.getRowCount());
    final IFilledList<Pair<IDebugger, INaviFunction>> targets = new FilledList<Pair<IDebugger, INaviFunction>>();
    final Pair<IDebugger, INaviFunction> targetPair = new Pair<IDebugger, INaviFunction>(debugger, mockFunction);
    targets.add(targetPair);
    assertEquals(1, targets.size());
    CBreakpointRemoveFunctions.removeBreakpoints(targets);
    @SuppressWarnings("unused") final BreakpointManager manager = debugger.getBreakpointManager();
    assertEquals(0, tableModel.getRowCount());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) Breakpoint(com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) IFilledList(com.google.security.zynamics.zylib.types.lists.IFilledList) CBreakpointTableModel(com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) IDebugger(com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Pair(com.google.security.zynamics.zylib.general.Pair) Test(org.junit.Test)

Aggregations

BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)87 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)60 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)49 Test (org.junit.Test)39 HashSet (java.util.HashSet)24 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)22 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)15 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)15 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)15 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)13 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)11 BreakpointManager (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager)11 TraceList (com.google.security.zynamics.binnavi.debug.models.trace.TraceList)11 ArrayList (java.util.ArrayList)9 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)8 DebugTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings)8 DebuggerProvider (com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider)8 CBreakpointTableModel (com.google.security.zynamics.binnavi.Gui.Debug.BreakpointTable.CBreakpointTableModel)7 TraceLogger (com.google.security.zynamics.binnavi.debug.models.trace.TraceLogger)7 ITraceEvent (com.google.security.zynamics.binnavi.debug.models.trace.interfaces.ITraceEvent)7