Search in sources :

Example 26 with RegisterDescription

use of com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription in project binnavi by google.

the class CMemoryRefreshButtonSynchronizerTest method testReceiveTargetInformation.

@Test
public void testReceiveTargetInformation() throws DebugExceptionWrapper {
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    m_model.setActiveDebugger(debugger);
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, true, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    assertFalse(m_refreshButton.isEnabled());
    assertEquals(m_defaultAction, m_refreshButton.getAction());
    debugger.connection.m_synchronizer.receivedEvent(new TargetInformationReply(0, 0, new TargetInformation(32, new FilledList<RegisterDescription>(), new DebuggerOptions(false, false, false, false, false, false, false, false, false, false, 1, 0, new ArrayList<DebuggerException>(), false, false, false))));
    assertFalse(m_refreshButton.isEnabled());
    assertEquals(m_askAction, m_refreshButton.getAction());
    m_synchronizer.dispose();
    debugger.close();
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) Test(org.junit.Test)

Example 27 with RegisterDescription

use of com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription in project binnavi by google.

the class Debugger method writeRegister.

// ! Writes a register value.
/**
   * Changes the value of a register in the given thread.
   *
   * @param tid Thread ID of the thread whose register value is changed.
   * @param register Name of the register to change.
   * @param value The new value of the register.
   *
   * @throws DebugException Thrown if the message could not be sent to the debug client.
   */
public void writeRegister(final long tid, final String register, final long value) throws DebugException {
    Preconditions.checkNotNull(register, "Error: Register argument can not be null");
    Preconditions.checkNotNull(m_debugger.getProcessManager().getTargetInformation(), "Error: Target information string has not yet been received");
    final List<RegisterDescription> registers = m_debugger.getProcessManager().getTargetInformation().getRegisters();
    int index = 0;
    for (final RegisterDescription description : registers) {
        if (description.getName().equalsIgnoreCase(register)) {
            if (!description.isEditable()) {
                throw new IllegalArgumentException("Error: Selected register can not be edited");
            }
            break;
        }
        index++;
    }
    if (index == registers.size()) {
        throw new IllegalArgumentException("Error: Unknown register name");
    }
    try {
        m_debugger.setRegister(tid, index, BigInteger.valueOf(value));
    } catch (final DebugExceptionWrapper e) {
        throw new DebugException(e);
    }
}
Also used : RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) DebugExceptionWrapper(com.google.security.zynamics.binnavi.debug.debugger.DebugExceptionWrapper)

Example 28 with RegisterDescription

use of com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription 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 29 with RegisterDescription

use of com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription in project binnavi by google.

the class CRegisterProvider method setRegisterInformation.

/**
   * Updates the register information.
   *
   * @param information The new register information to display.
   */
public void setRegisterInformation(final List<RegisterValue> information) {
    Preconditions.checkNotNull(information, "IE01475: Information argument can not be null");
    if (!information.isEmpty() && (m_information == null)) {
        throw new IllegalStateException("IE01124: Can not set register values if no target information is given");
    }
    final RegisterInformationInternal[] oldRegisterInformation = registerInformation;
    final RegisterInformationInternal[] newRegisterInformation = new RegisterInformationInternal[information.size()];
    int counter = 0;
    if (!information.isEmpty()) {
        Preconditions.checkNotNull(m_information, "IE01125: Target information should not be null at this point");
        for (final RegisterValue registerValue : information) {
            final RegisterDescription regInfo = getDescription(registerValue.getName());
            Preconditions.checkNotNull(regInfo, "IE01476: Unknown register");
            newRegisterInformation[counter] = new RegisterInformationInternal(regInfo.getName(), regInfo.getSize());
            newRegisterInformation[counter].setValue(registerValue.getValue());
            // Make sure to highlight modified register values.
            highlightChangedRegister(counter, registerValue, oldRegisterInformation, newRegisterInformation);
            counter++;
        }
    }
    registerInformation = newRegisterInformation;
    notifyRegisterChanged();
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) RegisterInformationInternal(com.google.security.zynamics.zylib.gui.JRegisterView.RegisterInformationInternal) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)

Aggregations

RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)29 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)26 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)20 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)18 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)17 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)17 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)17 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)17 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)14 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)14 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)14 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)9 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)9 DebuggerException (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException)8 DetachReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.DetachReply)5 ModuleLoadedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleLoadedReply)4 ModuleUnloadedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ModuleUnloadedReply)4 ProcessStartReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ProcessStartReply)4