radare2/test/perf/mem.frida.js

27 lines
933 B
JavaScript
Raw Normal View History

2023-08-16 15:59:02 +00:00
var mallocPtr = Module.findExportByName(null, "malloc");
var malloc = new NativeFunction(mallocPtr, 'pointer', ['long']);
var freePtr = Module.findExportByName(null, "free");
var freel = new NativeFunction(freePtr, 'void', ['pointer']);
var reallocPtr = Module.findExportByName(null, "realloc");
var reallocl = new NativeFunction(reallocPtr, 'pointer', ['pointer', 'int']);
Interceptor.replace(mallocPtr, new NativeCallback(function (size) {
var p = malloc(size);
console.error("mem::malloc " + size +" = " + p);
return p;
}, 'pointer', ['int']));
Interceptor.replace(freePtr, new NativeCallback(function (p) {
freel(p);
if (p) console.error("mem::free " + p);
}, 'void', ['pointer']));
Interceptor.replace(reallocPtr, new NativeCallback(function (p, size) {
var p_ret;
p_ret = reallocl(p, size);
console.error("mem::realloc " + p + " " + size + " = " + p_ret);
}, 'void', ['pointer', 'int']));