Skip to content

Instantly share code, notes, and snippets.

@konwa
Forked from 709924470/hookNativeFunc.js
Created August 9, 2022 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save konwa/96729423d63048e5ba4b577330a482a4 to your computer and use it in GitHub Desktop.
Save konwa/96729423d63048e5ba4b577330a482a4 to your computer and use it in GitHub Desktop.
Frida android native hooking
// Android native hooks By @709924470
// CC-BY-NC 4.0
var moduleName = "libmain.so"; // Module name gose here
var hookFunctions = [
{
name: "Java_com_example_hellojni_getstr", // Function name goes here
onEnter: function(args){
// TODO: your code here
},
onLeave: function(ret){
// TODO: your code here
}
},
];
Interceptor.attach(Module.findExportByName(null, "android_dlopen_ext"), {
onEnter: function (args) {
var path = Memory.readUtf8String(args[0]);
//console.log("[*] android_dlopen_ext(\" " + path +" \")");
hookNative(path);
}
});
Interceptor.attach(Module.findExportByName(null, "dlopen"), {
onEnter: function (args) {
var path = Memory.readUtf8String(args[0]);
//console.log("[*] dlopen(\" " + path +" \")");
hookNative(path);
}
});
function hookNative(path){
if(path.indexOf(moduleName) != -1){
// TODO: actions after module loaded goes here
for(var i = 0; i < hookFunctions.length; i++){
Interceptor.attach(Module.findExportByName(moduleName, hookFunctions[i].name),{
onEnter: hookFunctions[i].onEnter,
onLeave: hookFunctions[i].onLeave
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment