Can I know the name of the class and method (from the java decompiler) to replace its implementation or make the JVM call my method instead of the target method?
I tried using frida for this purpose, but the application freezes after replacing.
Env
$ 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
// I'm trying to replace the StringBuilder constructor implementation in a desktop Java application using frida api
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.Str1ing');
ctor.implementation = function (arg) {
console.log(arg); return this.ctor(arg);
};
console.log('[+] new StringBuilder(java.lang.String) hooked');
});
New contributor
Nik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.