hi, this is the one of the most common issues that faced by many people who started to develop scripts on frida. if there are 2 functions with the same name and if you try to hook, you’ll see different types of parameters. first of all, I’ll talk about why it happens and then what is the solution.

the main reason for this is based on what we call method overloading.

what is Method Overloading?



Java allows us to define multiple methods with the same name. writing more than one method in this way is called overloading. you can define two functions with the same name, but there is a rule you must follow. the function that you're trying to implement method overloading, needs to take different parameters from the other. e.g;




package com.lab.ahmeth4n;
 
public class MethodOverloadingExample {
void funcOver(String atl){
atl = "ahmeth4n" + atl;
System.out.println("message: " + atl);
}
void funcOver(int atl){
atl = 1337 + atl;
System.out.println("message: " + String.valueOf(atl ));
}
 
 
public static void main(String[] args) {
 
MethodOverloadingExample testlab = new MethodOverloadingExample();
testlab.kareKok("x86");
testlab.kareKok(37);
}
 
}

here we have created two "funcOver" methods with the same name in the MethodOverloadingExample class.

the first one takes a String type parameter while the other takes an int type parameter. if you assign a string parameter to the function, Java will run the function that takes its string parameter. if you assign an int parameter, it will run the function that takes an int parameter. we call this method overloading.


so how to hook the function with method overloading!?



calm down. there is a very simple method to this.

if you overload the parameter type of the function you want to be hooked directly from the function name, like a normal frida script writer, frida will throw an error and stop. the reason for this is that the 2 overloaded methods I just mentioned take different parameters. there is a very simple move you have to make here.

i will explain through a simple script i wrote.



	Java.perform(function() {
    const helper = Java.use('com.lab.ahmeth4n.MethodOverloadingExample')
    const overloads = helper.funcOver.overloads
    overloads.forEach(overload => {
        if (overload.returnType.name == "java.lang.String"){ 
            overload.implementation = function(args){
		console.log(args);
                return overload.call(this, args)
            }
        }
    })
});




after specifying the class i want to hook with .use, i assigned the overloads of the target function to a variable. since there are more than one function with this name, i looped the variable i assigned with forEach to make it easier to get the target function. I checked the type of variable i want to hook with a very simple check in the loop. because for me the function that takes an int parameter doesn't matter

if i had written a normal frida script and overloaded it, i would have had an error while returning it in the overload function. because the type i sent as a parameter is String, but since this parameter goes to both functions, it would try to give a String parameter to the function that takes an int parameter. here's a very simple if check that gets the job done.

java is everywhere! see you man.