Search in sources :

Example 46 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class ProcessStartParser method parse.

/**
   * Parses the byte stream containing the process start packet.
   *
   * @param data The raw data to be parsed.
   * @return The parsed process start object.
   * @throws MessageParserException Thrown if an error occurred while parsing.
   */
public static ProcessStart parse(final byte[] data) throws MessageParserException {
    Preconditions.checkNotNull(data, "IE00066: Data argument can not be null");
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    TargetProcessThread thread = null;
    MemoryModule module = 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 ("thread".equals(nodeName)) {
                thread = parseThreadInformation(node);
            } else if ("module".equals(nodeName)) {
                module = MemoryModuleParser.parseModule(node);
            } else {
                throw new MessageParserException(String.format("Found unknown node '%s' in process start string", nodeName));
            }
        }
    } catch (final Exception exception) {
        CUtilityFunctions.logException(exception);
        throw new MessageParserException(exception.getLocalizedMessage());
    }
    Preconditions.checkNotNull(thread, "IE01665: E00068: Received invalid process start string (missing thread information)");
    Preconditions.checkNotNull(module, "IE01668: E00069: Received invalid target process start string (missing module information)");
    return new ProcessStart(thread, module);
}
Also used : ProcessStart(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessStart) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) MemoryModule(com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 47 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class ProcessStartParser method parseThreadInformation.

/**
   * Parses the thread xml node.
   *
   * @param node The node containing the thread item.
   * @return The parsed thread object.
   * @throws MessageParserException Thrown if an error occurred while parsing.
   */
private static TargetProcessThread parseThreadInformation(final Node node) throws MessageParserException {
    final long id = Long.valueOf(getAttribute(node, "threadId"));
    final ThreadState state = convertThreadState(Integer.valueOf(getAttribute(node, "threadState")));
    return new TargetProcessThread(id, state);
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) ThreadState(com.google.security.zynamics.binnavi.debug.models.processmanager.ThreadState)

Example 48 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class BreakpointHitSynchronizer method handleSuccess.

/**
   * Handles incoming Breakpoint Hit replies.
   *
   * @param reply The incoming Breakpoint Hit reply to handle.
   */
@Override
protected void handleSuccess(final BreakpointHitReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    // When the debug client notifies BinNavi that a
    // breakpoint was hit, it is necessary to mark the
    // breakpoint as hit.
    // TODO: Check for success
    RelocatedAddress eventAddress = 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()) {
                    eventAddress = new RelocatedAddress(new CAddress(registerValue.getValue()));
                }
            }
        }
    }
    if (eventAddress != null) {
        updateHitBreakpoints(DebuggerHelpers.getBreakpointAddress(getDebugger(), eventAddress));
    } else {
        throw new IllegalStateException("IE00173: register reply did not include program counter");
    }
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getThreadId());
        // Update the thread with the new register values.
        for (final ThreadRegisters threadRegisters : registerValues) {
            if (tid == threadRegisters.getTid()) {
                thread.setRegisterValues(threadRegisters.getRegisters());
                break;
            }
        }
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(eventAddress);
    } catch (final MaybeNullException exception) {
        NaviLogger.info("Error: there is no thread with the specified thread id %d Exception: %s", reply.getThreadId(), exception);
    }
}
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) 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 49 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class ExceptionOccurredSynchronizer method handleSuccess.

@Override
protected void handleSuccess(final ExceptionOccurredReply reply) {
    final ProcessManager processManager = getDebugger().getProcessManager();
    try {
        final TargetProcessThread thread = processManager.getThread(reply.getThreadId());
        processManager.setActiveThread(thread);
        thread.setCurrentAddress(reply.getAddress());
        processManager.addExceptionEvent(new DebuggerException(reply.getExceptionName(), reply.getExceptionCode(), DebuggerExceptionHandlingAction.Continue));
        refreshRegisters();
    } catch (final MaybeNullException exception) {
        NaviLogger.severe("Exception occured in unknown thread %d", reply.getThreadId());
    }
}
Also used : TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) DebuggerException(com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerException) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)

Example 50 with TargetProcessThread

use of com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread in project binnavi by google.

the class ReplySynchronizer method setRegisterValues.

/**
   * Updates the thread the register data belongs to with the new values.
   *
   * @param registerValues The new register values.
   */
protected void setRegisterValues(final RegisterValues registerValues) {
    Preconditions.checkNotNull(registerValues, "IE01046: Register values argument can not be null");
    final ProcessManager processManager = debugger.getProcessManager();
    for (final ThreadRegisters threadRegister : registerValues) {
        for (final TargetProcessThread thread : processManager.getThreads()) {
            if (thread.getThreadId() == threadRegister.getTid()) {
                // Update the thread with the new register values.
                thread.setRegisterValues(threadRegister.getRegisters());
                for (final RegisterValue registerValue : threadRegister.getRegisters()) {
                    if (registerValue.isPc()) {
                        thread.setCurrentAddress(new RelocatedAddress(new CAddress(registerValue.getValue())));
                    }
                }
            }
        }
    }
}
Also used : RegisterValue(com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue) TargetProcessThread(com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread) RelocatedAddress(com.google.security.zynamics.binnavi.disassembly.RelocatedAddress) ThreadRegisters(com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters) ProcessManager(com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Aggregations

TargetProcessThread (com.google.security.zynamics.binnavi.debug.models.processmanager.TargetProcessThread)91 Test (org.junit.Test)50 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)27 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)22 TargetInformation (com.google.security.zynamics.binnavi.debug.models.targetinformation.TargetInformation)21 MockDebugger (com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger)20 ModuleTargetSettings (com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings)20 DebuggerOptions (com.google.security.zynamics.binnavi.debug.models.targetinformation.DebuggerOptions)20 MemoryMap (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryMap)19 MemorySection (com.google.security.zynamics.binnavi.debug.models.processmanager.MemorySection)18 RegisterDescription (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterDescription)17 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)16 TargetInformationReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.TargetInformationReply)15 ArrayList (java.util.ArrayList)15 MemoryMapReply (com.google.security.zynamics.binnavi.debug.connection.packets.replies.MemoryMapReply)14 RegisterValue (com.google.security.zynamics.binnavi.debug.models.targetinformation.RegisterValue)14 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)12 ProcessManager (com.google.security.zynamics.binnavi.debug.models.processmanager.ProcessManager)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)10 ThreadRegisters (com.google.security.zynamics.binnavi.debug.models.targetinformation.ThreadRegisters)9