Created
October 14, 2017 18:57
-
-
Save FrankSpierings/6e2608e22121b1aeaaa4588f13387dde to your computer and use it in GitHub Desktop.
Hook all overloads - Java/Android - Frida
This file contains 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
function getGenericInterceptor(className, func, parameters) { | |
args = [] | |
for (i = 0; i < parameters.length; i++) { | |
args.push('arg_' + i) | |
} | |
var script = "result = this.__FUNCNAME__(__SEPARATED_ARG_NAMES__);\nlogmessage = '__CLASSNAME__.__FUNCNAME__(' + __SEPARATED_ARG_NAMES__ + ') => ' + result;\nconsole.log(logmessage);\nreturn result;" | |
script = script.replace(/__FUNCNAME__/g, func); | |
script = script.replace(/__SEPARATED_ARG_NAMES__/g, args.join(', ')); | |
script = script.replace(/__CLASSNAME__/g, className); | |
script = script.replace(/\+ \+/g, '+'); | |
args.push(script) | |
cb = Function.apply(null, args) | |
return cb | |
} | |
function hookall(className, func, cb) { | |
const clazz = Java.use(className); | |
overloads = clazz[func].overloads; | |
for (i in overloads) { | |
if (overloads[i].hasOwnProperty('argumentTypes')) { | |
var parameters = []; | |
for (j in overloads[i].argumentTypes) { | |
parameters.push(overloads[i].argumentTypes[j].className); | |
} | |
const cb = getGenericInterceptor(className, func, parameters); | |
clazz[func].overload.apply('this', parameters).implementation = cb; | |
} | |
} | |
} | |
if (Java.available) { | |
// Switch to the Java context | |
Java.perform(function() { | |
const JavaString = Java.use('java.lang.String'); | |
//Hook all init overloads | |
hookall('java.lang.StringBuilder', '$init', 'a'); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here we go, created method that searches for a specific
class.method
signature, maybe some one will need something like me so you will find it here :)P.S. There are many other stuff btw, you can search for an methods with specific modifier [public, private, etc..] or even method return value type.
Anyway tnx for help once again, have a nice life :)