Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The application freezes after replacing the method implementation #321

Open
Holpak opened this issue May 28, 2024 · 1 comment
Open

The application freezes after replacing the method implementation #321

Holpak opened this issue May 28, 2024 · 1 comment

Comments

@Holpak
Copy link

Holpak commented May 28, 2024

I'm trying to replace the StringBuilder constructor implementation in a desktop Java application, but it freezes immediately.

$ java --version
java 17.0.11 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 17.0.11+7-LTS-207)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.11+7-LTS-207, mixed mode, sharing)
$ frida --version
16.2.5

Script

Java.perform(() => {
    
    const StringBuilder = Java.use('java.lang.StringBuilder');
    // We need to replace .$init() instead of .$new(), since .$new() = .alloc() + .init()
    const ctor = StringBuilder.$init.overload('java.lang.String');
    ctor.implementation = function (arg) {
        console.log(arg); return this.ctor(arg);
    };
    console.log('[+] new StringBuilder(java.lang.String) hooked');
});
@realgam3
Copy link

realgam3 commented Jul 28, 2024

what about:

Java.perform(() => {
    const StringBuilder = Java.use('java.lang.StringBuilder');
    const ctor = StringBuilder.$init.overload('java.lang.String');
    ctor.implementation = function (arg) {
        console.log(arg); 
        return ctor.call(this, arg);
    };
    console.log('[+] new StringBuilder(java.lang.String) hooked');
});

or:

Java.perform(() => {
    const StringBuilder = Java.use('java.lang.StringBuilder');
    StringBuilder.$init.overload('java.lang.String').implementation = function (arg) {
        console.log(arg); 
        return this.$init.overload('java.lang.String').call(this, arg);
    };
    console.log('[+] new StringBuilder(java.lang.String) hooked');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants