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);
}
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);
}
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);
}
}
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());
}
}
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())));
}
}
}
}
}
}
Aggregations