Skip to content

Commit 6b0c72e

Browse files
committed
Improve Android Frida download error recovery
1 parent 22da813 commit 6b0c72e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const isFridaInstalled = (deviceClient: DeviceClient) =>
3131
deviceClient.readdir(ANDROID_DEVICE_HTK_PATH)
3232
.then((entries) => entries.some((entry) =>
3333
entry.name === FRIDA_BINARY_NAME &&
34-
(entry.mode & ALL_X_PERMS) !== 0
34+
(entry.mode & ALL_X_PERMS) !== 0 &&
35+
entry.size > 0
3536
))
3637
.catch(() => false);
3738

@@ -144,8 +145,21 @@ export async function launchAndroidHost(adbClient: AdbClient, hostId: string) {
144145

145146
return fridaServerStream;
146147
} catch (e: any) {
147-
console.log(e.message ?? e);
148-
throw new Error(`Failed to launch Frida server for ${hostId}`);
148+
const errorMessage = e?.message === 'Wait loop failed'
149+
? 'Frida server did not startup before timeout'
150+
: e.message ?? e;
151+
console.log('Fride launch failed:', errorMessage);
152+
153+
// Try cleaning up the Frida server (async) just in case it's corrupted somehow:
154+
deviceClient.shell(runAsRoot('rm', '-f', ANDROID_FRIDA_BINARY_PATH)).catch((e) => {
155+
console.warn(
156+
`Failed to clean up broken Frida server on ${hostId} at ${ANDROID_FRIDA_BINARY_PATH}: ${
157+
e.message ?? e
158+
}`
159+
);
160+
});
161+
162+
throw new Error(`Failed to launch Frida server for ${hostId}: ${e.message ?? e}`);
149163
}
150164
}
151165

0 commit comments

Comments
 (0)