[TIP] How to define a keyboard shortcut for an IDAPython script

IDAPython

Today, i want to share with you a very useful tip that ive been using for a while, and i particulary like. Gera posted a variation of it in the IDA official forum some time ago but i think that would be useful to share it also here.

Usually, in IDA, we find ourselves needing a way to define a shortcut for that useful IDAPython script to bypass the tedious “alt+9 + [select the wanted IDAPython script] + enter” procedure.

When i finished the FindInFunc script (you can read my previous post about it here), i faced that situation for the Nth time and i finally managed to get an easy hack to get it working.

We know that it is possible to set a shortcut to an IDC script by defining it in the idamain.cfg so after googling for a while i went to the IDAPython source and i’ve found this:

/* Simple Python statement runner function for IDC */
static const char idc_runpythonstatement_args[] = { VT_STR, 0 };
static error_t idaapi idc_runpythonstatement(value_t *argv, value_t *res)
{
res->num = PyRun_SimpleString(argv[0].str);
return eOk;
}

http://code.google.com/p/idapython/source/diff?spec=svn32&r=32&format=side&path=/trunk/python.cpp

This functions alows us to execute a python sentence in the context of an IDC script… Dude! It’s pretty much convenient for our purposes because if we do:

RunPythonStatement("execfile 'c:\pathoffile\script.py'")

Voila! We have our script executed.

So, all we need now is to add something like this to the main() function in ida.idc:

AddHotkey("Alt-F8", "py_findinfunc");

And then, add this handler at the end, in the same file.

static py_findinfunc()
{
RunPythonStatement("execfile('c:\\FindInFunc.py')");
}

~ by aLS -- on January 3, 2010.

6 Responses to “[TIP] How to define a keyboard shortcut for an IDAPython script”

  1. Пользовался ранее и буду пользоваться дальше.

  2. Да, лучше бы Вы писали по человечески.

  3. 😀

  4. […] the help of some friends i managed to get a way to reuse the tip I've previously shared with you here. The idea behind this post is to take advantage of the posibilities of using IDC in conditional […]

  5. […] help of some friends i managed to get a way to reuse the tip I’ve previously shared with you here. The idea behind this post is to take advantage of the posibilities of using IDC in conditional […]

  6. Really useful and very cool.. Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: