Skip to content

Commit

Permalink
Add exec magic command to the REPL
Browse files Browse the repository at this point in the history
Sometimes you want to execute a multiline script after you've already
opened the REPL and you don't want to close it and lose all state. The
exec command will let the user execute a file from the REPL while
running, just like typing the code manually.
  • Loading branch information
yotamN committed Feb 5, 2022
1 parent 81c92a3 commit 8cf6740
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frida_tools/_repl_magic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import abc
import codecs
import json
import os


class Magic(abc.ABC):
Expand Down Expand Up @@ -68,6 +70,29 @@ def execute(self, repl, args):
repl._autoperform_command(args[0])


class Exec(Magic):
@property
def description(self):
return "execute the given file path in the context of the currently loaded scripts"

@property
def required_args_count(self):
return 1

def execute(self, repl, args):
if not os.path.exists(args[0]):
repl._print("Can't read the given file because it does not exist")
return

try:
with codecs.open(args[0], 'rb', 'utf-8') as f:
if not repl._eval_and_print(f.read()):
repl._errors += 1
except PermissionError:
repl._print("Can't read the given file because of a permission error")



class Time(Magic):
@property
def description(self):
Expand Down
1 change: 1 addition & 0 deletions frida_tools/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ def _print_help(self, expression):
'reload': _repl_magic.Reload(),
'unload': _repl_magic.Unload(),
'autoperform': _repl_magic.Autoperform(),
'exec': _repl_magic.Exec(),
'time': _repl_magic.Time(),
'help': _repl_magic.Help()
}
Expand Down

0 comments on commit 8cf6740

Please sign in to comment.