File tree Expand file tree Collapse file tree 3 files changed +44
-54
lines changed
Expand file tree Collapse file tree 3 files changed +44
-54
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 FRIDA_DEFAULT_PORT ,
1717 FRIDA_VERSION ,
1818 FridaHost ,
19+ launchScript ,
1920 testAndSelectProxyAddress
2021} from './frida-integration' ;
2122
@@ -204,34 +205,9 @@ export async function interceptAndroidFridaTarget(
204205 proxyPort
205206 ) ;
206207
207- const scriptSession = await session . createScript ( interceptionScript ) ;
208-
209- let scriptLoaded = false ;
210- await new Promise ( ( resolve , reject ) => {
211- session . onMessage ( ( message ) => {
212- if ( message . type === 'error' ) {
213- const error = new Error ( message . description ) ;
214- error . stack = message . stack ;
215-
216- if ( ! scriptLoaded ) {
217- reject ( error ) ;
218- } else {
219- console . warn ( 'Frida Android injection error:' , error ) ;
220- }
221- } else if ( message . type === 'log' ) {
222- console . log ( `Frida Android [${ message . level } ]: ${ message . payload } ` ) ;
223- } else {
224- console . log ( message ) ;
225- }
226- } ) ;
227-
228- scriptSession . loadScript ( )
229- . then ( resolve )
230- . catch ( reject ) ;
231- } ) ;
232-
233- scriptLoaded = true ;
208+ await launchScript ( `Android (${ appId } )` , session , interceptionScript ) ;
234209 await session . resume ( ) ;
210+ console . log ( `Frida Android interception started: ${ appId } on ${ hostId } forwarding to ${ proxyIp } :${ proxyPort } ` ) ;
235211 } catch ( e ) {
236212 // If anything goes wrong, just make sure we shut down the app again
237213 await session . kill ( ) ;
Original file line number Diff line number Diff line change @@ -91,4 +91,42 @@ export async function testAndSelectProxyAddress(
9191 } ) ) . catch ( ( e ) => {
9292 throw new FridaProxyError ( "No proxy IPs were reachable from the target" , e ) ;
9393 } ) ;
94+ }
95+
96+ /**
97+ * Launch a script, watching for errors during its initial exception, and logging any
98+ * output or returned messages from the session to the console.
99+ *
100+ * Note that only one session monitor can be active at any time, so this will replace
101+ * any existing session message monitoring.
102+ */
103+ export async function launchScript ( targetName : string , session : FridaJs . FridaAgentSession , script : string ) {
104+ const scriptSession = await session . createScript ( script ) ;
105+
106+ let scriptLoaded = false ;
107+ await new Promise ( ( resolve , reject ) => {
108+ session . onMessage ( ( message ) => {
109+ if ( message . type === 'error' ) {
110+ const error = new Error ( message . description ) ;
111+ error . stack = message . stack ;
112+
113+ if ( ! scriptLoaded ) {
114+ reject ( error ) ;
115+ } else {
116+ console . warn ( `Frida ${ targetName } injection error:` , error ) ;
117+ }
118+ } else if ( message . type === 'log' ) {
119+ if ( message . payload . trim ( ) === '' ) return ;
120+ console . log ( `Frida ${ targetName } [${ message . level } ]: ${ message . payload } ` ) ;
121+ } else {
122+ console . log ( message ) ;
123+ }
124+ } ) ;
125+
126+ scriptSession . loadScript ( )
127+ . then ( resolve )
128+ . catch ( reject ) ;
129+ } ) ;
130+
131+ scriptLoaded = true ;
94132}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { buildIosFridaScript } from './frida-scripts';
66import {
77 FRIDA_DEFAULT_PORT ,
88 FridaHost ,
9+ launchScript ,
910 testAndSelectProxyAddress
1011} from './frida-integration' ;
1112
@@ -121,34 +122,9 @@ export async function interceptIosFridaTarget(
121122 proxyPort
122123 ) ;
123124
124- const scriptSession = await session . createScript ( interceptionScript ) ;
125-
126- let scriptLoaded = false ;
127- await new Promise ( ( resolve , reject ) => {
128- session . onMessage ( ( message ) => {
129- if ( message . type === 'error' ) {
130- const error = new Error ( message . description ) ;
131- error . stack = message . stack ;
132-
133- if ( ! scriptLoaded ) {
134- reject ( error ) ;
135- } else {
136- console . warn ( 'Frida iOS injection error:' , error ) ;
137- }
138- } else if ( message . type === 'log' ) {
139- console . log ( `Frida iOS [${ message . level } ]: ${ message . payload } ` ) ;
140- } else {
141- console . log ( message ) ;
142- }
143- } ) ;
144-
145- scriptSession . loadScript ( )
146- . then ( resolve )
147- . catch ( reject ) ;
148- } ) ;
149-
150- scriptLoaded = true ;
125+ await launchScript ( `iOS (${ appId } )` , session , interceptionScript ) ;
151126 await session . resume ( ) ;
127+ console . log ( `Frida iOS interception started: ${ appId } on ${ hostId } forwarding to ${ proxyIp } :${ proxyPort } ` ) ;
152128 } catch ( e ) {
153129 // If anything goes wrong, just make sure we shut down the app again
154130 await session . kill ( ) ;
You can’t perform that action at this time.
0 commit comments