@@ -62,18 +62,15 @@ def actionFromSnippet(snippetName, snippetDescription):
62
62
else :
63
63
return "Snippets\\ " + snippetDescription
64
64
65
-
66
- def executeSnippet (code , context ):
65
+ def setupGlobals (context ):
67
66
snippetGlobals = {}
68
67
if context .binaryView == None :
69
68
dock = DockHandler .getActiveDockHandler ()
70
69
if not dock :
71
- log_error ("Snippet triggered with no context and no dock handler. This should not happen. Please report reproduction steps if possible." )
72
- return
70
+ return snippetGlobals
73
71
viewFrame = dock .getViewFrame ()
74
72
if not viewFrame :
75
- log_error ("Snippet triggered with no context and no view frame. Snippets require at least one open binary." )
76
- return
73
+ return snippetGlobals
77
74
viewInterface = viewFrame .getCurrentViewInterface ()
78
75
context .binaryView = viewInterface .getData ()
79
76
snippetGlobals ['current_view' ] = context .binaryView
@@ -109,12 +106,17 @@ def executeSnippet(code, context):
109
106
else :
110
107
snippetGlobals ['current_selection' ] = None
111
108
snippetGlobals ['uicontext' ] = context
109
+ return snippetGlobals
110
+
111
+
112
+ def executeSnippet (code , context ):
113
+ snippetGlobals = setupGlobals (context )
112
114
113
115
exec ("from binaryninja import *" , snippetGlobals )
114
116
exec (code , snippetGlobals )
115
- if snippetGlobals ['here' ] != context .address :
117
+ if hasattr ( snippetGlobals , "here" ) and snippetGlobals ['here' ] != context .address :
116
118
context .binaryView .file .navigate (context .binaryView .file .view , snippetGlobals ['here' ])
117
- if snippetGlobals ['current_address' ] != context .address :
119
+ if hasattr ( snippetGlobals , "current_address" ) and snippetGlobals ['current_address' ] != context .address :
118
120
context .binaryView .file .navigate (context .binaryView .file .view , snippetGlobals ['current_address' ])
119
121
120
122
0 commit comments