Created
December 22, 2019 17:17
-
-
Save 709924470/9447431354bdbf997a07665f7a2bcf9f to your computer and use it in GitHub Desktop.
Frida android native hooking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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