summaryrefslogtreecommitdiff
path: root/python/examples
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2020-01-25 02:35:04 -0500
committerJordan Wiens <jordan@psifertex.com>2020-01-25 02:35:04 -0500
commitbb20e584c4702fd7c1a861a8540e1b6e2652818c (patch)
tree35fdd921b300c0af04c3c50f8dd23be9dec20df8 /python/examples
parentae95e27021d681a81d4f0f7f9ac858fd39b16d63 (diff)
match behavior of script console so speceific function selected will still expose other forms
Diffstat (limited to 'python/examples')
-rw-r--r--python/examples/snippets/__init__.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/python/examples/snippets/__init__.py b/python/examples/snippets/__init__.py
index 41cd076e..5434010a 100644
--- a/python/examples/snippets/__init__.py
+++ b/python/examples/snippets/__init__.py
@@ -52,7 +52,26 @@ def executeSnippet(code, context):
snippetGlobals = {}
snippetGlobals['current_view'] = context.binaryView
snippetGlobals['bv'] = context.binaryView
- snippetGlobals['current_function'] = context.function
+ if not context.function:
+ if not context.lowLevelILFunction:
+ if not context.mediumLevelILFunction:
+ snippetGlobals['current_mlil'] = None
+ snippetGlobals['current_function'] = None
+ snippetGlobals['current_llil'] = None
+ else:
+ snippetGlobals['current_mlil'] = context.mediumLevelILFunction
+ snippetGlobals['current_function'] = context.mediumLevelILFunction.source_function
+ snippetGlobals['current_llil'] = context.mediumLevelILFunction.source_function.llil
+ else:
+ snippetGlobals['current_llil'] = context.lowLevelILFunction
+ snippetGlobals['current_function'] = context.lowLevelILFunction.source_function
+ snippetGlobals['current_mlil'] = context.lowLevelILFunction.source_function.mlil
+ else:
+ snippetGlobals['current_function'] = context.function
+ snippetGlobals['current_mlil'] = context.function.mlil
+ snippetGlobals['current_llil'] = context.function.llil
+ snippetGlobals['current_token'] = context.function.llil
+
if context.function is not None:
snippetGlobals['current_basic_block'] = context.function.get_basic_block_at(context.address)
else:
@@ -63,8 +82,7 @@ def executeSnippet(code, context):
snippetGlobals['current_selection'] = (context.address, context.address+context.length)
else:
snippetGlobals['current_selection'] = None
- snippetGlobals['current_llil'] = context.lowLevelILFunction
- snippetGlobals['current_mlil'] = context.mediumLevelILFunction
+ snippetGlobals['uicontext'] = context
exec("from binaryninja import *", snippetGlobals)
exec(code, snippetGlobals)