Getting weird types on hooking native method with Frida - frida

I'm trying to hook some function in an class it works fine but I want to view one argumant that is an class instance and this class has field that is String type, but when I try to get this field I get some really weird type instead of the string
Here is the code:
var someclass = Java.use('com.myapp.classes.someclass.a');
// String (Object, String, Boolean)
someclass.getData.overload('com.myapp.classes.ClassContext',
'java.lang.String', 'java.lang.Boolean').implementation = function (a, b, c) {
console.log('com.myapp.classes.ClassContext.stringify: ',
JSON.stringify(a.fieldWithStringData), '\r\n');
}
But instead of string I get some weird object when I used JSON.stringify on this object I got string like this (pretty printed for this question):
{
"_p": ["<instance: com.myapp.classes.ClassContext>", 2, {
"className": "java.lang.String",
"name": "Ljava/lang/String;",
"type": "pointer",
"size": 1,
"defaultValue": "0x0"
}, "0xa3144614", "0xc2aaa8b0", "0xc2aace70"]
}
What is this object and how to get actual string from it, can some one help?

You can use like this: a.fieldWithStringData.value

Related

Quicktype option parameter handling

I have an optional parameter in my web-service response which can or can not return null. What will be the best what to manage those?
As if I pass null in creator lets say for this structure:
{
"email": "test#test.com",
"profilePicture": null,
"firstTime": true,
"preference1": {
"$id": "26",
"$values": []
},
"Preference2": {
"$id": "27",
"$values": []
}
}
Now profilePicture is set to JSONNull and next time when I actually get profile URL it will not parse that and my response data to LNUser is nil. If I set this variable to String and null received response get set to nil.
You need
let profilePicture:URL?
quicktype needs an exhaustive set of examples, so make sure one of your samples includes a non-null value. Like this: https://app.quicktype.io?share=ldXiDP9cIKB1Q7CPJ7Id

How to hide properties with null values in FSharp.Data JsonProvider?

This piece of code:
open FSharp.Data
type ColorProvider = JsonProvider<"""
[
{
"color": "Red",
"code": 15
},
{
"color": "Green"
}
]
""", SampleIsList=true>
let value = ColorProvider.Root(color = "Blue", code = None)
printf "%A" value
Produces this JSON:
{
"color": "Blue",
"code": null
}
I'm passing the json to an external service which doesn't handle nulls. Either it must be an integer or the whole property must be missing.
Is there a way to hide the code property when it's null?
You are using FSharp's object printing feature for generating JSON. It produces JSON-like output, but in my opinion it is not meant for that task. I'd suggest using a JSON library for that, personally I like using https://github.com/Microsoft/fsharplu/wiki/fsharplu.json for that task, as it produces beautiful JSON for Discriminate Unions.

Getting user's complete information using TwitterKit

I'm using this API to get a user's followers list, and returns the followers in JSON format as described in the documentation. Here is a snippet of a returned object:
{
"users": [
{
"id": 2960784075,
"id_str": "2960784075",
"name": "Jesus Rafael Abreu M",
"screen_name": "chuomaraver",
"location": "",
"profile_location": null,
"url": null,
"description": "",
"protected": false,
"followers_count": 1,
"friends_count": 101,
"listed_count": 0,
"created_at": "Sun Jan 04 19:58:06 +0000 2015",
.....
.....
"default_profile": true,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"muting": false
},
.....
.....
],
"next_cursor": 1489467234237774933,
"next_cursor_str": "1489467234237774933",
"previous_cursor": 0,
"previous_cursor_str": "0"
}
As you notice, the user object has a lot of properties, and I don't want to
parse them one by one or use a library to do that for me.
The TwitterKit has a class named TWTRUser, and here is it's documentation. To initialize an object of this class, you can just use a constructor that takes a JSON dictionary like this:
let follower = TWTRUser(jsonDictionary: jsonDictionary)
This way I can get the JSON Object the is returned to me parsed and initialize a TWTRUser object.
The problem is that TWTRUser doesn't have all the properties listed in the JSON returned, it only has these properties as listed in the documentation:
userID property
name property
screenName property
isVerified
property
isProtected property
profileImageURL property
profileImageMiniURL property
profileImageLargeURL property
formattedScreenName property
profileURL property
I tried to use valueForKey method that takes a key and returns it value like this:
let createdAt = follower.value(forKey: "created_at")
I thought it would work, but it didn't. When I use it the application crashes and gives me the following message:
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[ valueForUndefinedKey:]: this class
is not key value coding-compliant for the key contributors_enabled.'
What could I do to get all the user's properties using TWTRUser class?
value(forKey:) is a method inherited with NSObject and it is used for Key-Value Coding so it doesn't return results of the JSON. The TWTRUser class only defines 10 properties and that's all you can get with it. If you want to get other properties, you would have to parse the JSON yourself with the following line of code (using the standard library)
let user = try JSONSerialization.jsonObject(with: jsonDictionary) as? [String: Any]
First of all, like it's already been mentioned, don't use value(for key), if the object had that value it probably would expose it through a public property.
My suggestion would be to subclass TWTRUser, add the properties you want to your new class (you can call it something like TwitterUser) and override init(json), there you can see if the dictionary contains the values you want and add them to the object.
After that you'll be able to access those properties like you would with any other properties in the TWTRUser class.

Access values in a nested map in dartlang using string interpolation

I have the following code and I am trying to access the nested map values using string interpolation. However, it returns the entire variable rather than just a particular value.
Map<String, Map<String, String>> questionBank = {
"1": {
"question": "What is the capital of Canada?",
"ans1": "Toronto",
"ans2": "Montreal",
"ans3": "Ottawa",
"ans4": "Vancouver"
},
"2": {
"question": "What is the capital of Britain?",
"ans1": "London",
"ans2": "Manchester",
"ans3": "Newcastle",
"ans4": "Edinburgh"
}
};
void main() {
print('Question: $questionBank[1][question]');
}
How do I address this? Grateful for any insights.
Apparently, that evaluates to an expression and not just a variable and therefore needs to be enclosed with a parentheses.
print('Question: ${questionBank["1"]["question"]}');

class cast exception when data binding with list

The domain looks like
class EventDonation implements Serializable{
String title
String body
Integer customDonationMin
Integer customDonationMax
EntityStatus status
List denominations
static hasMany = [denominations: Integer]
}
Please note that the denominations is a list of Integers. Now during binding
List<String> whiteList = ['title', 'body', 'customDonationMin', 'customDonationMax', 'denominations']
bindData(don, params, ['include': whiteList])
if(params.status){
don.status = EntityStatus.ACTIVE
}
else{
don.status = EntityStatus.INACTIVE
}
don.validate()
if(don.hasErrors()){
render(view: "editdonation", model: [id:id, donation:don])
return
}
The following error is displayed
Message: java.lang.String cannot be cast to java.lang.Integer
In the view page there are 4 textboxes for entering denominations. I was thinking that the strings i.e '10', '20', '30', '40' will automatically be converted to integers during binding. I think the error is associated with binding this list. I appreciate any help. Thanks!
Interesting thing is when i change the type of the list to String as follows:
class EventDonation implements Serializable{
String title
String body
Integer customDonationMin
Integer customDonationMax
EntityStatus status
List denominations
static hasMany = [denominations: String]
}
The following binding works fine i.e no error is thrown.
List<String> whiteList = ['title', 'body', 'customDonationMin', 'customDonationMax', 'denominations']
bindData(don, params, ['include': whiteList])
if(params.status){
don.status = EntityStatus.ACTIVE
}
else{
don.status = EntityStatus.INACTIVE
}
don.validate()
if(don.hasErrors()){
render(view: "editdonation", model: [id:id, donation:don])
return
}
So, i am confident that the type Integer for the list is the source of the problem. Since denominations are integers i cannot think of any other type. I appreciate any help on this. Thank you!

Resources