Skip to content

Commit 362ea92

Browse files
authored
Merge pull request #140 from kaifcodec/main
fix: update deprecated Module.* APIs for Frida v17
2 parents b4f9c27 + aacc157 commit 362ea92

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

ios/ios-connect-hook.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020

2121
// This is the method we're going to patch:
2222
// https://developer.apple.com/documentation/network/2976677-nw_connection_create (iOS 12+)
23-
const nw_connection_create = Module.findExportByName('libnetwork.dylib', 'nw_connection_create');
23+
const libnetwork = Process.getModuleByName('libnetwork.dylib');
24+
const nw_connection_create = libnetwork.getExportByName('nw_connection_create');
2425

2526
// This is the method to make a new endpoint to connect to:
2627
// https://developer.apple.com/documentation/network/2976720-nw_endpoint_create_host (iOS 12+)
2728
const nw_endpoint_create_host = new NativeFunction(
28-
Module.findExportByName('libnetwork.dylib', 'nw_endpoint_create_host'),
29+
libnetwork.findExportByName('nw_endpoint_create_host'),
2930
'pointer', ['pointer', 'pointer']
3031
);
3132

native-connect-hook.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ const PROXY_HOST_IPv4_BYTES = PROXY_HOST.split('.').map(part => parseInt(part, 1
2121
const IPv6_MAPPING_PREFIX_BYTES = [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff];
2222
const PROXY_HOST_IPv6_BYTES = IPv6_MAPPING_PREFIX_BYTES.concat(PROXY_HOST_IPv4_BYTES);
2323

24-
const connectFn = (
25-
Module.findExportByName('libc.so', 'connect') ?? // Android
26-
Module.findExportByName('libc.so.6', 'connect') ?? // Linux
27-
Module.findExportByName('libsystem_kernel.dylib', 'connect') // iOS
28-
);
24+
let connectFn = null;
25+
try {
26+
connectFn =
27+
Process.findModuleByName('libc.so')?.findExportByName('connect') ?? // Android
28+
Process.findModuleByName('libc.so.6')?.findExportByName('connect') ?? // Linux
29+
Process.findModuleByName('libsystem_kernel.dylib')?.findExportByName('connect'); // iOS
30+
} catch (e) {
31+
console.error("Failed to find 'connect' export:", e);
32+
}
2933

3034
if (!connectFn) { // Should always be set, but just in case
3135
console.warn('Could not find libc connect() function to hook raw traffic');

native-tls-hook.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const TARGET_LIBS = [
4040
];
4141

4242
TARGET_LIBS.forEach((targetLib) => {
43-
waitForModule(targetLib.name, (moduleName) => {
44-
patchTargetLib(moduleName);
43+
waitForModule(targetLib.name, (targetModule) => {
44+
patchTargetLib(targetModule, targetLib.name);
4545
targetLib.hooked = true;
4646
});
4747

@@ -56,36 +56,36 @@ TARGET_LIBS.forEach((targetLib) => {
5656
}
5757
});
5858

59-
function patchTargetLib(targetLib) {
59+
function patchTargetLib(targetModule, targetName) {
6060
// Get the peer certificates from an SSL pointer. Returns a pointer to a STACK_OF(CRYPTO_BUFFER)
6161
// which requires use of the next few methods below to actually access.
6262
// https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#SSL_get0_peer_certificates
6363
const SSL_get0_peer_certificates = new NativeFunction(
64-
Module.findExportByName(targetLib, 'SSL_get0_peer_certificates'),
64+
targetModule.getExportByName('SSL_get0_peer_certificates'),
6565
'pointer', ['pointer']
6666
);
6767

6868
// Stack methods:
6969
// https://commondatastorage.googleapis.com/chromium-boringssl-docs/stack.h.html
7070
const sk_num = new NativeFunction(
71-
Module.findExportByName(targetLib, 'sk_num'),
71+
targetModule.getExportByName('sk_num'),
7272
'size_t', ['pointer']
7373
);
7474

7575
const sk_value = new NativeFunction(
76-
Module.findExportByName(targetLib, 'sk_value'),
76+
targetModule.getExportByName('sk_value'),
7777
'pointer', ['pointer', 'int']
7878
);
7979

8080
// Crypto buffer methods:
8181
// https://commondatastorage.googleapis.com/chromium-boringssl-docs/pool.h.html
8282
const crypto_buffer_len = new NativeFunction(
83-
Module.findExportByName(targetLib, 'CRYPTO_BUFFER_len'),
83+
targetModule.getExportByName('CRYPTO_BUFFER_len'),
8484
'size_t', ['pointer']
8585
);
8686

8787
const crypto_buffer_data = new NativeFunction(
88-
Module.findExportByName(targetLib, 'CRYPTO_BUFFER_data'),
88+
targetModule.getExportByName('CRYPTO_BUFFER_data'),
8989
'pointer', ['pointer']
9090
);
9191

@@ -118,7 +118,7 @@ function patchTargetLib(targetLib) {
118118
}
119119
pendingCheckThreads.add(threadId);
120120

121-
if (targetLib !== 'libboringssl.dylib') {
121+
if (targetName !== 'libboringssl.dylib') {
122122
// Cronet assumes its callback is always called, and crashes if not. iOS's BoringSSL
123123
// meanwhile seems to use some negative checks in its callback, and rejects the
124124
// connection independently of the return value here if it's called with a bad cert.
@@ -171,8 +171,8 @@ function patchTargetLib(targetLib) {
171171
};
172172

173173
const customVerifyAddrs = [
174-
Module.findExportByName(targetLib, "SSL_set_custom_verify"),
175-
Module.findExportByName(targetLib, "SSL_CTX_set_custom_verify")
174+
targetModule.findExportByName("SSL_set_custom_verify"),
175+
targetModule.findExportByName("SSL_CTX_set_custom_verify")
176176
].filter(Boolean);
177177

178178
customVerifyAddrs.forEach((set_custom_verify_addr) => {
@@ -190,14 +190,14 @@ function patchTargetLib(targetLib) {
190190

191191
if (customVerifyAddrs.length) {
192192
if (DEBUG_MODE) {
193-
console.log(`[+] Patched ${customVerifyAddrs.length} ${targetLib} verification methods`);
193+
console.log(`[+] Patched ${customVerifyAddrs.length} ${targetName} verification methods`);
194194
}
195-
console.log(`== Hooked native TLS lib ${targetLib} ==`);
195+
console.log(`== Hooked native TLS lib ${targetName} ==`);
196196
} else {
197-
console.log(`\n !!! Hooking native TLS lib ${targetLib} failed - no verification methods found`);
197+
console.log(`\n !!! Hooking native TLS lib ${targetName} failed - no verification methods found`);
198198
}
199199

200-
const get_psk_identity_addr = Module.findExportByName(targetLib, "SSL_get_psk_identity");
200+
const get_psk_identity_addr = targetModule.findExportByName("SSL_get_psk_identity");
201201
if (get_psk_identity_addr) {
202202
// Hooking this is apparently required for some verification paths which check the
203203
// result is not 0x0. Any return value should work fine though.

0 commit comments

Comments
 (0)