frida / frida

Clone this repo to build Frida
https://frida.re
Other
16.14k stars 1.67k forks source link

can not trace java function with 10.0.12 #283

Closed DogeWatch closed 7 years ago

DogeWatch commented 7 years ago

my code is: URI = Java.use("java.net.URI"); URI.URI.implementation = function(){ console.log("URI modified"); }

and it says {u'columnNumber': 1, u'description': u"TypeError: cannot write property 'implementation' of undefined", u'fileName': u'script1.js', u'lineNumber': 17, u'type': u'error', u'stack': u"TypeError: cannot write property 'implementation' of undefined\n at [anon] (duk_hobject_props.c:3352)\n at [anon] (script1.js:17)\n at frida/node_modules/frida-java/lib/vm.js:39\n at y (frida/node_modules/frida-java/index.js:322)\n at frida/node_modules/frida-java/index.js:296\n at frida/node_modules/frida-java/lib/vm.js:39\n at java.js:2209\n at script1.js:18"}

dzonerzy commented 7 years ago

Your code is wrong , since URI is you wrapper class to java.net.URI, if you want to hook constructor , you should do something similar:

var URI = Java.use('java.net.URI');
URI.$init.overload('java.lang.String').implementation = function (url)
{
send("URI object created with value: " + url);
// call the original method not the hooked one
return URI.$init.overload('java.lang.String').call(this, url);
}

We used .overload('java.lang.String') since URI constructor have different signature as stated here https://docs.oracle.com/javase/7/docs/api/java/net/URI.html