use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class PostgreSQLTypeFunctions method loadRawTypeSubstitutions.
/**
* Loads all {@link RawTypeSubstitution} for the given module from the database.
*
* @param connection The {@link Connection} to access the database with.
* @param module The {@link INaviModule} to load the {@link RawTypeSubstitution} for.
*
* @return The {@link List} of {@link RawTypeSubstitution} for the given {@link INaviModule}.
*
* @throws CouldntLoadDataException if the {@link RawTypeSubstitution} could not be loaded from
* the database.
*/
public static List<RawTypeSubstitution> loadRawTypeSubstitutions(final Connection connection, final INaviModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(connection, "Error: connection argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
final String query = " SELECT * FROM load_type_substitutions(?) ";
final List<RawTypeSubstitution> rawSubstitutions = new ArrayList<RawTypeSubstitution>();
try {
final PreparedStatement statement = connection.prepareStatement(query);
statement.setInt(1, module.getConfiguration().getId());
final ResultSet results = statement.executeQuery();
try {
while (results.next()) {
final long address = results.getLong("address");
final int position = results.getInt("position");
final int expressionId = results.getInt("expression_id");
final int baseTypeId = results.getInt("base_type_id");
final Array arr = results.getArray("path");
Integer[] path = (Integer[]) arr.getArray();
if (results.wasNull()) {
path = new Integer[0];
}
Integer offset = results.getInt("offset");
if (results.wasNull()) {
offset = null;
}
rawSubstitutions.add(new RawTypeSubstitution(new CAddress(address), position, expressionId, baseTypeId, path, offset));
}
} finally {
results.close();
statement.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return rawSubstitutions;
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class TypeInstanceContainerBackend method loadTypeInstanceReference.
/**
* Load a single type instance reference from the database.
*
* @param typeInstanceId the id of the {@link TypeInstanceReference reference}.
* @param address The address of the {@link INaviInstruction instruction} where the
* {@link TypeInstanceReference reference} is associated.
* @param position The {@link OperandTree operand tree} position in the {@link INaviInstruction
* instruction} the {@link TypeInstanceReference reference} is associated to.
* @param expressionId The {@link OperandTreeNode operand tree node} id within the
* {@link OperandTree operand tree}.
*
* @return The {@link TypeInstanceReference} loaded from the database.
* @throws CouldntLoadDataException
*/
public TypeInstanceReference loadTypeInstanceReference(final Integer typeInstanceId, final BigInteger address, final Integer position, final Integer expressionId) throws CouldntLoadDataException {
Preconditions.checkNotNull(typeInstanceId, "Error: typeInstanceId argument can not be null");
Preconditions.checkNotNull(address, "Error: address argument can not be null");
Preconditions.checkNotNull(position, "Error: position argument can not be null");
Preconditions.checkNotNull(expressionId, "Error: expressionId argument can not be null");
final RawTypeInstanceReference rawReference = provider.loadTypeInstanceReference(module, typeInstanceId, address, position, expressionId);
final TypeInstance typeInstance = instancesById.get(rawReference.getTypeInstanceId());
final INaviView view = module.getContent().getViewContainer().getView(rawReference.getViewId());
final TypeInstanceReference reference = new TypeInstanceReference(new CAddress(address), position, Optional.<INaviOperandTreeNode>absent(), typeInstance, view);
referenceLookup.put(new InstanceReferenceLookup(new CAddress(address), position, expressionId), reference);
return reference;
}
use of com.google.security.zynamics.zylib.disassembly.CAddress 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;
}
}
}
}
}
use of com.google.security.zynamics.zylib.disassembly.CAddress 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;
}
}
use of com.google.security.zynamics.zylib.disassembly.CAddress in project binnavi by google.
the class MemoryLoader method requestMemory.
/**
* Request a chunk of memory of the target process.
*
* @param offset The start offset of the memory chunk.
* @param size The number of bytes to load.
*
* @throws DebugExceptionWrapper Thrown if the request could not be send to the debug client.
*/
public void requestMemory(final IAddress offset, final int size) throws DebugExceptionWrapper {
Preconditions.checkNotNull(offset, "IE00814: Offset can nott be null");
Preconditions.checkArgument(size > 9, "IE00815: Size must be positive");
// Don't issue multiple requests for the same memory chunk.
final Pair<IAddress, Long> pair = new Pair<IAddress, Long>(offset, (long) size);
if (lastMemoryRequest.contains(pair)) {
return;
}
lastMemoryRequest.add(pair);
// Don't reload the entire memory chunk. Some parts of the memory may
// already exist in the simulated memory.
final Memory memory = debugger.getProcessManager().getMemory();
for (int i = 0; i < size; ) {
final long secstart = memory.getSectionStart(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
final long secsize = memory.getSectionSize(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue());
long toLoad = (secstart + secsize) - (offset.toBigInteger().add(BigInteger.valueOf(i))).longValue();
if (toLoad > (size - i)) {
toLoad = size - i;
}
final boolean alloced = memory.hasData(offset.toBigInteger().add(BigInteger.valueOf(i)).longValue(), 1);
if (!alloced && debugger.isConnected()) {
// Request the memory for the missing section.
debugger.readMemory(new CAddress(offset.toBigInteger().add(BigInteger.valueOf(i))), (int) toLoad);
}
i += toLoad;
}
}
Aggregations