Search in sources :

Example 31 with RelocatedAddress

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

the class BreakpointHitSynchronizer method handleSuccess.

/**
   * Handles incoming Breakpoint Hit replies.
   *
   * @param reply The incoming Breakpoint Hit reply to handle.
   */
@Override
protected void handleSuccess(final BreakpointHitReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    // When the debug client notifies BinNavi that a
    // breakpoint was hit, it is necessary to mark the
    // breakpoint as hit.
    // TODO: Check for success
    RelocatedAddress eventAddress = null;
    final RegisterValues registerValues = reply.getRegisterValues();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : registerValues) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    eventAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                }
            }
        }
    }
    if (eventAddress != null) {
        updateHitBreakpoints(DebuggerHelpers.getBreakpointAddress(getDebugger(), eventAddress));
    } else {
        throw new IllegalStateException("IE00173: register reply did not include program counter");
    }
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getThreadId());
        // Update the thread with the new register values.
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                thread.setRegisterValues(threadRegisters.getRegisters());
                break;
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(eventAddress);
    } catch (final MaybeNullException exception) {
        NaviLogger.info("Error: there is no thread with the specified thread id %d Exception: %s", reply.getThreadId(), exception);
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 32 with RelocatedAddress

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

the class BreakpointRemovedSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final BreakpointsRemovedReply reply) {
    // If a breakpoint was removed from the target process, it can be removed
    // from the breakpoint manager too unless the breakpoint is set to disabled
    // there.
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final Set<BreakpointAddress> addressesToRemove = new HashSet<>();
    final Set<BreakpointAddress> addressesToInvalidate = new HashSet<>();
    for (final Pair<RelocatedAddress, Integer> resultPair : reply.getAddresses()) {
        if (resultPair.second() == 0) {
            final BreakpointAddress address = DebuggerHelpers.getBreakpointAddress(getDebugger(), resultPair.first());
            if (manager.getBreakpointStatus(address, BreakpointType.REGULAR) == BreakpointStatus.BREAKPOINT_DELETING) {
                addressesToRemove.add(address);
            }
        } else {
            addressesToInvalidate.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), resultPair.first()));
        }
    }
    manager.removeBreakpointsPassive(BreakpointType.REGULAR, addressesToRemove);
    manager.setBreakpointStatus(addressesToInvalidate, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_INVALID);
}
Also used : RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) HashSet(java.util.HashSet)

Example 33 with RelocatedAddress

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

the class BreakpointSetSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final BreakpointSetReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final Set<BreakpointAddress> addressesToActivate = new HashSet<>();
    final Set<BreakpointAddress> addressesToInvalidate = new HashSet<>();
    for (final Pair<RelocatedAddress, Integer> resultPair : reply.getAddresses()) {
        if (resultPair.second() == 0) {
            // If a breakpoint was successfully set in the target process, its status is
            // set to ACTIVE in the breakpoint manager.
            final BreakpointAddress breakpointAddress = DebuggerHelpers.getBreakpointAddress(getDebugger(), resultPair.first());
            if (manager.getBreakpointStatus(breakpointAddress, BreakpointType.REGULAR) != BreakpointStatus.BREAKPOINT_DISABLED) {
                addressesToActivate.add(breakpointAddress);
            }
        } else {
            // If a breakpoint could not be set in the target process, its status in the
            // breakpoint manager is set to INVALID. The real status of the breakpoint
            // is unknown though.
            addressesToInvalidate.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), resultPair.first()));
        }
    }
    manager.setBreakpointStatus(addressesToInvalidate, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_INVALID);
    manager.setBreakpointStatus(addressesToActivate, BreakpointType.REGULAR, BreakpointStatus.BREAKPOINT_ACTIVE);
}
Also used : RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) HashSet(java.util.HashSet)

Example 34 with RelocatedAddress

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

the class StepBreakpointRemovedParser method parseSuccess.

@Override
public StepBreakpointsRemovedReply parseSuccess(final int packetId, final int argumentCount) throws IOException {
    final List<Pair<RelocatedAddress, Integer>> addresses = new ArrayList<>();
    for (int i = 0; i < parseInteger(); i++) {
        final RelocatedAddress address = new RelocatedAddress(parseAddress());
        addresses.add(new Pair<RelocatedAddress, Integer>(address, parseInteger()));
    }
    return new StepBreakpointsRemovedReply(packetId, 0, addresses);
}
Also used : StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 35 with RelocatedAddress

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

the class StepBreakpointSetParser method parseSuccess.

@Override
public StepBreakpointSetReply parseSuccess(final int packetId, final int argumentCount) throws IOException {
    final List<Pair<RelocatedAddress, Integer>> addresses = new ArrayList<>();
    final int numberOfAddresses = parseInteger();
    for (int i = 0; i < numberOfAddresses; i++) {
        final RelocatedAddress address = new RelocatedAddress(parseAddress());
        addresses.add(new Pair<RelocatedAddress, Integer>(address, parseInteger()));
    }
    return new StepBreakpointSetReply(packetId, 0, addresses);
}
Also used : StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) Pair(com.google.security.zynamics.zylib.general.Pair)

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