4
4
import os
5
5
import re
6
6
from PySide2 .QtWidgets import (QLineEdit , QPushButton , QApplication , QTextEdit , QWidget ,
7
- QVBoxLayout , QHBoxLayout , QDialog , QFileSystemModel , QTreeView , QLabel , QSplitter ,
7
+ QVBoxLayout , QHBoxLayout , QDialog , QFileSystemModel , QTreeView , QLabel , QSplitter ,
8
8
QInputDialog , QMessageBox , QHeaderView , QMenu , QAction , QKeySequenceEdit ,
9
9
QPlainTextEdit )
10
10
from PySide2 .QtCore import (QDir , QObject , Qt , QFileInfo , QItemSelectionModel , QSettings )
11
11
from PySide2 .QtGui import (QFont , QFontMetrics , QDesktopServices , QKeySequence )
12
12
from binaryninja import user_plugin_path
13
13
from binaryninja .plugin import PluginCommand , MainThreadActionHandler
14
14
from binaryninja .mainthread import execute_on_main_thread
15
- from binaryninja .log import (log_info , log_warn , log_alert , log_debug )
15
+ from binaryninja .log import (log_error , log_debug )
16
16
from binaryninjaui import (getMonospaceFont , UIAction , UIActionHandler , Menu )
17
17
import numbers
18
18
@@ -36,14 +36,14 @@ def loadSnippetFromFile(snippetPath):
36
36
try :
37
37
snippetText = open (snippetPath , 'r' ).readlines ()
38
38
except :
39
- return (False , [], False )
39
+ return ("" , "" , "" )
40
40
if (len (snippetText ) < 3 ):
41
- return (False , [], False )
41
+ return ("" , "" , "" )
42
42
else :
43
43
qKeySequence = QKeySequence (snippetText [1 ].strip ()[1 :])
44
44
if qKeySequence .isEmpty ():
45
45
qKeySequence = None
46
- return (snippetText [0 ].strip ()[1 :],
46
+ return (snippetText [0 ].strip ()[1 :],
47
47
qKeySequence ,
48
48
'' .join (snippetText [2 :])
49
49
)
@@ -52,7 +52,26 @@ def executeSnippet(code, context):
52
52
snippetGlobals = {}
53
53
snippetGlobals ['current_view' ] = context .binaryView
54
54
snippetGlobals ['bv' ] = context .binaryView
55
- snippetGlobals ['current_function' ] = context .function
55
+ if not context .function :
56
+ if not context .lowLevelILFunction :
57
+ if not context .mediumLevelILFunction :
58
+ snippetGlobals ['current_mlil' ] = None
59
+ snippetGlobals ['current_function' ] = None
60
+ snippetGlobals ['current_llil' ] = None
61
+ else :
62
+ snippetGlobals ['current_mlil' ] = context .mediumLevelILFunction
63
+ snippetGlobals ['current_function' ] = context .mediumLevelILFunction .source_function
64
+ snippetGlobals ['current_llil' ] = context .mediumLevelILFunction .source_function .llil
65
+ else :
66
+ snippetGlobals ['current_llil' ] = context .lowLevelILFunction
67
+ snippetGlobals ['current_function' ] = context .lowLevelILFunction .source_function
68
+ snippetGlobals ['current_mlil' ] = context .lowLevelILFunction .source_function .mlil
69
+ else :
70
+ snippetGlobals ['current_function' ] = context .function
71
+ snippetGlobals ['current_mlil' ] = context .function .mlil
72
+ snippetGlobals ['current_llil' ] = context .function .llil
73
+ snippetGlobals ['current_token' ] = context .function .llil
74
+
56
75
if context .function is not None :
57
76
snippetGlobals ['current_basic_block' ] = context .function .get_basic_block_at (context .address )
58
77
else :
@@ -63,8 +82,7 @@ def executeSnippet(code, context):
63
82
snippetGlobals ['current_selection' ] = (context .address , context .address + context .length )
64
83
else :
65
84
snippetGlobals ['current_selection' ] = None
66
- snippetGlobals ['current_llil' ] = context .lowLevelILFunction
67
- snippetGlobals ['current_mlil' ] = context .mediumLevelILFunction
85
+ snippetGlobals ['uicontext' ] = context
68
86
69
87
exec ("from binaryninja import *" , snippetGlobals )
70
88
exec (code , snippetGlobals )
@@ -124,7 +142,7 @@ def __init__(self, parent=None):
124
142
self .tree .setRootIndex (self .files .index (snippetPath ))
125
143
for x in range (self .columns ):
126
144
#self.tree.resizeColumnToContents(x)
127
- self .tree .header ().setSectionResizeMode (x , QHeaderView .ResizeToContents )
145
+ self .tree .header ().setSectionResizeMode (x , QHeaderView .ResizeToContents )
128
146
treeLayout = QVBoxLayout ()
129
147
treeLayout .addWidget (self .tree )
130
148
treeButtons = QHBoxLayout ()
0 commit comments