Search in sources :

Example 36 with RelocatedAddress

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

the class EchoBreakpointSetSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final EchoBreakpointSetReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final Set<BreakpointAddress> addressesToActivate = new HashSet<>();
    final Set<BreakpointAddress> addressesToRemove = new HashSet<>();
    for (final Pair<RelocatedAddress, Integer> resultPair : reply.getAddresses()) {
        final RelocatedAddress address = resultPair.first();
        if (resultPair.second() == 0) {
            addressesToActivate.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), address));
        } else {
            addressesToRemove.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), address));
        }
    }
    manager.setBreakpointStatus(addressesToActivate, BreakpointType.ECHO, BreakpointStatus.BREAKPOINT_ACTIVE);
    manager.removeBreakpointsPassive(BreakpointType.ECHO, addressesToRemove);
}
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 37 with RelocatedAddress

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

the class ReplySynchronizer method setRegisterValues.

/**
   * Updates the thread the register data belongs to with the new values.
   *
   * @param registerValues The new register values.
   */
protected void setRegisterValues(final RegisterValues registerValues) {
    Preconditions.checkNotNull(registerValues, "IE01046: Register values argument can not be null");
    final ProcessManager processManager = debugger.getProcessManager();
    for (final ThreadRegisters threadRegister : registerValues) {
        for (final TargetProcessThread thread : processManager.getThreads()) {
            if (thread.getThreadId() == threadRegister.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegister.getRegisters());
                for (final RegisterValue registerValue : threadRegister.getRegisters()) {
                    if (registerValue.isPc()) {
                        thread.setCurrentAddress(new RelocatedAddress(new CAddress(registerValue.getValue())));
                    }
                }
            }
        }
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) 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) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 38 with RelocatedAddress

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

the class StepBreakpointSetSynchronizer method handleSuccess.

/**
   * When a stepping breakpoint was set in the target process, its state is set to ACTIVE in the
   * breakpoint manager.
   */
@Override
protected void handleSuccess(final StepBreakpointSetReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final Set<BreakpointAddress> addressesToActivate = new HashSet<BreakpointAddress>();
    final Set<BreakpointAddress> addressesToRemove = new HashSet<BreakpointAddress>();
    for (final Pair<RelocatedAddress, Integer> resultPair : reply.getAddresses()) {
        final RelocatedAddress address = resultPair.first();
        if (resultPair.second() == DebuggerErrorCodes.SUCCESS) {
            addressesToActivate.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), address));
        } else {
            addressesToRemove.add(DebuggerHelpers.getBreakpointAddress(getDebugger(), address));
        }
    }
    manager.setBreakpointStatus(addressesToActivate, BreakpointType.STEP, BreakpointStatus.BREAKPOINT_ACTIVE);
    manager.removeBreakpoints(BreakpointType.STEP, addressesToRemove);
}
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 39 with RelocatedAddress

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

the class DebuggerTest method testListeners3.

@SuppressWarnings("unchecked")
@Test
public void testListeners3() throws MessageParserException, DebugExceptionWrapper, MaybeNullException {
    mockDebugger.connect();
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.getProcessManager().getThread(0).setCurrentAddress(new RelocatedAddress(new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeThreadReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ResumeThreadReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SearchReply(0, 0, new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SearchReply(0, 1, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SelectFileReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SelectFileReply(0, 1));
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.getProcessManager().getThread(0).setCurrentAddress(new RelocatedAddress(new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SetRegisterReply(0, 0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SetRegisterReply(0, 1, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SingleStepReply(0, 0, 0, new RelocatedAddress(new CAddress(0)), new RegisterValues(new FilledList<ThreadRegisters>())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SingleStepReply(0, 1, 0, new RelocatedAddress(new CAddress(0)), new RegisterValues(new FilledList<ThreadRegisters>())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], false, false)))))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointSetReply(0, 1, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new StepBreakpointsRemovedReply(0, 1, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SuspendThreadReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new SuspendThreadReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, TargetInformationParser.parse("<foo><size>32</size><registers></registers><options></options></foo>".getBytes())));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 1, null));
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(0, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadClosedReply(0, 0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadClosedReply(0, 1, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadCreatedReply(0, 0, 0, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ThreadCreatedReply(0, 1, 0, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ValidateMemoryReply(0, 0, new CAddress(0), new CAddress(0)));
    mockDebugger.connection.m_synchronizer.receivedEvent(new ValidateMemoryReply(0, 1, null, null));
    mockDebugger.connection.m_synchronizer.receivedEvent(new WriteMemoryReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new WriteMemoryReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TerminateReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new TerminateReply(0, 1));
}
Also used : SingleStepReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SingleStepReply) SetRegisterReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SetRegisterReply) ThreadClosedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadClosedReply) ValidateMemoryReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ValidateMemoryReply) StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) SearchReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SearchReply) TerminateReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TerminateReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) SelectFileReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SelectFileReply) SuspendThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.SuspendThreadReply) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) ResumeThreadReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ResumeThreadReply) WriteMemoryReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.WriteMemoryReply) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ThreadCreatedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadCreatedReply) Test(org.junit.Test)

Example 40 with RelocatedAddress

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

the class DebuggerTest method testListeners2.

@SuppressWarnings("unchecked")
@Test
public void testListeners2() throws DebugExceptionWrapper {
    final DebuggerListener listener = new DebuggerListener();
    debugger.addListener(listener);
    mockDebugger.connect();
    mockDebugger.getProcessManager().addThread(new TargetProcessThread(1, ThreadState.RUNNING));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointConditionSetReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new BreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 1))));
    mockDebugger.getBreakpointManager().removeBreakpoints(BreakpointType.REGULAR, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.connection.m_synchronizer.receivedEvent(new DebuggerClosedUnexpectedlyReply());
    mockDebugger.connection.m_synchronizer.receivedEvent(new DetachReply(0, 0));
    mockDebugger.connection.m_synchronizer.receivedEvent(new DetachReply(0, 1));
    mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], false, false)))))));
    mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointHitReply(0, 0, 1, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(1, Lists.newArrayList(new RegisterValue("eip", BigInteger.ONE, new byte[0], true, false)))))));
    debugger.removeListener(listener);
}
Also used : StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) BreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointSetReply) EchoBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) BreakpointConditionSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) BreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointHitReply) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) DetachReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply) EchoBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply) BreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointsRemovedReply) StepBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) DebuggerClosedUnexpectedlyReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.DebuggerClosedUnexpectedlyReply) Test(org.junit.Test)

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