Skip to content

Commit

Permalink
class-factory: Fix toString() for overloaded methods (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
yotamN authored Apr 14, 2023
1 parent 4ac5c89 commit 09c77f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/class-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,10 @@ dispatcherPrototype = Object.create(Function.prototype, {
return method.apply(receiver, args);
}

if (this.methodName === 'toString') {
return `<class: ${receiver.$n}>`;
}

throwOverloadError(this.methodName, this.overloads, 'argument types do not match any of:');
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/re/frida/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ public void performNowWorks() {
assertEquals("Hello", script.getNextMessage());
}

// Issue #271
@Test
public void toStringOnOverloadedToString() {
loadScript("const utf16 = Java.use('android.icu.text.UTF16');" +
"send(utf16.toString());");
assertEquals("<class: android.icu.text.UTF16>", script.getNextMessage());
}

@Test
public void replacementCanAcceptModifiedUTF8StringParameter() {
loadScript("var Badger = Java.use('re.frida.Badger');" +
Expand Down

0 comments on commit 09c77f4

Please sign in to comment.