4

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?

1 Answer 1

4

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: AskYN, AskLong, AskSelector, AskFunction, 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.

Importing a protected module

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.

Importing a sys.argv module

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'] import script

Calling 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 execfile and eval here and here, respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.