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

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?

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, ...);

Related

JSON.parse is not a function in node js

I'm new in node js and I'm trying to parse a JSON. This is what I've done so far:
const JSON = require("nodemon/lib/utils");
...
someFunction() {
let sens = [];
// sensor is the result of fs.readFileSync call and file is a json array
sens = JSON.parse(sensors);
It throws me:
JSON.parse is not a function.
How can I solve it?
Just comment out the very first line. JSON is built in already.
//const JSON = require("nodemon/lib/utils");
JSON is kind of a global object. It doesn't need to be required. So, just remove the line where JSON is required and it'll work fine.

How to pass a global variable before it gets rewritten to a fs.readFile in nodejs

Update: I think I found the answer to a similar problem in here: NodeJS readFile() retrieve filename
the point is that loops and have several call in http are actually kind of the same problem. The smartest solution may be to use ForEach instead of For
Hi I have the following code:
path = foo;
fs.readFile(path, function(err, data){
do_something_with_data(data);
do_something_with_path(path);
});
The problem is that the value of foo & path is overwritten with each single http request. So when the function do_something_with_path(path); is executed, the value of path is not the same as the one that was send as argument on fs.readFile(path ..
Is there anyway to use within fs.readFile the path value that was used instead of the last one?
Don't use a global variable. Instead, make a in-function variable. So whenever the function is called, a variable will be created which has something to do with this file.
Another try: use
var path = foo;
You can create a global variable in another module then reference this from the file you are using readFile.
Create a settings.js file in your project root:
module.exports = {
path: foo // Your variable
}
Inside your other js file where fs.readFile is being used.
var settings = require('../settings'); // Relative path to your settings file.
Then you can use settings.path as your global variable.
var settings = require('../settings');
path = foo;
fs.readFile(path, function(err, data){
do_something_with_data(data);
do_something_with_path(settings.path);
});
Use global keyword to store value of a variable globally
like following
global.path = foo;
It will store value globally.
Thanks

Vert.x how to call a file in module

I have a module like this structure:
module_root/
mod.json
filestore/myfile
com/my/www/my.groovy(Compiled to my.class)
I want to call filestore/myfile in my.groovy. I tried many methods to access the file, but I failed.
First, I try to use relative path. Both ../../../filestore/myfile and filestore/myfile failed. No such file or directory.
new FileInputStream('../../../filestore/myfile').withStream {
// ...
}
Then I try to use absolute path, I don't know how to get the module's absolute path. I try to get the my.groovy path use this code:
scriptFile = getClass().protectionDomain.codeSource.location.path
But when I exec vertx runzip mymodule.zip, I get an exception:
java.lang.NullPointerException: Cannot get property 'location' on null object
How to do this?
for me this works..please let me know if works for you:
this is js, I don't know groovy but I suppose than must be similar
var CURRENT-DIRECTORY = new java.io.File("").getAbsolutePath()
then you can use string concatenation
CURRENT-DIRECTORY+"/filestore/myfile/mysuperFile.groovy" <--notice the /
remember than the response is a buffer, maybe you must be convert this to string
return response.toString()
good luck

How to get a global Object by Object name

In the meteor server.There is object like this:
A.js
testObject = function(){}
and I want to get testObject by testObject's name "testObject"
if "A.js" in Client . I know I can get the Object by
var a = window["testObject"]
because of window is a global Object and save all other global Object.
but I don't know how to get it in Server.
Any suggestions appreciated!
An easy way to retain a global scope reference is just to wrap your code in an IIFE closure like this:
(function( namespace ) {
console.log( namespace["testObject"] );
}( this ));
This will work on both server and client.
just like node code. use like this
global["testObject"]
I get the answer on FreeNode .Thank you #bline

how to retrieve caller function js file global variable value in nodejs

Sample Code from nodejs:
Code from JS1.js :
var js2=require("../../util");
var dataName="Billy";
function hello1(){
js2.hello2("message");
}
Code from JS3.js :
var js2=require("../../util");
var dataName="Tom";
function hello3(){
js2.hello2("message");
}
Code from JS2.js :
exports.hello2=hello2;
function hello2(arg1){
console.log(arg1);
//Here I need the data in global variable "dataName" of file JS1.js or JS3.js
}
I need to access the global variable of caller js file.
All modules share a global object in node.js. So in JS1.js ...
global.dataName = "Billy";
... then in JS2.js:
console.log(global.dataName);
However, it shouldn't be surprising that using global in this way is generally considered poor form. Unless you have a specific reason for not wanting JS2 to depend on JS1, it's probably better to just have JS2 export dataName as part of it's module.exports.

Resources