Skip to content

Commit

Permalink
uEmu: Fixes to load automatically as IDA plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhude committed Sep 26, 2017
1 parent 4950b7c commit cbaa285
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Supports following architectures out of the box: **x86**, **x64**, **ARM**, **AR
- `pip install unicorn` to install Unicorn python bindings
- Use `File / Script file...` or `ALT+F7` in IDA to load **uEmu.py**

Optionally **uEmu** can be loaded automatically as IDA plugin. In this case put it into [IDA]/Plugins folder and change `USE_AS_SCRIPT` to `False` inside **uEmu.py**

## Features

### Popup Menu
Expand Down
38 changes: 24 additions & 14 deletions uEmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Copyright (c) 2017 Alexander Hude. All rights reserved.
#

USE_AS_SCRIPT = True # Set to `False` if you want to load uEmu automatically as IDA Plugin

import pickle
import threading
import json
Expand Down Expand Up @@ -1183,11 +1185,11 @@ class uEmuPlugin(plugin_t, UI_Hooks):

popup_menu_hook = None

flags = PLUGIN_KEEP
flags = PLUGIN_HIDE
comment = ""

help = "Tiny cute emulator"
wanted_name = "Plugin"
wanted_name = PLUGIN_MENU_NAME
wanted_hotkey = ""

# --- PLUGIN DATA
Expand All @@ -1209,6 +1211,7 @@ class uEmuPlugin(plugin_t, UI_Hooks):

def init(self):
super(uEmuPlugin, self).__init__()
self.hook_ui_actions()
uemu_log("Init plugin")
return PLUGIN_KEEP

Expand All @@ -1219,14 +1222,13 @@ def run(self, arg = 0):
uemu_log("Run plugin")
self.register_menu_actions()
self.attach_main_menu_actions()
self.hook_popup_menu_actions()
self.unicornEngine = UnicornEngine(self)

def term(self): # asynchronous unload (external, UI_Hook::term)
self.unicornEngine = None
self.unhook_popup_menu_actions()
self.unhook_ui_actions()
self.detach_main_menu_actions()
self.unregister_actions();
self.unregister_menu_actions()
uemu_log("Unload plugin")

def get_context_columns(self):
Expand All @@ -1235,11 +1237,17 @@ def get_context_columns(self):
def unload_plugin(self): # synchronous unload (internal, Main Menu)
self.unregister_popup_menu_actions()
self.unregister_main_menu_actions()
self.unregister_actions();
self.unregister_menu_actions()

def do_nothing(self):
pass

def ready_to_run(self):
uemu_log("UI ready. Run plugin")
self.register_menu_actions()
self.attach_main_menu_actions()
self.unicornEngine = UnicornEngine(self)

def follow_pc(self):
return self.settings["follow_pc"];

Expand Down Expand Up @@ -1386,11 +1394,11 @@ def detach_main_menu_actions(self):

# --- POPUP MENU

def hook_popup_menu_actions(self):
def hook_ui_actions(self):
self.popup_menu_hook = self
self.popup_menu_hook.hook()

def unhook_popup_menu_actions(self):
def unhook_ui_actions(self):
if self.popup_menu_hook != None:
self.popup_menu_hook.unhook()

Expand Down Expand Up @@ -1612,9 +1620,11 @@ def show_settings(self):
self.settings["force_code"] = True if settingsDlg.emu_group.value & kSettingsMask_ForceCode else False
self.settings["trace_inst"] = True if settingsDlg.emu_group.value & kSettingsMask_TraceInst else False

#def PLUGIN_ENTRY():
# return PluginPlugin()
if __name__ == '__main__':
uEmu = uEmuPlugin()
uEmu.init()
uEmu.run()
def PLUGIN_ENTRY():
return uEmuPlugin()

if USE_AS_SCRIPT:
if __name__ == '__main__':
uEmu = uEmuPlugin()
uEmu.init()
uEmu.run()

0 comments on commit cbaa285

Please sign in to comment.