Search in sources :

Example 11 with RegisterDescription

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

the class CMemoryRefreshButtonSynchronizerTest method testSwitchDebugger.

@Test
public void testSwitchDebugger() throws DebugExceptionWrapper {
    final TargetProcessThread thread = new TargetProcessThread(0x666, ThreadState.RUNNING);
    final MemoryModule module = new MemoryModule("narf.exe", "C:\\zort\\narf.exe", new RelocatedAddress(new CAddress(0x1000)), 123345);
    final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger.connect();
    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))));
    debugger.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    final MockDebugger debugger2 = new MockDebugger(new ModuleTargetSettings(CommonTestObjects.MODULE));
    debugger2.connect();
    debugger2.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))));
    debugger2.connection.m_synchronizer.receivedEvent(new ProcessStartReply(0, 0, new ProcessStart(thread, module)));
    m_model.setActiveDebugger(debugger);
    debugger.getProcessManager().setActiveThread(thread);
    assertTrue(m_refreshButton.isEnabled());
    assertEquals(m_defaultAction, m_refreshButton.getAction());
    m_model.setActiveDebugger(debugger2);
    debugger2.getProcessManager().setActiveThread(thread);
    assertTrue(m_refreshButton.isEnabled());
    assertEquals(m_askAction, m_refreshButton.getAction());
    m_synchronizer.dispose();
    debugger.close();
    debugger2.close();
}
Also used : ProcessStart(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessStart) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ArrayList(java.util.ArrayList) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) ProcessStartReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.ProcessStartReply) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) 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) TargetInformationReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply) Test(org.junit.Test)

Example 12 with RegisterDescription

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

the class TargetInformationParser method parseRegisterInformation.

/**
   * Parses register information from the target information string.
   *
   * @param node The root node of the registers information.
   *
   * @return Parsed register description information.
   *
   * @throws MessageParserException Thrown if parsing the information failed.
   */
private static List<RegisterDescription> parseRegisterInformation(final Node node) throws MessageParserException {
    final List<RegisterDescription> registers = new ArrayList<>();
    final NodeList nodes = node.getChildNodes();
    for (int i = 0; i < nodes.getLength(); ++i) {
        final Node child = nodes.item(i);
        final String registerName = getAttribute(child, "name");
        final String registerSize = getAttribute(child, "size");
        final String registerEditable = getAttribute(child, "editable");
        registers.add(new RegisterDescription(registerName, Integer.valueOf(registerSize), Boolean.valueOf(registerEditable)));
    }
    return registers;
}
Also used : RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 13 with RegisterDescription

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

the class TargetInformationParser method parse.

/**
   * Parses a target information message and creates Java objects from the information found in the
   * message.
   *
   * @param data The byte array that contains the target information.
   * @return The usable object that contains the target information.
   * @throws IllegalArgumentException If the data argument is null.
   * @throws MessageParserException If parsing goes wrong.
   */
public static TargetInformation parse(final byte[] data) throws MessageParserException {
    Preconditions.checkNotNull(data, "IE01300: Data argument can not be null");
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    int addressSize = -1;
    List<RegisterDescription> registers = null;
    DebuggerOptions options = null;
    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(new ByteArrayInputStream(data, 0, data.length));
        final NodeList nodes = document.getFirstChild().getChildNodes();
        for (int i = 0; i < nodes.getLength(); ++i) {
            final Node node = nodes.item(i);
            final String nodeName = node.getNodeName();
            if ("registers".equals(nodeName)) {
                registers = parseRegisterInformation(node);
            } else if ("size".equals(nodeName)) {
                addressSize = Integer.valueOf(node.getTextContent());
            } else if ("options".equals(nodeName)) {
                options = parseOptionsInformation(node);
            } else {
                throw new MessageParserException(String.format("Found unknown node '%s' in target information string", nodeName));
            }
        }
    } catch (final ParserConfigurationException | SAXException | IOException exception) {
        CUtilityFunctions.logException(exception);
        throw new MessageParserException(exception.getLocalizedMessage());
    }
    if (addressSize == -1) {
        throw new MessageParserException("E00070: IE01043: Received invalid target information string (missing address size information)");
    }
    Preconditions.checkNotNull(registers, "IE01044: Received invalid target information string (missing registers information)");
    Preconditions.checkNotNull(options, "IE01046: Received invalid target information string (missing options information)");
    return new TargetInformation(addressSize, registers, options);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DebuggerOptions(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) TargetInformation(com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with RegisterDescription

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

the class DebuggerTest method writeRegister4.

@Test(expected = IllegalArgumentException.class)
public void writeRegister4() throws DebugException {
    debugger.connect();
    debugger.getNative().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)));
    debugger.writeRegister(0, "ebx", 0);
}
Also used : RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) 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) Test(org.junit.Test)

Example 15 with RegisterDescription

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

the class DebuggerTest method writeRegister5.

@Test(expected = IllegalArgumentException.class)
public void writeRegister5() throws DebugException {
    debugger.connect();
    debugger.getNative().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)));
    debugger.writeRegister(0, "ecx", 0);
}
Also used : RegisterDescription(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription) 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) Test(org.junit.Test)

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