use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.
the class CallResolver method resolveFunction.
private ResolvedFunction resolveFunction(final Address address) {
for (final Module module : target.getModules()) {
if (!resolvedFunctions.containsKey(module)) {
resolveFunctions(module);
if (!resolvedFunctions.containsKey(module)) {
continue;
}
}
final Map<Address, Function> functionMap = resolvedFunctions.get(module);
final Function function = functionMap.get(address);
if (function != null) {
return new ResolvedFunction(function);
}
}
for (final MemoryModule memoryModule : target.getDebugger().getProcess().getModules()) {
if ((address.toLong() >= memoryModule.getBaseAddress().toLong()) && (address.toLong() < (memoryModule.getBaseAddress().toLong() + memoryModule.getSize()))) {
return new ResolvedFunction(memoryModule, address);
}
}
return new ResolvedFunction(address);
}
use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.
the class CallResolver method removeBreakpoint.
/**
* Removes a breakpoint from an indirect call.
*
* @param indirectCall The indirect call from which the breakpoint is removed.
*/
private void removeBreakpoint(final IndirectCall indirectCall) {
final Module module = indirectCall.getModule();
final Address address = indirectCall.getAddress();
final BreakpointManager breakpointManager = debugger.getBreakpointManager();
if (breakpointManager.hasBreakpoint(module, address)) {
debugger.getBreakpointManager().removeBreakpoint(indirectCall.getModule(), indirectCall.getAddress());
}
}
use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.
the class CallResolver method processCompleteSingleStep.
/**
* After a single step was completed successfully, we know the target of the function call and can
* update our internal structures.
*
* @param threadId The thread ID of the thread that completed the single step.
* @param resolvedAddress The address of the called function.
*/
private void processCompleteSingleStep(final long threadId, final BigInteger resolvedAddress) {
final BigInteger lastIndirectCallAddress = lastHits.get(threadId);
if (lastIndirectCallAddress == null) {
// occurs because of a race condition in multi-threaded programs.
return;
}
synchronized (resolvedAddresses) {
if (!resolvedAddresses.containsKey(lastIndirectCallAddress)) {
resolvedAddresses.put(lastIndirectCallAddress, new HashSet<ResolvedFunction>());
}
final ResolvedFunction resolvedFunction = resolveFunction(new Address(resolvedAddress));
if (resolvedAddresses.get(lastIndirectCallAddress).add(resolvedFunction)) {
hitCounter.put(lastIndirectCallAddress, 0);
}
if (hitCounter.get(lastIndirectCallAddress) >= HIT_THRESHOLD) {
final IndirectCall indirectCall = IndirectCallResolver.findIndirectCall(debugger, indirectCallAddresses, lastIndirectCallAddress);
if (indirectCall != null) {
removeBreakpoint(indirectCall);
removedBreakpoints.add(indirectCall);
resolvedCall(lastIndirectCallAddress, resolvedFunction);
}
}
}
}
use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.
the class IndirectCallResolver method findIndirectCall.
/**
* Searches for an indirect call given the relocated call address.
*
* @param debugger The debugger that provides the relocation information.
* @param indirectCallAddresses The list of indirect call addresses to search through.
* @param callAddress The relocated call address to find.
*
* @return The found indirect call object.
*/
public static IndirectCall findIndirectCall(final Debugger debugger, final List<IndirectCall> indirectCallAddresses, final BigInteger callAddress) {
for (final IndirectCall indirectCall : indirectCallAddresses) {
final Module module = indirectCall.getModule();
final Address address = indirectCall.getAddress();
final Address rebasedAddress = debugger.toImagebase(module, address);
if (rebasedAddress.equals(new Address(callAddress))) {
return indirectCall;
}
}
return null;
}
use of com.google.security.zynamics.binnavi.API.disassembly.Address in project binnavi by google.
the class IndirectCallFinder method getDirectFunctionCalls.
/**
* Returns the direct function call addresses for a given module.
*
* @param module The module whose direct function call addresses are returned.
*
* @return The direct function call addresses of the module.
*/
private static Set<Address> getDirectFunctionCalls(final Module module) {
final Set<Address> set = new HashSet<Address>();
final String query = "SELECT it.address" + " FROM " + TableNames.INSTRUCTIONS_TABLE + " AS it" + " JOIN " + TableNames.ADDRESS_REFERENCES_TABLE + " AS art ON it.address = art.address " + " AND it.module_id = art.module_id" + " WHERE type = 'call_direct' AND art.module_id = " + module.getId();
try {
final ResultSet resultSet = module.getDatabase().executeQuery(query);
try {
while (resultSet.next()) {
set.add(new Address(resultSet.getLong("address")));
}
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
exception.printStackTrace();
}
return set;
}
Aggregations