Search in sources :

Example 51 with RelocatedAddress

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

the class CDebuggerSynchronizerTest method testEchoBreakpointSetErr.

@SuppressWarnings("unchecked")
@Test
public void testEchoBreakpointSetErr() throws DebugExceptionWrapper {
    mockDebugger.connect();
    breakpointManager.addBreakpoints(BreakpointType.ECHO, CommonTestObjects.BP_ADDRESS_123_SET);
    debuggerSynchronizer.receivedEvent(new EchoBreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 5))));
    assertEquals(0, breakpointManager.getNumberOfBreakpoints(BreakpointType.ECHO));
    assertEquals("ERROR_SET_ECHO_BREAKPOINT/00001123/5;", listener.events);
}
Also used : BigInteger(java.math.BigInteger) EchoBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) Test(org.junit.Test)

Example 52 with RelocatedAddress

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

the class CDebuggerSynchronizerTest method testStepBreakpointLifecycle.

/**
   * This test is used to determine whether the step breakpoint lifecycle (Set Step BP -> Hit Step
   * BP -> Remove Step BP) works correctly.
   *
   * @throws DebugExceptionWrapper Thrown if something goes wrong.
   */
@SuppressWarnings("unchecked")
@Test
public void testStepBreakpointLifecycle() throws DebugExceptionWrapper {
    mockDebugger.connect();
    final TargetProcessThread thread = new TargetProcessThread(0, ThreadState.RUNNING);
    mockDebugger.getProcessManager().addThread(thread);
    mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, CommonTestObjects.BP_ADDRESS_123_SET);
    mockDebugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, CommonTestObjects.BP_ADDRESS_456_SET);
    debuggerSynchronizer.receivedEvent(new StepBreakpointSetReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0), new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_456_RELOC, 0))));
    assertEquals(BreakpointStatus.BREAKPOINT_ACTIVE, mockDebugger.getBreakpointManager().getBreakpointStatus(CommonTestObjects.BP_ADDRESS_123, BreakpointType.STEP));
    assertEquals(BreakpointStatus.BREAKPOINT_ACTIVE, mockDebugger.getBreakpointManager().getBreakpointStatus(CommonTestObjects.BP_ADDRESS_456, BreakpointType.STEP));
    final RegisterValues registerValues = new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(0, Lists.newArrayList(new RegisterValue("esp", BigInteger.valueOf(0x123), new byte[0], true, false)))));
    debuggerSynchronizer.receivedEvent(new StepBreakpointHitReply(0, 0, 0, registerValues));
    listener.toString();
    assertTrue(Iterables.isEmpty(mockDebugger.getBreakpointManager().getBreakpoints(BreakpointType.STEP)));
    assertEquals(thread, mockDebugger.getProcessManager().getActiveThread());
    assertEquals(0x123, thread.getCurrentAddress().getAddress().toLong());
}
Also used : BigInteger(java.math.BigInteger) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) StepBreakpointSetReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) StepBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) Test(org.junit.Test)

Example 53 with RelocatedAddress

use of com.google.security.zynamics.binnavi.disassembly.RelocatedAddress 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());
}
Also used : ModuleUnloadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ThreadCreatedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ThreadCreatedReply) ModuleLoadedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleLoadedReply) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 54 with RelocatedAddress

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

the class CDebuggerSynchronizerTest method testEchoBreakpointRemoveSucc.

@SuppressWarnings("unchecked")
@Test
public void testEchoBreakpointRemoveSucc() throws DebugExceptionWrapper {
    mockDebugger.connect();
    breakpointManager.addBreakpoints(BreakpointType.ECHO, CommonTestObjects.BP_ADDRESS_123_SET);
    debuggerSynchronizer.receivedEvent(new EchoBreakpointsRemovedReply(0, 0, Lists.newArrayList(new Pair<RelocatedAddress, Integer>(CommonTestObjects.BP_ADDRESS_123_RELOC, 0))));
    assertEquals(0, breakpointManager.getNumberOfBreakpoints(BreakpointType.ECHO));
}
Also used : BigInteger(java.math.BigInteger) EchoBreakpointsRemovedReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) Test(org.junit.Test)

Example 55 with RelocatedAddress

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

the class CDebuggerFunctions method stepBlock.

/**
   * Lets the debugger step to the next block.
   *
   * @param parent Parent window used for dialogs.
   * @param debugger The debugger that steps to the next block.
   * @param graph The graph where the step operation happens.
   */
public static void stepBlock(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> relocatedBlockAddresses = CStepBlockHelper.getNextBlocks(graph, oldAddress);
    if (relocatedBlockAddresses.isEmpty()) {
        CMessageBox.showError(parent, "Couldn't step to the next block");
        return;
    } else {
        debugger.getProcessManager().setActiveThread(null);
        final Set<BreakpointAddress> setBreakpoints = new HashSet<BreakpointAddress>();
        debugger.getBreakpointManager().addBreakpoints(BreakpointType.STEP, relocatedBlockAddresses);
        setBreakpoints.addAll(relocatedBlockAddresses);
        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 = "E00045: " + "Could not send step block command to the debug client";
            final String innerDescription = CUtilityFunctions.createDescription("BinNavi could not send the step block 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) HashSet(java.util.HashSet)

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