Skip to content

Instantly share code, notes, and snippets.

@chrisdmc
Last active February 9, 2023 09:47
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chrisdmc/c1463c3624fbca187ccf48f3faa55651 to your computer and use it in GitHub Desktop.
Save chrisdmc/c1463c3624fbca187ccf48f3faa55651 to your computer and use it in GitHub Desktop.
Frida MemoryAccessMonitor that auto-renews on access
function monitorMemory(base, length, interceptedInstructions = new Set()) {
const baseAddress = ptr(base.toString());
MemoryAccessMonitor.enable({base: baseAddress, size: length}, {
onAccess: function(details) {
let baseOffset = details.address.sub(baseAddress);
console.log(`${details.address} (offset in range ${baseAddress} = ${baseOffset}) accessed for ${details.operation} from address ${DebugSymbol.fromAddress(details.from)}. Page ${details.pageIndex + 1} of ${details.pagesTotal}`);
let instruction = Instruction.parse(details.from);
const nextInstr = ptr(instruction.next.toString());
if (interceptedInstructions.has(nextInstr.toString())) {
return;
}
interceptedInstructions.add(nextInstr.toString());
Interceptor.attach(nextInstr, function(_) {
monitorMemory(baseAddress, length, interceptedInstructions);
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment