Skip to content

Commit a80d42e

Browse files
Bump to 3.9 (#97)
* Bump paramiko from 2.11.0 to 3.3.1 Bumps [paramiko](https://github.com/paramiko/paramiko) from 2.11.0 to 3.3.1. - [Commits](paramiko/paramiko@2.11.0...3.3.1) --- updated-dependencies: - dependency-name: paramiko dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump tqdm from 4.64.1 to 4.66.1 Bumps [tqdm](https://github.com/tqdm/tqdm) from 4.64.1 to 4.66.1. - [Release notes](https://github.com/tqdm/tqdm/releases) - [Commits](tqdm/tqdm@v4.64.1...v4.66.1) --- updated-dependencies: - dependency-name: tqdm dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * add backtrace to hooking.js * optimize hook.py * update readme * update setup.py * update requirements * update requirements * update changelog --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: noobpk <>
1 parent 528d40a commit a80d42e

File tree

6 files changed

+113
-50
lines changed

6 files changed

+113
-50
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Frida iOS Hook ChangeLog
22

3+
## [Release 3.9] - 2023-08-17
4+
5+
### Added
6+
- Add backtrace to hooking.js
7+
8+
### Changed
9+
- Update frida version
10+
- Update readme, changelog, requirement
11+
12+
### Fixed
13+
- Fix issue #85
14+
15+
316
## [Release 3.8] - 2022-12-11
417

518
### Added

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,23 @@ Version: 3.8
111111
git clone -b dev https://github.com/noobpk/frida-ios-hook
112112
```
113113

114-
## Build
114+
## Environment
115115

116116
```
117+
[+] Python >= v3.0 (Recommend to use pyenv or virtualenv)
118+
117119
1. cd frida-ios-hook/
118-
2. pip3 install -r requirements.txt
120+
2. python3 -m venv py-env
121+
3. source py-env/bin/active
122+
```
123+
124+
## Build
125+
126+
```
127+
1. pip3 install -r requirements.txt
119128
3. python3 setup.py
120129
4. cd frida-ios-hook
130+
5. ./ioshook -h (--help)
121131
```
122132

123133
## Usage

frida-ios-hook/core/hook.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ def main():
207207
logger.info('[*] Spawning: ' + options.package)
208208
logger.info('[*] Script: ' + options.script)
209209
time.sleep(2)
210-
pid = frida.get_usb_device().spawn(options.package)
211-
session = frida.get_usb_device().attach(pid)
210+
device = frida.get_usb_device()
211+
pid = device.spawn(options.package)
212+
time.sleep(1)
213+
session = device.attach(pid)
212214
hook = open(options.script, 'r')
213215
script = session.create_script(hook.read())
214216
script.load()
215-
frida.get_usb_device().resume(pid)
217+
device.resume(pid)
216218
sys.stdin.read()
217219
else:
218220
logger.error('[x_x] Script not found!')

frida-ios-hook/hooking.js

+66-36
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,61 @@ function search_classes(){
5454
return classes_found;
5555
}
5656

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.
6663
*/
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+
}
73109
}
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);
76112
}
77113
}
78114

@@ -97,35 +133,29 @@ if (ObjC.available)
97133
onEnter: function (args) {
98134
this._className = ObjC.Object(args[0]).toString();
99135
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);
101137
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+
}
117147
},
118148
onLeave: function(returnValues) {
119-
console.log(colors.green,"Return value of: ",colors.resetColor);
149+
console.log(colors.green,"[+] Return value of: ",colors.resetColor);
120150
console.log(' ' + this._className + ' --> ' + this._methodName);
121151
console.log(colors.green,"\t[-] Type of return value: ",colors.resetColor + Object.prototype.toString.call(returnValues));
122152
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));
123154
}
124155
});
125156
}
126-
127157
}
128-
console.log('\n[*] Starting Intercepting');
158+
console.log(colors.green,"\n[*] Starting Intercepting", colors.resetColor);
129159
}
130160
else {
131161
console.log('Objective-C Runtime is not available!');

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ frida==16.1.3
33
frida-tools==12.2.1
44
scp==0.14.4
55
requests==2.31.0
6-
paramiko==2.11.0
6+
paramiko==3.3.1
77
tqdm==4.64.1
88
psutil
99
reflutter

setup.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/python3
22
import sys
33
import os
4+
from tqdm import tqdm
5+
46
setup = """#!/usr/bin/python3
57
68
import os
@@ -25,19 +27,25 @@
2527
def _buildBinary():
2628
try:
2729
if sys.platform == 'darwin':
28-
with open('frida-ios-hook/ioshook','w+', encoding="utf-8") as f:
29-
f.write(setup)
30-
os.system('chmod +x frida-ios-hook/ioshook')
30+
for i in tqdm(range(100), colour="red"):
31+
with open('frida-ios-hook/ioshook','w+', encoding="utf-8") as f:
32+
f.write(setup)
33+
os.system('chmod +x frida-ios-hook/ioshook')
3134
print("[+] Build executable for Darwin success.")
35+
print("[+] Try ./frida-ios-hook/ioshook -h (--help)")
3236
elif sys.platform == 'linux':
33-
with open('frida-ios-hook/ioshook','w+', encoding="utf-8") as f:
34-
f.write(setup)
35-
os.system('chmod +x frida-ios-hook/ioshook')
37+
for i in tqdm(range(100), colour="red"):
38+
with open('frida-ios-hook/ioshook','w+', encoding="utf-8") as f:
39+
f.write(setup)
40+
os.system('chmod +x frida-ios-hook/ioshook')
3641
print("[+] Build executable for Linux success.")
42+
print("[+] ./frida-ios-hook/ioshook -h (-help)")
3743
elif sys.platform == 'win32':
38-
with open('frida-ios-hook/ioshook.py','w+', encoding="utf-8") as f:
39-
f.write(setup)
44+
for i in tqdm(range(100), colour="red"):
45+
with open('frida-ios-hook/ioshook.py','w+', encoding="utf-8") as f:
46+
f.write(setup)
4047
print("[+] Build executable for Windows success.")
48+
print("[+] ./frida-ios-hook/ioshook -h (-help)")
4149
except Exception as e:
4250
raise e
4351

0 commit comments

Comments
 (0)