Skip to content

Commit 9d54aef

Browse files
committed
Improve logging & HTTP response if querying Android Frida targets fails
Previously this resulted in lots of Adbkit "FailError: closed" messages when the connection failed, which weren't very helpful or necessary. This mostly happens right now due to broken demo functionality in the UI, but it could happen any time and this is much cleaner.
1 parent 5c276a0 commit 9d54aef

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CustomError } from '@httptoolkit/util';
12
import { Client as AdbClient, DeviceClient } from '@devicefarmer/adbkit';
23
import * as FridaJs from 'frida-js';
34

@@ -163,12 +164,20 @@ export async function launchAndroidHost(adbClient: AdbClient, hostId: string) {
163164
}
164165
}
165166

167+
const getFridaStream = (hostId: string, deviceClient: DeviceClient) =>
168+
// Try alt port first (preferred and more likely to work - it's ours)
169+
deviceClient.openTcp(FRIDA_ALTERNATE_PORT)
170+
.catch(() => deviceClient.openTcp(FRIDA_DEFAULT_PORT))
171+
.catch(() => {
172+
throw new CustomError(`Couldn't connect to Frida for ${hostId}`, {
173+
statusCode: 502
174+
});
175+
});
176+
166177
export async function getAndroidFridaTargets(adbClient: AdbClient, hostId: string) {
167178
const deviceClient = adbClient.getDevice(hostId);
168179

169-
// Try alt port first (preferred and more likely to work - it's ours)
170-
const fridaStream = await deviceClient.openTcp(FRIDA_ALTERNATE_PORT)
171-
.catch(() => deviceClient.openTcp(FRIDA_DEFAULT_PORT));
180+
const fridaStream = await getFridaStream(hostId, deviceClient);
172181

173182
const fridaSession = await FridaJs.connect({
174183
stream: fridaStream
@@ -191,9 +200,7 @@ export async function interceptAndroidFridaTarget(
191200
await createPersistentReverseTunnel(deviceClient, proxyPort, proxyPort)
192201
.catch(() => {}); // If we can't tunnel that's OK - we'll use wifi/etc instead
193202

194-
// Try alt port first (preferred and more likely to work - it's ours)
195-
const fridaStream = await deviceClient.openTcp(FRIDA_ALTERNATE_PORT)
196-
.catch(() => deviceClient.openTcp(FRIDA_DEFAULT_PORT));
203+
const fridaStream = await getFridaStream(hostId, deviceClient);
197204

198205
const fridaSession = await FridaJs.connect({
199206
stream: fridaStream

0 commit comments

Comments
 (0)