I have an IDAPython script x.py which takes some arguments, which prevents me from simply using alt + F7 and selecting my script.
How can I execute this script within IDA Pro and specify the arguments for the script?
Naturally, the best way would be editing the script and have it ask the user for those parameters. IDA has quite a few ways of doing that. You could use one or several of the many
idc.Ask* functions. Such as:
AskFile and others. Sometimes when multiple input parameters are needd, it becomes inconvenient to ask for many speciif values, you could then create a full blown dialog instead.
You could create a new process using
popen or something similar, but I can't say I recommend doing that.
If depends on how the python script you're trying to execute is implemented, but you're probably better off trying to include/import it in one pythonic way or another.
If the script is properly written, it probably wraps any execution functionality with an
if __name__ == "__main__" clause, protecting such cases as executing when imported. If that's the case, simply import it with an
import modulename and then call its main/whatever.
If the module directly uses
sys.argv and you cannot/would not prevent it from doing so, you can mock your
sys.argv before importing the module. Simply doing something like the following should work:
sys.argv = ['./script.py', 'command', 'parameter1', 'parameter2', 'optional']
execfile of the file
If neither of those approaches works for you, you can always directly call
execfile and completely control the context in which the python script is executed. You should read the documentation of
eval here and here, respectively.