Skip to content

Instantly share code, notes, and snippets.

@709924470
Created December 22, 2019 17:17
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 709924470/9447431354bdbf997a07665f7a2bcf9f to your computer and use it in GitHub Desktop.
Save 709924470/9447431354bdbf997a07665f7a2bcf9f 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