参考:http://www.hexblog.com/?p=119
https://github.com/EiNSTeiN-/idapython/tree/master/examples
Using custom viewers from IDAPython
The simplest custom viewer which does not handle any events (like key presses, mouse or cursor position movements, displaying hints, etc) can be created like this:
v = idaapi.simplecustviewer_t()
if v.Create("Simple custom viewer"):
for i in xrange(1, 11):
v.AddLine("Line %d" % i)
v.Show()
else:
print "Failed to create viewer"
处理用户事件的窗体
class mycv_t(simplecustviewer_t):
def Create(self, sn=None):
# Form the title
title = "Simple custom view test"
if sn:
title += " %d" % sn
# Create the customview
if not simplecustviewer_t.Create(self, title):
return False
self.menu_hello = self.AddPopupMenu("Hello")
self.menu_world = self.AddPopupMenu("World")
for i in xrange(0, 100):
self.AddLine("Line %d" % i)
return True
def OnKeydown(self, vkey, shift):
# ESCAPE?
if vkey == 27:
self.Close()
# Goto?
elif vkey == ord('G'):
n = self.GetLineNo()
if n is not None:
v = idc.AskLong(self.GetLineNo(), "Where to go?")
if v:
self.Jump(v, 0, 5)
elif vkey == ord('R'):
print "refreshing...."
self.Refresh()
else:
return False
return True
def OnPopupMenu(self, menu_id):
if menu_id == self.menu_hello:
print "Hello"
elif menu_id == self.menu_world:
print "World"
else:
# Unhandled
return False
return True
调用
view = mycv_t()
if view.Create(1):
view.Show()
建立用户菜单(对 idaapi.IDA_SDK_VERSION==700 运行不了!)
参见:https://www.programcreek.com/python/example/83980/idaapi.add_menu_item
Example 1
def init(self):
global initialized
if initialized == False:
initialized = True
# menu = idaapi.add_menu_item("Edit/x64dbgida/", "About", "", 0,
# self.about, None)
# if menu is not None:
idaapi.attach_action_to_menu("Edit/x64dbgida/", 'my:exportdb', idaapi.SETMENU_APP)
idaapi.attach_action_to_menu("Edit/x64dbgida/", 'my:importdb', idaapi.SETMENU_APP)
# idaapi.add_menu_item("Edit/x64dbgida/",
# "Import (uncompressed) database", "", 0,
# self.importdb, None)
# elif idaapi.IDA_SDK_VERSION < 680:
# idaapi.add_menu_item("File/Produce file/",
# "Export x64dbg database", "", 0,
# self.exportdb, None)
# idaapi.add_menu_item("File/Load file/",
# "Import x64dbg database", "", 0,
# self.importdb, None)
return idaapi.PLUGIN_OK
Example 2
def init(self):
NO_HOTKEY = ""
SETMENU_INS = 0
NO_ARGS = tuple()
logger.debug("[+] %s.init()" % self.__class__.__name__)
self.menuitems = []
logger.debug("[+] setting up menus")
menu = idaapi.add_menu_item(self.wanted_menu[0],
self.wanted_menu[1],
NO_HOTKEY,
SETMENU_INS,
self.menu_config,
NO_ARGS)
self.menuitems.append(menu)
return idaapi.PLUGIN_KEEP
Example 3
def add(cls, path, name, fn, hotkey='', flags=0, args=()):
if (path,name) in cls.state:
cls.rm(path, name)
ctx = idaapi.add_menu_item(path, name, hotkey, flags, fn, args)
cls.state[path,name] = ctx
Example 4
def register_menu(self):
global g_bindiff
g_bindiff = self
idaapi.add_menu_item("Edit/Plugins/", "Diaphora - Show results", "F3", 0, show_choosers, ())
idaapi.add_menu_item("Edit/Plugins/", "Diaphora - Save results", None, 0, save_results, ())
idaapi.add_menu_item("Edit/Plugins/", "Diaphora - Load results", None, 0, load_results, ())
Warning("""AUTOHIDE REGISTRY\nIf you close one tab you can always re-open it by pressing F3
or selecting Edit -> Plugins -> Diaphora - Show results""")
Example 5
def RegisterMenuActions(handler):
global g_MenuList
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Unload Plugin", "SHIFT+CTRL+U", 0, handler.unloadPlugin, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Stop Server", None, 0, handler.stopServer, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Start Server", None, 0, handler.startServer, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Debug Log Toggle", None, 0, handler.logToggle, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Symbol Overwrite Toggle", None, 0, handler.overwriteSymbolToggle, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Settings", None, 0, handler.showSettings, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Close DB", None, 0, handler.showCloseDB, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Execute DB Query", None, 0, handler.showExecQuery, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Open DB", None, 0, handler.showOpenDB, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Create DB", None, 0, handler.showCreateDB, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Step Over Breakpoint", "SHIFT+CTRL+O", 0, handler.handleDebugStepOver, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Step Into Breakpoint", "SHIFT+CTRL+I", 0, handler.handleDebugStepInto, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Release Breakpoint", "SHIFT+CTRL+R", 0, handler.handleDebugContinue, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Target Log", None, 0, handler.showTargetLog, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show FRAPL Log", "SHIFT+CTRL+L", 0, handler.showFraplLog, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Address Converter", "SHIFT+CTRL+A", 0, handler.showAddressConverter, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Module List", None, 0, handler.showModuleList, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Memory Manager", "SHIFT+CTRL+M", 0, handler.showMemoryManager, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Arbitrary Hooks", None, 0, handler.showArbitraryHooks, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Replaced Funcs", None, 0, handler.showReplacedFuncs, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show Import Hooks", "SHIFT+CTRL+S", 0, handler.showImportHooks, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Show IDB Hooks", None, 0, handler.showDatabaseHooks, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Execute Frida Script", "SHIFT+CTRL+E", 0, handler.showExecScriptDlg, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Fetch Target Modules", None, 0, handler.requestModules, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Load Module", None, 0, handler.loadModule, ()))
add_menu_item( "Edit/Plugin/Frida Link/", "-", None, 0, handler.doNothing, ())
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Save Project", None, 0, handler.saveProject, ()))
g_MenuList.append(add_menu_item("Edit/Plugin/Frida Link/", "Load Project", None, 0, handler.loadProject, ()))
建立用户菜单(对应 idaapi.IDA_SDK_VERSION==700 !)
def init(self):
global initialized
if initialized == False:
initialized = True
if idaapi.IDA_SDK_VERSION <= 695 and idaapi.IDA_SDK_VERSION >= 680:
menu = idaapi.add_menu_item("Edit/x64dbgida/", "About", "", 0,
self.about, None)
idaapi.add_menu_item("Edit/x64dbgida/", "Export database", "",
0, self.exportdb, None)
idaapi.add_menu_item("Edit/x64dbgida/",
"Import (uncompressed) database", "", 0,
self.importdb, None)
elif idaapi.IDA_SDK_VERSION < 680:
idaapi.add_menu_item("File/Produce file/",
"Export x64dbg database", "", 0,
self.exportdb, None)
idaapi.add_menu_item("File/Load file/",
"Import x64dbg database", "", 0,
self.importdb, None)
if idaapi.IDA_SDK_VERSION >= 700:
#populating action menus
action_desc = idaapi.action_desc_t(
'my:aboutaction', # The action name. This acts like an ID and must be unique
'About!', # The action text.
AboutHandler(), # The action handler.
'', # Optional: the action shortcut
'About X64dbg ida', # Optional: the action tooltip (available in menus/toolbar)
) # Optional: the action icon (shows when in menus/toolbars) use numbers 1-255
# Register the action
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu(
'Edit/x64dbgida/',
'my:aboutaction',
idaapi.SETMENU_APP)
action_desc = idaapi.action_desc_t(
'my:eksportaction',
'Export x64dbg database',
EksportHandler(),
'',
'Export x64dbg database',
)
# Register the action
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu(
'Edit/x64dbgida/',
'my:eksportaction',
idaapi.SETMENU_APP)
action_desc = idaapi.action_desc_t(
'my:importaction',
'Import (uncompressed) database',
ImportHandler(),
'',
'Import (uncompressed) database',
)
# Register the action
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu(
'Edit/x64dbgida/',
'my:importaction',
idaapi.SETMENU_APP)
else:
pass
return idaapi.PLUGIN_KEEP