Skip to content

Commit

Permalink
fainterp: interpreter is now passed to python scripts instead of kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jul 23, 2020
1 parent 45adc4e commit 72bfe61
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ Confused? That's alright :grinning:. [Just look at the examples below](#examples

User may also use his own python script files to perform
the search. Just create a new `.py` file in your project
directory and implement the `run(**kwargs)` method. Also, the project's
path is appended to python's `sys.path` so you may import
your scripts from one another.
directory and implement the `run(interpreter)` method.
Also, the project's path is appended to python's `sys.path`
so you may import your scripts from one another.

To view the list of available commands, [view the list below](#available-commands)

Expand Down Expand Up @@ -261,15 +261,13 @@ from fa.commands.find_str import find_str
from fa.commands.set_name import set_name
from fa import context

def run(**kwargs):
def run(interpreter):
# throw an exception if not running within ida context
context.verify_ida('script-name')

interp = kwargs['interpreter']

# locate the global string
resultset = set_name(find_str('hello world', null_terminated=True),
'g_hello_world', interp)
set_name(find_str('hello world', null_terminated=True),
'g_hello_world', interpreter)
```

#### Python script to automate SIG files interpreter
Expand All @@ -283,14 +281,12 @@ unique
set-name '{function_name}'
'''

def run(**kwargs):
interp = kwargs['interpreter']

def run(interpreter):
for function_name in ['func1', 'func2', 'func3']:
instructions = TEMPLATE.format(unique_string=function_name,
function_name=function_name).split('\n')

interp.find_from_instructions_list(instructions)
interpreter.find_from_instructions_list(instructions)
```

#### Python script to dynamically add structs
Expand Down
2 changes: 1 addition & 1 deletion fa/fainterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def get_python_symbols(self, file_name=None):
if not hasattr(m, 'run'):
self.log('skipping: {}'.format(filename))
else:
m.run(interpreter=self)
m.run(self)

def get_json_signatures(self, symbol_name=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion fa/signatures/test-project-ida/add_structs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fa import fa_types


def run(**kwargs):
def run(interpreter):
fa_types.add_const('CONST7', 7)
fa_types.add_const('CONST8', 8)

Expand Down
5 changes: 2 additions & 3 deletions fa/signatures/test-project-ida/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
'''


def run(**kwargs):
interp = kwargs['interpreter']
interp.find_from_instructions_list(TEMPLATE.splitlines())
def run(interpreter):
interpreter.find_from_instructions_list(TEMPLATE.splitlines())

0 comments on commit 72bfe61

Please sign in to comment.