Search in sources :

Example 1 with ThreadRegisters

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

the class EchoBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final EchoBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final long tid = reply.getThreadId();
    for (final ThreadRegisters threadRegisters : reply.getRegisterValues()) {
        if (tid == threadRegisters.getTid()) {
            for (final RegisterValue registerValue : threadRegisters) {
                if (registerValue.isPc()) {
                    final RelocatedAddress address = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    manager.setBreakpointStatus(Sets.newHashSet(DebuggerHelpers.getBreakpointAddress(getDebugger(), address)), BreakpointType.ECHO, BreakpointStatus.BREAKPOINT_HIT);
                    break;
                }
            }
        }
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 2 with ThreadRegisters

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

the class StepBreakpointHitSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final StepBreakpointHitReply reply) {
    final BreakpointManager manager = getDebugger().getBreakpointManager();
    final ProcessManager processManager = getDebugger().getProcessManager();
    RelocatedAddress breakpointAddress = 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()) {
                    breakpointAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                    break;
                }
            }
        }
    }
    manager.clearBreakpointsPassive(BreakpointType.STEP);
    try {
        final TargetProcessThread thread = processManager.getThread(tid);
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegisters.getRegisters());
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(breakpointAddress);
    } catch (final MaybeNullException exception) {
        // Apparently there is no thread with the specified TID.
        // This is not necessarily an error because the thread might have
        // been closed while this handler was active.
        // Nevertheless this should be logged.
        NaviLogger.info("Error: Process manager could not get thread. Exception %s", exception);
        return;
    }
}
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) BreakpointManager(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointManager) 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 3 with ThreadRegisters

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

the class TraceLoggerTest method testHits.

@Test
public void testHits() throws CouldntSaveDataException, DebugExceptionWrapper {
    m_mockDebugger.connect();
    final Trace trace = m_logger.start("Name", "Description", Lists.newArrayList(new TracePoint(m_mockModule, new Address(0x100)), new TracePoint(m_mockModule, new Address(0x100))));
    m_mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointHitReply(0, 0, 0, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(0, Lists.newArrayList(new RegisterValue("esp", BigInteger.valueOf(0x1100), new byte[0], true, false)))))));
    m_logger.stop();
    assertEquals("Name", trace.getName());
    assertEquals("Description", trace.getDescription());
    assertEquals(1, trace.getEvents().size());
    assertEquals(0x100, trace.getEvents().get(0).getAddress().toLong());
    assertEquals("TraceLogger [Debugger 'Mock' : Mock Module]", m_logger.toString());
}
Also used : Trace(com.google.security.zynamics.binnavi.API.disassembly.Trace) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) TracePoint(com.google.security.zynamics.binnavi.API.disassembly.TracePoint) 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 4 with ThreadRegisters

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

the class TraceLoggerTest method testHitsProject.

@Test
public void testHitsProject() throws CouldntSaveDataException, DebugExceptionWrapper {
    m_mockDebugger.connect();
    final Trace trace = m_projectLogger.start("Name", "Description", Lists.newArrayList(new TracePoint(m_mockModule, new Address(0x100))));
    m_mockDebugger.connection.m_synchronizer.receivedEvent(new EchoBreakpointHitReply(0, 0, 0, new RegisterValues(Lists.<ThreadRegisters>newArrayList(new ThreadRegisters(0, Lists.newArrayList(new RegisterValue("esp", BigInteger.valueOf(0x1100), new byte[0], true, false)))))));
    m_projectLogger.stop();
    assertEquals("Name", trace.getName());
    assertEquals("Description", trace.getDescription());
    assertEquals(1, trace.getEvents().size());
    assertEquals(0x100, trace.getEvents().get(0).getAddress().toLong());
    assertEquals("TraceLogger [Debugger 'Mock' : Mock Project]", m_projectLogger.toString());
}
Also used : Trace(com.google.security.zynamics.binnavi.API.disassembly.Trace) RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) EchoBreakpointHitReply(com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply) TracePoint(com.google.security.zynamics.binnavi.API.disassembly.TracePoint) 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 5 with ThreadRegisters

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

the class RegisterValuesParser method parse.

/**
   * Parses a byte array from the debug client into usable register information.
   *
   * @param data Byte array from the debug client.
   *
   * @return Usable register information.
   *
   * @throws IllegalArgumentException If the data argument is null.
   * @throws MessageParserException If parsing the message failed.
   */
public static RegisterValues parse(final byte[] data) throws MessageParserException {
    Preconditions.checkNotNull(data, "IE01299: Data argument can not be null");
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(new ByteArrayInputStream(data, 0, data.length));
        final NodeList nodes = document.getFirstChild().getChildNodes();
        final List<ThreadRegisters> threads = new ArrayList<>();
        for (int i = 0; i < nodes.getLength(); ++i) {
            final Node node = nodes.item(i);
            if (node.getNodeName().equals("Thread")) {
                threads.add(parseThreadNode(node));
            } else {
                throw new MessageParserException(String.format("IE01040: Invalid node '%s' found during register values message parsing", node.getNodeName()));
            }
        }
        return new RegisterValues(threads);
    } catch (IOException | ParserConfigurationException | SAXException exception) {
        CUtilityFunctions.logException(exception);
        throw new MessageParserException(exception.getLocalizedMessage());
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) RegisterValues(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)

Aggregations

ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)16 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)14 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)11 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)10 Test (org.junit.Test)10 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)9 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)9 BigInteger (java.math.BigInteger)7 EchoBreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointHitReply)5 StepBreakpointHitReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointHitReply)5 StepBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointSetReply)5 EchoBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply)4 EchoBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply)4 StepBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply)4 BreakpointConditionSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply)3 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)2 Trace (com.google.security.zynamics.binnavi.API.disassembly.Trace)2 TracePoint (com.google.security.zynamics.binnavi.API.disassembly.TracePoint)2 ExceptionOccurredReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.ExceptionOccurredReply)2 HaltReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.HaltReply)2