Search in sources :

Example 1 with RegisterValue

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

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

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

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

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

the class RegisterValuesParser method parseThreadNode.

/**
   * Parses a single thread node.
   *
   * @param node The node to parse.
   *
   * @return The thread registers object created from the content of the node.
   *
   * @throws MessageParserException Thrown if parsing the thread node failed.
   */
private static ThreadRegisters parseThreadNode(final Node node) throws MessageParserException {
    final List<RegisterValue> registerValues = new ArrayList<>();
    final long tid = Long.valueOf(node.getAttributes().getNamedItem("id").getNodeValue());
    final NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        final Node child = children.item(i);
        final String registerName = getAttribute(child, "name");
        final BigInteger registerValue = new BigInteger(getAttribute(child, "value"), 16);
        final byte[] memory = MemoryStringParser.parseMemoryString(getAttribute(child, "memory"));
        final boolean isPc = hasAttribute(child, "pc");
        final boolean isSp = hasAttribute(child, "sp");
        registerValues.add(new RegisterValue(registerName, registerValue, memory, isPc, isSp));
    }
    return new ThreadRegisters(tid, registerValues);
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)

Aggregations

RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)22 Test (org.junit.Test)16 TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)14 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)13 RegisterValues (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValues)9 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)9 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)6 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)6 BigInteger (java.math.BigInteger)6 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 StepBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.StepBreakpointsRemovedReply)4 BreakpointConditionSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.BreakpointConditionSetReply)3 EchoBreakpointSetReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointSetReply)3 EchoBreakpointsRemovedReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.EchoBreakpointsRemovedReply)3 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)3 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)3 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)3