'How to call an iOS method of an argument of a method in a Frida Trace handler?

I am currently trying to log packets between some game client and server. And I have this question. I do this:

onEnter(log, args, state) {
    console.log(ObjC.Object(args[0]).$super.$ownMethods.join('\n'))
    console.log(ObjC.Object(args[0]).
        $super.setHost(ObjC.classes.NSString.stringWithUTF8String_(
            Memory.allocUtf8String('192.168.1.69'))))
}

And get this output:

- Close
- IsConnected
- IsConnecting
- portSSL
- setPortSSL:
- Open
- getCurrentPort
- server_name
- setServer_name:
- OnConnected
- getPassphraseForP12
- Open:
- addSSLProperties
- Close:ssl:
- findNewMessage
- onAllDataSended
- setLastStreamError:
- setLastStreamErrorTime:
- lastStreamError
- lastConnectionTime
- lastStreamErrorTime
- onNewMessage:
- SendMessageString:
- clearAllOutData
- setLastConnectionTime:
- stream:handleEvent:
- setHost:
- setPort:
- .cxx_destruct
- setDelegate:
- delegate
- host
- port
{'type': 'error', 'description': 'TypeError: not a function', 'stack': 'TypeError: not a function\n    at onEnter (<input>:24)\n    at call (native)\n    at invokeNativeHandler (agent.ts:308)\n    at onEnter (agent.ts:273)', 'fileName': '<input>', 'lineNumber': 24, 'columnNumber': 1}

As you can see, there is method called setHost, but I can't call it. Why? How do I call it?



Solution 1:[1]

The problem solved by calling ObjC.Object(args[0])['setHost:'](...) - the colon. Noticed it when looked through method names from frida-trace output.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wynell