-
Notifications
You must be signed in to change notification settings - Fork 177
/
MyEmu.py
68 lines (47 loc) · 2.05 KB
/
MyEmu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# uEmu
from uEmu import *
MYEMU_USE_AS_SCRIPT = True # Set to `False` if you want to load MyEmu automatically as IDA Plugin
def myemu_log(entry):
uemu_log(entry, name = "MyEmu")
class MyEmuPlugin(uEmuPlugin):
### uEmuPlugin methods override
def __init__(self):
hooks = uEmuExtensionHooks()
hooks.init_context = self.hook_init_context
hooks.trace_log = self.hook_trace_log
hooks.emu_step = self.hook_emu_step
super(MyEmuPlugin, self).__init__("MyEmu", hooks)
def add_custom_menu(self):
self.MENU_ITEMS.append(UEMU_HELPERS.MenuItem(self.plugin_name + ":myemu_test", self.myemu_test, "MyEmu", "MyEmu", None, True ))
self.MENU_ITEMS.append(UEMU_HELPERS.MenuItem("-", self.do_nothing, "", None, None, True ))
def update_context(self, address, context):
super(MyEmuPlugin, self).update_context(address, context)
myemu_log("MyEmu update context")
def close_windows(self):
super(MyEmuPlugin, self).close_windows()
myemu_log("MyEmu close windows")
### uEmuUnicornEngine hooks
def hook_init_context(self):
myemu_log("MyEmu context init")
# return False to let uEmu init context, True otherwise
return False
def hook_trace_log(self, pc):
bytes = IDAAPI_GetBytes(pc, IDAAPI_NextHead(pc) - pc)
bytes_hex = UEMU_HELPERS.bytes_to_str(bytes)
myemu_log("* MYTRACE<I> 0x%X | %-16s | %s" % (pc, bytes_hex, IDAAPI_GetDisasm(pc, 0)))
# return False to let uEmu output its own trace log, True otherwise
return True
def hook_emu_step(self, pc):
myemu_log("MyEmu emulation step")
# return False to let uEmu execute next instruction, True otherwise
return False
### MyEmuPlugin methods
def myemu_test(self):
myemu_log("MyEmu menu click")
def PLUGIN_ENTRY():
return MyEmuPlugin()
if MYEMU_USE_AS_SCRIPT:
if __name__ == '__main__':
MyEmu = MyEmuPlugin()
MyEmu.init()
MyEmu.run()