首页
社区
课程
招聘
[求助]idapython addhotkey
2016-1-8 10:25 6915

[求助]idapython addhotkey

2016-1-8 10:25
6915
如果使用idc,可以通过以下方式添加快捷方式,使用起来正常
#include <idc.idc>

static hello_idc()
{
    Message("hello idc");
}

static main()
{
    AddHotkey("z", "hello_idc");
}
因为idapython更为强大,所以想改成idapython的
from idaapi import *
from idc import *

def hello_idapython():
    print "hello idapython"
   
def main():
    AddHotkey("z", "hello_idapython")

if __name__ == "__main__":
    main()
不过使用的时候会报错,
Runtime error:Attempt to call undefined function 'hello_idapython'
是我AddHotkey参数写错了,还是idapython模式下就不可行,请大神指教,先谢了。

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞0
打赏
分享
最新回复 (5)
雪    币: 1517
活跃值: (3290)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小希希 2016-1-8 12:20
2
0
AddHotkey

// Add hotkey for IDC function
//      hotkey  - hotkey name ('a', "Alt-A", etc)
//      idcfunc - IDC function name
// returns:
#define IDCHK_OK        0       // ok
#define IDCHK_ARG       -1      // bad argument(s)
#define IDCHK_KEY       -2      // bad hotkey name
#define IDCHK_MAX       -3      // too many IDC hotkeys

long AddHotkey(string hotkey,string idcfunc);

看说明要求 idcfunc,python func不行
雪    币: 2145
活跃值: (383)
能力值: ( LV9,RANK:200 )
在线值:
发帖
回帖
粉丝
疯子 4 2016-1-8 13:20
3
0
from idaapi import *
from idc import *

def hello_idapython():
    print "hello idapython"

def main():
    CompileLine(r'static idc_hello_idapython() { RunPythonStatement("hello_idapython()"); }')
    AddHotkey("z", "idc_hello_idapython")

if __name__ == "__main__":
    main()
雪    币: 1969
活跃值: (46)
能力值: (RANK:550 )
在线值:
发帖
回帖
粉丝
hawking 12 2016-1-8 13:59
4
0
谢谢 能用快捷方式实在是太好了
雪    币: 2145
活跃值: (383)
能力值: ( LV9,RANK:200 )
在线值:
发帖
回帖
粉丝
疯子 4 2016-1-8 14:08
5
0
FYI . copy from IDAscope.py

    def registerHotkey(self, shortcut, py_function_pointer):
        """
        Can be used by IDAscope widgets to register hotkeys.
        Uses a global list HOTKEYS of function pointers that link to the desired functionality.
        Right now, linked functions cannot take parameters and should scrape all information they need by themselves.
        @param shortcut: A string describing a shortcut, e.g. "ctrl+F3"
        @type shortcut: str
        @param py_function_pointer: a python function that shall be called when the shortcut is triggered.
        @type py_function_pointer: a pointer to a python function
        """
        global HOTKEYS
        hotkey_index = len(HOTKEYS)
        hotkey_name = "idascope_HOTKEY_%d" % hotkey_index
        HOTKEYS.append(py_function_pointer)
        self.ida_proxy.CompileLine('static %s() { RunPythonStatement("HOTKEYS[%d]()"); }' % (hotkey_name, hotkey_index))
        self.ida_proxy.AddHotkey(shortcut, hotkey_name)
雪    币: 1969
活跃值: (46)
能力值: (RANK:550 )
在线值:
发帖
回帖
粉丝
hawking 12 2016-1-11 10:30
6
0
受教了:)
游客
登录 | 注册 方可回帖
返回