Skip to content

Commit 956056a

Browse files
committed
Add ability to eval JS inline on heap objects.
1 parent c88f612 commit 956056a

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

objection/commands/ios/heap.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ def _should_return_as_string(args) -> bool:
4242
return len(args) > 0 and '--return-string' in args
4343

4444

45+
def _should_interpret_inline_js(args) -> bool:
46+
"""
47+
Check if we have the --inline flag
48+
49+
:param args:
50+
:return:
51+
"""
52+
53+
return len(args) > 0 and '--inline' in args
54+
55+
4556
def instances(args: list) -> None:
4657
"""
4758
Asks the agent to print the currently live instances of a particular class
@@ -173,19 +184,30 @@ def evaluate(args: list) -> None:
173184
"""
174185

175186
if len(args) < 1:
176-
click.secho('Usage: ios heap execute js <pointer> (eg: 0x600001130660)', bold=True)
187+
click.secho('Usage: ios heap execute js <pointer> (eg: 0x600001130660) ' +
188+
'(optional: --inline) (optional: <JavaScript source>)', bold=True)
177189
return
178190

179191
target_pointer = args[0]
180192

181-
js = prompt(
182-
click.secho('(The pointer at `{pointer}` will be available as the `ptr` variable.)n'.format(
183-
pointer=target_pointer
184-
), dim=True),
185-
multiline=True, lexer=PygmentsLexer(JavascriptLexer),
186-
bottom_toolbar='JavaScript edit mode. [ESC] and then [ENTER] to accept. [CTRL] + C to cancel.').strip()
193+
# adding the --inline flag would trigger reading the line contents
194+
# as JavaScript sources
195+
if _should_interpret_inline_js(args):
196+
args.remove('--inline')
197+
js = ''.join(args[1:])
198+
199+
click.secho('Reading inline JavaScript for evaluation...', dim=True)
200+
click.secho('{}\n'.format(js), fg='green', dim=True)
201+
202+
else:
203+
js = prompt(
204+
click.secho('(The pointer at `{pointer}` will be available as the `ptr` variable.)n'.format(
205+
pointer=target_pointer
206+
), dim=True),
207+
multiline=True, lexer=PygmentsLexer(JavascriptLexer),
208+
bottom_toolbar='JavaScript edit mode. [ESC] and then [ENTER] to accept. [CTRL] + C to cancel.').strip()
187209

188-
click.secho('JavaScript capture complete. Evaluating...', dim=True)
210+
click.secho('JavaScript capture complete. Evaluating...', dim=True)
189211

190212
api = state_connection.get_api()
191213
api.ios_heap_evaluate_js(target_pointer, js)

objection/console/commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@
624624
},
625625
'evaluate': {
626626
'meta': 'Evaluate JavaScript on objects on the iOS heap',
627+
'flags': ['--inline'],
627628
'exec': ios_heap.evaluate
628629
}
629630
}

0 commit comments

Comments
 (0)