@@ -54,25 +54,61 @@ function search_classes(){
54
54
return classes_found ;
55
55
}
56
56
57
- function print_arguments ( args ) {
58
- /*
59
- Frida's Interceptor has no information about the number of arguments, because there is no such
60
- information available at the ABI level (and we don't rely on debug symbols).
61
-
62
- I have implemented this function in order to try to determine how many arguments a method is using.
63
- It stops when:
64
- - The object is not nil
65
- - The argument is not the same as the one before
57
+ /**
58
+ * The function `print_arguments` takes an array of arguments and prints information about each
59
+ * argument, including its type, byte representation in hexadecimal, string representation, and binary
60
+ * data representation.
61
+ * @param args - The `args` parameter is an array of arguments passed to a function. In this case, it
62
+ * seems to be an array of Objective-C objects.
66
63
*/
67
- var n = 100 ;
68
- var last_arg = '' ;
69
- for ( var i = 2 ; i < n ; ++ i ) {
70
- var arg = ( new ObjC . Object ( args [ i ] ) ) . toString ( ) ;
71
- if ( arg == 'nil' || arg == last_arg ) {
72
- break ;
64
+ function print_arguments ( args ) {
65
+ try {
66
+ var n = 100 ;
67
+ var last_arg = '' ;
68
+ for ( var i = 2 ; i < n ; ++ i ) {
69
+ var arg = ( new ObjC . Object ( args [ i ] ) ) . toString ( ) ;
70
+ if ( arg == 'nil' || arg == last_arg ) {
71
+ break ;
72
+ }
73
+ last_arg = arg ;
74
+ console . log ( '\t[+] Dump Arg' + i + ': ' + ( new ObjC . Object ( args [ i ] ) ) . toString ( ) ) ;
75
+ var data = new ObjC . Object ( args [ i ] ) ;
76
+ console . log ( colors . green , "\t\t[-] Arugment type: " , colors . resetColor ) ;
77
+ console . log ( "\t\t\t" , data . $className ) ;
78
+ /* Converting Byte to HexString */
79
+ console . log ( colors . green , "\t\t[-] Bytes to Hex:" , colors . resetColor ) ;
80
+ try {
81
+ var arg = ObjC . Object ( args [ 2 ] ) ;
82
+ var length = arg . length ( ) . valueOf ( ) ;
83
+ var bytes = arg . bytes ( ) ;
84
+ var byteString = "" ;
85
+ for ( var i = 0 ; i < length ; i ++ ) {
86
+ var byte = bytes . add ( i ) . readU8 ( ) ;
87
+ byteString += byte . toString ( 16 ) . padStart ( 2 , '0' ) ; // Convert to hex and pad with leading zero if needed
88
+ }
89
+ console . log ( "\t\t\t" , byteString ) ;
90
+ } catch ( err_bytes2hex ) {
91
+ console . log ( colors . red , "\t\t\t[x] Cannot convert Byte to Hex. Error: " , err_bytes2hex , colors . resetColor ) ;
92
+ }
93
+ /* Converting NSData to String */
94
+ console . log ( colors . green , "\t\t[-] NSData to String: " , colors . resetColor ) ;
95
+ try {
96
+ var buf = data . bytes ( ) . readUtf8String ( data . length ( ) ) ;
97
+ console . log ( "\t\t\t" , buf ) ;
98
+ } catch ( err_nsdata2string ) {
99
+ console . log ( colors . red , "\t\t\t[x] Cannot convert NSData to String. Error: " , err_nsdata2string , colors . resetColor ) ;
100
+ }
101
+ /* Converting NSData to Binary Data */
102
+ console . log ( colors . green , "\t\t[-] NSData to Binary Data: " , colors . resetColor ) ;
103
+ try {
104
+ var buf = data . bytes ( ) . readByteArray ( data . length ( ) ) ;
105
+ console . log ( hexdump ( buf , { ansi : true } ) ) ;
106
+ } catch ( err_nsdata2bin ) {
107
+ console . log ( colors . red , "\t\t\t[x] Cannot convert NSData to Binary Data. Error: " , err_nsdata2bin , colors . resetColor ) ;
108
+ }
73
109
}
74
- last_arg = arg ;
75
- console . log ( '\t[-] arg' + i + ': ' + ( new ObjC . Object ( args [ i ] ) ) . toString ( ) ) ;
110
+ } catch ( err_dump ) {
111
+ console . log ( colors . red , "\t\t\t[x] Cannot dump all arugment in method . Error: " , err_dump , colors . resetColor ) ;
76
112
}
77
113
}
78
114
@@ -97,35 +133,29 @@ if (ObjC.available)
97
133
onEnter : function ( args ) {
98
134
this . _className = ObjC . Object ( args [ 0 ] ) . toString ( ) ;
99
135
this . _methodName = ObjC . selectorAsString ( args [ 1 ] ) ;
100
- console . log ( colors . green , "[+] Detected call to: " , colors . resetColor ) ;
136
+ console . log ( colors . green , "[+] Detected call to: " , colors . resetColor ) ;
101
137
console . log ( ' ' + this . _className + ' --> ' + this . _methodName ) ;
102
- console . log ( colors . green , "[+] Dump Arugment in method: " , colors . resetColor ) ;
103
- // print_arguments(args);
104
- // console.log(ObjC.Object(args[2]));
105
- // var data = new ObjC.Object(args[2]);
106
- console . log ( colors . green , "[+] Arugment type: " , colors . resetColor ) ;
107
- // console.log(data.$className);
108
- /* Converting NSData to String */
109
- // var buf = data.bytes().readUtf8String(data.length());
110
- console . log ( colors . green , "[+] NSData to String: " , colors . resetColor ) ;
111
- // console.log(buf);
112
- /* Converting NSData to Binary Data */
113
- // var buf = data.bytes().readByteArray(data.length());
114
- console . log ( colors . green , "[+] NSData to Binary Data: " , colors . resetColor ) ;
115
- // console.log(hexdump(buf, { ansi: true }));
116
-
138
+ console . log ( colors . green , "[+] Dump all arugment in method: " , colors . resetColor ) ;
139
+ print_arguments ( args ) ;
140
+ /* Backtrace */
141
+ console . log ( colors . green , "[+] Backtrace: " , colors . resetColor ) ;
142
+ try {
143
+ console . log ( Thread . backtrace ( this . context , Backtracer . ACCURATE ) . map ( DebugSymbol . fromAddress ) . join ( "\n\t" ) ) ;
144
+ } catch ( err_backtrace ) {
145
+ console . log ( colors . red , "\t\t\t[x] Cannot backtrace . Error: " , err_backtrace , colors . resetColor ) ;
146
+ }
117
147
} ,
118
148
onLeave : function ( returnValues ) {
119
- console . log ( colors . green , "Return value of: " , colors . resetColor ) ;
149
+ console . log ( colors . green , "[+] Return value of: " , colors . resetColor ) ;
120
150
console . log ( ' ' + this . _className + ' --> ' + this . _methodName ) ;
121
151
console . log ( colors . green , "\t[-] Type of return value: " , colors . resetColor + Object . prototype . toString . call ( returnValues ) ) ;
122
152
console . log ( colors . green , "\t[-] Return Value: " , colors . resetColor + returnValues ) ;
153
+ console . log ( colors . green , "\t[-] Return Value: " , colors . resetColor + JSON . stringify ( returnValues , null , 2 ) ) ;
123
154
}
124
155
} ) ;
125
156
}
126
-
127
157
}
128
- console . log ( ' \n[*] Starting Intercepting' ) ;
158
+ console . log ( colors . green , " \n[*] Starting Intercepting" , colors . resetColor ) ;
129
159
}
130
160
else {
131
161
console . log ( 'Objective-C Runtime is not available!' ) ;
0 commit comments