summaryrefslogtreecommitdiff
path: root/python/examples/arch_hook.py
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-02-26 22:37:19 -0500
committerRusty Wagner <rusty@vector35.com>2018-02-26 23:04:10 -0500
commit105fb2549bd8fc0e19907fefff1168322dee3bb3 (patch)
tree0f00c3846356f142804e65c458f47bbf51a4dad4 /python/examples/arch_hook.py
parentbfce40850be6f6df4138d717798d4d0d35865908 (diff)
Architecture plugins no longer need to override the perform_* methods (you can now override get_instruction_info, not perform_get_instruction_info). The perform_* methods are now deprecated but will still function as expected. Added architecture hooks to Python API using this new style.
Diffstat (limited to 'python/examples/arch_hook.py')
-rw-r--r--python/examples/arch_hook.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/python/examples/arch_hook.py b/python/examples/arch_hook.py
new file mode 100644
index 00000000..452bd2b6
--- /dev/null
+++ b/python/examples/arch_hook.py
@@ -0,0 +1,16 @@
+from binaryninja.architecture import Architecture, ArchitectureHook
+
+class X86ReturnHook(ArchitectureHook):
+ def get_instruction_text(self, data, addr):
+ # Call the original implementation's method by calling the superclass
+ result, length = super(X86ReturnHook, self).get_instruction_text(data, addr)
+
+ # Patch the name of the 'retn' instruction to 'ret'
+ if len(result) > 0 and result[0].text == 'retn':
+ result[0].text = 'ret'
+
+ return result, length
+
+# Install the hook by constructing it with the desired architecture to hook, then registering it
+X86ReturnHook(Architecture['x86']).register()
+