Skip to content

Commit 4c060c8

Browse files
committed
Improve Frida script error reporting with explicit wrappers
Frida errors themselves include stack info from only the script, and won't make much sense in some cases. Including a wrapper like this gives us a lot more information about what's going on, which app is failing, and what we were doing at the time.
1 parent 583cc7e commit 4c060c8

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/interceptors/frida/frida-integration.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ export const FRIDA_ALTERNATE_PORT = 24072; // Reversed to mildly inconvenience d
3535

3636
export const FRIDA_BINARY_NAME = `adirf-server`; // Reversed to mildly inconvenience detection
3737

38+
class FridaScriptError extends CustomError {
39+
constructor(
40+
message: FridaJs.ScriptAgentErrorMessage
41+
) {
42+
super(message.description);
43+
if (message.stack) {
44+
this.stack = message.stack;
45+
}
46+
}
47+
}
48+
3849
class FridaProxyError extends CustomError {
3950
constructor(message: string, options: { cause?: Error } = {}) {
4051
super(message, {
@@ -78,9 +89,11 @@ export async function testAndSelectProxyAddress(
7889
reject(new Error(`Unexpected message type: ${message.payload.type}`));
7990
}
8091
} else if (message.type === 'error') {
81-
const error = new Error(message.description);
82-
error.stack = message.stack;
83-
reject(error);
92+
const fridaError = new FridaScriptError(message);
93+
reject(new CustomError(
94+
`Error in Frida IP test script: ${message.description}`,
95+
{ cause: fridaError, code: 'frida-ip-test-script-error' }
96+
));
8497
}
8598
});
8699

@@ -107,13 +120,15 @@ export async function launchScript(targetName: string, session: FridaJs.FridaAge
107120
await new Promise((resolve, reject) => {
108121
session.onMessage((message) => {
109122
if (message.type === 'error') {
110-
const error = new Error(message.description);
111-
error.stack = message.stack;
123+
const fridaError = new FridaScriptError(message);
112124

113125
if (!scriptLoaded) {
114-
reject(error);
126+
reject(new CustomError(
127+
`Failed to run Frida script on ${targetName}: ${message.description}`,
128+
{ cause: fridaError, code: 'frida-script-error' }
129+
));
115130
} else {
116-
console.warn(`Frida ${targetName} injection error:`, error);
131+
console.warn(`Frida ${targetName} injection error:`, fridaError);
117132
}
118133
} else if (message.type === 'log') {
119134
if (message.payload.trim() === '') return;

0 commit comments

Comments
 (0)