Skip to content

Commit 6c72f31

Browse files
committed
Fix app killing on Frida script failures, to ensure clean shutdown
Previously we killed without resume, which doesn't actually work in all (some?) cases. This does now seem to reliably work everywhere.
1 parent 4c060c8 commit 6c72f31

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/interceptors/frida/frida-android-integration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
FRIDA_DEFAULT_PORT,
1717
FRIDA_VERSION,
1818
FridaHost,
19+
killProcess,
1920
launchScript,
2021
testAndSelectProxyAddress
2122
} from './frida-integration';
@@ -210,7 +211,7 @@ export async function interceptAndroidFridaTarget(
210211
console.log(`Frida Android interception started: ${appId} on ${hostId} forwarding to ${proxyIp}:${proxyPort}`);
211212
} catch (e) {
212213
// If anything goes wrong, just make sure we shut down the app again
213-
await session.kill();
214+
await killProcess(session).catch(console.log)
214215
throw e;
215216
}
216217
}

src/interceptors/frida/frida-integration.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as FridaJs from 'frida-js';
2-
import { CustomError } from '@httptoolkit/util';
2+
import { CustomError, delay } from '@httptoolkit/util';
33

44
import { getReachableInterfaces } from '../../util/network';
55
import { buildIpTestScript } from './frida-scripts';
@@ -55,6 +55,15 @@ class FridaProxyError extends CustomError {
5555
}
5656
}
5757

58+
export async function killProcess(session: FridaJs.FridaAgentSession) {
59+
// We have to resume and then wait briefly before we can kill:
60+
await session.resume()
61+
.then(() => delay(100)) // Even 0 seems to work - but let's be safe
62+
.catch(() => {});
63+
64+
await session.kill();
65+
}
66+
5867
export async function testAndSelectProxyAddress(
5968
session: FridaJs.FridaAgentSession,
6069
proxyPort: number,

src/interceptors/frida/frida-ios-integration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { buildIosFridaScript } from './frida-scripts';
66
import {
77
FRIDA_DEFAULT_PORT,
88
FridaHost,
9+
killProcess,
910
launchScript,
1011
testAndSelectProxyAddress
1112
} from './frida-integration';
@@ -127,7 +128,7 @@ export async function interceptIosFridaTarget(
127128
console.log(`Frida iOS interception started: ${appId} on ${hostId} forwarding to ${proxyIp}:${proxyPort}`);
128129
} catch (e) {
129130
// If anything goes wrong, just make sure we shut down the app again
130-
await session.kill();
131+
await killProcess(session).catch(console.log);
131132
throw e;
132133
}
133134
}

0 commit comments

Comments
 (0)