Conversation
test/re/frida/MethodTest.java
Outdated
| " var tm = X509TrustManager.$new();" + | ||
| "}catch(e){" + | ||
| " var MethodTest = Java.use('re.frida.MethodTest');" + | ||
| " MethodTest.Fail('couldnt create trustmanager: ' + e);" + |
There was a problem hiding this comment.
Let's use script.getNextMessage() instead (like above), that way we send('some string'); and assert that script.getNextMessage() gives us the same string.
test/re/frida/MethodTest.java
Outdated
| } | ||
|
|
||
| @Test | ||
| public void TestNewInterface() { |
There was a problem hiding this comment.
Should follow the camelCase() style here and below, and also avoid test as a prefix since it's already implicit from the class. I tried to follow the examples in the JUnit docs for naming, so in this case perhaps something like interfaceCannotBeInstantiated() or something like that.
test/re/frida/MethodTest.java
Outdated
| loadScript("var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');" + | ||
| "try{" + | ||
| " var tm = X509TrustManager.$new();" + | ||
| "}catch(e){" + |
There was a problem hiding this comment.
For the JS we should stick to semistandard, the style we're using in the implementation code. This is almost there, just missing spaces on each side of the curly braces and after catch.
test/re/frida/MethodTest.java
Outdated
| loadScript("var c = Java.use('java.lang.Class');" + | ||
| "try{" + | ||
| " var orig = c.forName.overload('java.lang.String');" + | ||
| " c.forName.overload('java.lang.String').implementation = function(s){ orig(s); };" + |
There was a problem hiding this comment.
For this test-suite we should avoid hooking things in the framework and only do that as a last resort. It's fine to start there though and refine the test so it's reproducing the same thing. The method in question here seems to be this one:
static Class<?> forName(String className)
And that made me think "uh oh, generics, we have some TODOs in that area", so maybe we can reproduce the same issue by using a locally defined method with the same kind of return type? I'd just throw it into the Badger class at the bottom.
There was a problem hiding this comment.
I've tried adding a static Class<?> function to Badger and hooking it. Frida does not crash in the same way as when hooking java.lang.Class. I also tried hooking some different built-ins with similar returns like dalvik.system.VMStack.getStackClass2 and even Made a function in Badger that calls through directly to java.lang.Class.forName() and hooked that. So far, I'm unable to reproduce the same crash without directly hooking java.lang.Class. Maybe we can comment it out for now so it doesn't block the rest of the PR?
…s, and returning string
oleavr
left a comment
There was a problem hiding this comment.
Curious if things are looking better on the latest master – released in Frida 9.1.4 this evening – hopefully there will be less weirdness now 🤞
test/re/frida/MethodTest.java
Outdated
| "} catch (e) {" + | ||
| " send('couldnt create trustmanager');" + | ||
| "}" + | ||
| "send('ok');" |
There was a problem hiding this comment.
Shouldn't this be right after var tm = ..., and the assert below should check against the error-case? (As the test is checking that it is invalid to instantiate an interface.) We should however have another test that illustrates how to register a new class implementing an interface in pure JS – or perhaps this test is meant to evolve into that?
test/re/frida/MethodTest.java
Outdated
| } | ||
|
|
||
| @Test | ||
| public void TestClassForNameOrig() { |
There was a problem hiding this comment.
Also, this test should be named like the other tests, without a test prefix, and communicating the expected outcome.
test/re/frida/MethodTest.java
Outdated
| } | ||
|
|
||
| @Test | ||
| public void TestClassForName() { |
test/re/frida/MethodTest.java
Outdated
| // this one was just hanging indefinitely during the test, but in an actual app, it was crashing | ||
| //! either one of those is bad. | ||
| @Test | ||
| public void TestMethodInvoke() { |
test/re/frida/MethodTest.java
Outdated
| }*/ | ||
|
|
||
| /*@Test | ||
| public void TestNativeLibraryLoading() { |
test/re/frida/MethodTest.java
Outdated
| "} catch (e) {" + | ||
| " send('SecretKeySpec: ' + e);" + | ||
| "}" + | ||
| "send('ok');" |
There was a problem hiding this comment.
The ok feels like it belongs inside the try, at the very end (that is only reached if everything went well).
test/re/frida/MethodTest.java
Outdated
| " c.$init.overload('[B', 'java.lang.String').implementation = function(a, b){ orig.call(this, a, b); };" + | ||
|
|
||
| // now look up the function again and call it | ||
| " var testConstructor = c.$new( [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], 'AES' );" + |
There was a problem hiding this comment.
Semistandard isn't followed here.
test/re/frida/MethodTest.java
Outdated
| } | ||
|
|
||
| static Class<?>forName() { | ||
| return Badger.class; |
test/re/frida/MethodTest.java
Outdated
| throw new IllegalStateException("Already dead"); | ||
| } | ||
|
|
||
| static Class<?>forName() { |
There was a problem hiding this comment.
Missing space between type and method name.
test/re/frida/MethodTest.java
Outdated
| loadScript("var c = Java.use('java.lang.Runtime');" + | ||
| "try{" + | ||
| " var orig = c.loadLibrary.overload('java.lang.String');" + | ||
| " c.loadLibrary.overload('java.lang.String').implementation = function(s){ orig(s); };" + |
There was a problem hiding this comment.
Semistandard isn't followed here.
oleavr
left a comment
There was a problem hiding this comment.
Let's push the style through the last mile :)
test/re/frida/MethodTest.java
Outdated
|
|
||
| import javax.crypto.Cipher; | ||
| import java.io.IOException; | ||
| import javax.crypto.Cipher; |
There was a problem hiding this comment.
This import looks like a duplicate.
| public void interfaceCannotBeInstantiated() { | ||
| loadScript("var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');" + | ||
| "try {" + | ||
| " var tm = X509TrustManager.$new();" + |
There was a problem hiding this comment.
Just noticed that indentation is inside the string, whereas the existing tests puts the indentation outside. I prefer your approach though, so I'll fix the other tests so they match it.
test/re/frida/MethodTest.java
Outdated
| "} catch (e) {" + | ||
| " send('couldnt create trustmanager');" + | ||
| "}" | ||
| ); |
There was a problem hiding this comment.
The ); should go on the previous line for consistency.
test/re/frida/MethodTest.java
Outdated
| "} catch (e) {" + | ||
| " send('class.forName failed. ' + e);" + | ||
| "}" | ||
| ); |
There was a problem hiding this comment.
The ); should go on the previous line for consistency.
test/re/frida/MethodTest.java
Outdated
| "} catch (e) {" + | ||
| " send('forName failed. ' + e);" + | ||
| "}" | ||
| ); |
There was a problem hiding this comment.
The ); should go on the previous line for consistency.
test/re/frida/MethodTest.java
Outdated
| loadScript("var c = Java.use('re.frida.Badger');" + | ||
| "try {" + | ||
| " var orig = c.forName;" + | ||
| " c.forName.implementation = function () { " + |
There was a problem hiding this comment.
This reads out the same value twice making the code hard to read. (See comment below.)
test/re/frida/MethodTest.java
Outdated
| "try {" + | ||
| " var c = Java.use('dalvik.system.VMStack');" + | ||
| " var orig = c.getStackClass2;" + | ||
| " c.getStackClass2.implementation = function () {" + |
There was a problem hiding this comment.
This reads out the same value twice making the code hard to read. (See comment below.)
test/re/frida/MethodTest.java
Outdated
| "try {" + | ||
| " var c = Java.use('re.frida.Badger');" + | ||
| " var orig = c.forNameYo;" + | ||
| " c.forNameYo.implementation = function () {" + |
There was a problem hiding this comment.
This reads out the same value twice making the code hard to read. (See comment below.)
test/re/frida/MethodTest.java
Outdated
|
|
||
| // hook the original | ||
| " var orig = c.invoke;" + | ||
| " c.invoke.implementation = function (obj, ...args) { " + |
There was a problem hiding this comment.
This reads out the same value twice making the code hard to read. (See comment below.)
test/re/frida/MethodTest.java
Outdated
| loadScript("var c = Java.use('java.lang.System');" + | ||
| "try {" + | ||
| " var orig = c.load;" + | ||
| " c.load.implementation = function (s) { " + |
There was a problem hiding this comment.
This reads out the same value twice making the code hard to read. (See comment below.)
| public void genericReturnBadger() { | ||
| loadScript("var C = Java.use('re.frida.Badger');" + | ||
| "try {" + | ||
| " var method1 = C.forName;" + |
| "var C2 = Java.use('java.lang.Class');" + | ||
| "try {" + | ||
| // hook the original | ||
| " var method1 = C.invoke;" + |
test/re/frida/MethodTest.java
Outdated
| loadScript("var C = Java.use('java.lang.System');" + | ||
| "try {" + | ||
| " var method1 = C.load;" + | ||
| " method1.implementation = function (s) { " + |
| public void loadWorks() { | ||
| loadScript("var C = Java.use('java.lang.System');" + | ||
| "try {" + | ||
| " var method1 = C.load;" + |
| " var method1 = C.load;" + | ||
| " method1.implementation = function (s) { " + | ||
| " method1.call(this,s);" + | ||
| " };" + |
| " var method1 = C.load;" + | ||
| " method1.implementation = function (s) { " + | ||
| " return method1.call(this,s);" + | ||
| " };" + |
test/re/frida/MethodTest.java
Outdated
| loadScript("var C = Java.use('java.lang.System');" + | ||
| "try {" + | ||
| " var method1 = C.load;" + | ||
| " method1.implementation = function (s) { " + |
| " };" + | ||
|
|
||
| // now look up the function again and call it | ||
| " var now = C.loadLibrary.overload('java.lang.String');" + |
| loadScript("var C = Java.use('java.lang.Runtime');" + | ||
| "try {" + | ||
| " var method1 = C.loadLibrary.overload('java.lang.String');" + | ||
| " method1.implementation = function (s) {" + |
| public void constructorReturnsCorrectType() { | ||
| loadScript("var C = Java.use('javax.crypto.spec.SecretKeySpec');" + | ||
| "try {" + | ||
| " var method1 = C.$init.overload('[B', 'java.lang.String');" + |
No description provided.