Skip to content

Commit 656a95f

Browse files
committed
Add current_il_instructions magic variable in the Python console. Fix Vector35#4327.
1 parent a693c79 commit 656a95f

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

binaryninjacore.h

+6
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,12 @@ extern "C"
27932793
uint64_t end;
27942794
} BNAddressRange;
27952795

2796+
typedef struct BNILIndexRange
2797+
{
2798+
size_t start;
2799+
size_t end;
2800+
} BNILIndexRange;
2801+
27962802
typedef struct BNSystemCallInfo
27972803
{
27982804
uint32_t number;

python/scriptingprovider.py

+17
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ def __init__(self, instance):
680680
"current_il_index",
681681
"current_il_function",
682682
"current_il_instruction",
683+
"current_il_instructions",
683684
"current_il_basic_block"
684685
}
685686
self.locals = BlacklistedDict(
@@ -709,6 +710,7 @@ def __init__(self, instance):
709710
self.active_file_offset = None
710711
self.active_dbg = None
711712
self.active_il_index = 0
713+
self.selection_start_il_index = 0
712714
self.active_il_function = None
713715

714716
self.locals.blacklist_enabled = False
@@ -899,6 +901,9 @@ def update_locals(self):
899901
elif action_handler is not None:
900902
action_context = action_handler.actionContext()
901903

904+
if view is not None:
905+
self.selection_start_il_index = view.getSelectionStartILInstructionIndex()
906+
902907
token_state = None
903908
token = None
904909
var = None
@@ -935,15 +940,26 @@ def update_locals(self):
935940
except:
936941
self.locals["current_il_instruction"] = None
937942

943+
invalid_il_index = 0xffffffffffffffff
944+
if invalid_il_index not in (self.active_il_index, self.selection_start_il_index):
945+
il_start = min(self.active_il_index, self.selection_start_il_index)
946+
il_end = max(self.active_il_index, self.selection_start_il_index)
947+
self.locals["current_il_instructions"] = (self.active_il_function[i] for i in \
948+
range(il_start, il_end + 1))
949+
else:
950+
self.locals["current_il_instructions"] = None
951+
938952
if self.locals["current_il_instruction"]:
939953
self.locals["current_il_basic_block"] = self.locals["current_il_instruction"].il_basic_block
940954
else:
941955
self.locals["current_il_instruction"] = None
956+
self.locals["current_il_instructions"] = None
942957
self.locals["current_il_basic_block"] = None
943958
else:
944959
self.locals["current_il_index"] = None
945960
self.locals["current_il_function"] = None
946961
self.locals["current_il_instruction"] = None
962+
self.locals["current_il_instructions"] = None
947963
self.locals["current_il_basic_block"] = None
948964
self.active_il_function = None
949965

@@ -971,6 +987,7 @@ def update_locals(self):
971987
self.locals["current_il_index"] = None
972988
self.locals["current_il_function"] = None
973989
self.locals["current_il_instruction"] = None
990+
self.locals["current_il_instructions"] = None
974991
self.locals["current_il_basic_block"] = None
975992

976993
self.locals.blacklist_enabled = True

ui/flowgraphwidget.h

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class BINARYNINJAUIAPI FlowGraphWidget :
279279
virtual MediumLevelILFunctionRef getCurrentMediumLevelILFunction() override;
280280
virtual HighLevelILFunctionRef getCurrentHighLevelILFunction() override;
281281
virtual size_t getCurrentILInstructionIndex() override;
282+
virtual size_t getSelectionStartILInstructionIndex() override;
283+
virtual BNILIndexRange getILIndexRange() override;
282284

283285
void scrollToCursor(bool center = false);
284286
bool isUpdating();

ui/linearview.h

+2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ private Q_SLOTS:
408408
virtual BasicBlockRef getCurrentBasicBlock() override;
409409
virtual ArchitectureRef getCurrentArchitecture() override;
410410
virtual size_t getCurrentILInstructionIndex() override;
411+
virtual size_t getSelectionStartILInstructionIndex() override;
412+
virtual BNILIndexRange getILIndexRange() override;
411413
virtual bool navigate(uint64_t offset) override;
412414
virtual bool navigateToFunction(FunctionRef func, uint64_t offset) override;
413415
virtual bool navigateToViewLocation(const ViewLocation& viewLocation, bool center = false) override;

ui/viewframe.h

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class BINARYNINJAUIAPI View
228228
virtual BNFunctionGraphType getILViewType() { return InvalidILViewType; }
229229
virtual void setILViewType(BNFunctionGraphType ilViewType) {}
230230
virtual size_t getCurrentILInstructionIndex() { return BN_INVALID_EXPR; }
231+
virtual size_t getSelectionStartILInstructionIndex() { return BN_INVALID_EXPR; }
232+
virtual BNILIndexRange getILIndexRange() { return {BN_INVALID_EXPR, BN_INVALID_EXPR}; }
231233

232234
virtual QFont getFont() = 0;
233235
virtual DisassemblySettingsRef getDisassemblySettings();

0 commit comments

Comments
 (0)