简体   繁体   中英

Frida. Pass different agrument type in class method. Error "argument types do not match any of"

I use frida to hook class. In my case HmacBuilder. It has method hmacSha256Hex()

Here what method wants..

hmacSha256Hex('java.lang.String', 'java.lang.String', 'java.lang.String', 'okhttp3.RequestBody', 'java.lang.String')

If i call it and just pass strings for all of them.. like

instance.hmacSha256Hex("none","none","none","none","none"))

frida gives error

argument types do not match any of:\n\t.overload('java.lang.String', 'java.lang.String', 'java.lang.String', 'okhttp3.RequestBody', 'java.lang.String')"

Please advise, how should i call this method properly?(Preferably passing string as okhttp3.RequestBody?

My full inject_code.js

   console.log("Script loaded successfully ");
Java.perform(function x() {

    //Find an instance of the class and call function.
    Java.choose("com.testapp.HmacBuilder", {
        onMatch: function (instance) {
            console.log("Found instance: " + instance);
           console.log("Result of HMAC func: " + instance.hmacSha256Hex("none","none","none","none","none"));
           
        },
        onComplete: function () { }
    });
});


    console.log("Script finished ");

If there isn't an overloaded method that takes 4 String arguments you have to create and pass a RequestBody as fourth parameter, that is the way programming works. Why don't you try to create a RequestBody using RequestBody.create(MediaType contentType, String content) ? For the MediaType MediaType.get(String) should be the correct method.

Translated to code it should be code like this (untested) code:

let requestBodyText = "my text"; // <- define the request body text here

let requestBodyClass = Java.use("okhttp3.RequestBody");
let mediaTypeClass = Java.use("okhttp3.MediaType");
let mediaType = mediaTypeClass.get("text/plain");
let requestBody = requestBodyClass.create(mediaType, requestBodyText);

instance.hmacSha256Hex("none","none","none",requestBody,"none"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM