Search code examples
rpcfrida

How to pass a dict parameter from Python to Frida RPC JavaScript function?


I want to pass dict to RPC, here is my agent.js:

rpc.exports = {
    signrequesturlwithparameters: function (param_dict,secret,signMethod) { 
    var result=ObjC.classes.GSNetworkUtils.signRequestUrlWithParameters_secret_signMethod_(param_dict,secret,signMethod);
    return String(ObjC.classes.NSString.stringWithString_(result));
    }
};

RPC invoke example;

script.load()
signrequesturlwithparameters= getattr(script.exports, 'signrequesturlwithparameters')
_dict={"imsi":"46001","device_model":"iPhone7,2"}
secret="93AA27467E8"; 
signMethod="md5";
a=signrequesturlwithparameters(_dict,secret,signMethod)
print(a)

There is an error, can I pass a dict from Python to JavaSript RPC function? How should I modify the Python or JavaScript code to make it work?

Update: I tried JSON.parse,but it seems frida's javascript cannot use JSON.Another issue is when I want to pass a variable parameter dict to a=signrequesturlwithparameters(_dict,secret,signMethod),how should I use setObject_forKey_("key1","value1")? I think I should resolve the variable parameter dict in frida javascript,then I tried to pass str(dict) from python to frida javascript and tried to resolve the string dict to dict in frida javascript with ObjC.classes.NSJSONSerialization,more details is here,but still fail,can you help me?


Solution

  • You can use json.dumps in py side & JSON.parse in JS side, but I think your issue is @ signRequestUrlWithParameters_secret_signMethod_ I do not think it expecting JSON but NSDictionary or something similar.

    var NSDict = ObjC.classes.NSMutableDictionary.alloc().init();   
    NSDict.setObject_forKey_("key1", "value1");     
    NSDict.setObject_forKey_("key2", "value2");
    signRequestUrlWithParameters_secret_signMethod_(NSDict, ...);