Skip to content

Commit 90623cc

Browse files
committed
Move from whitelist/blacklist variable names to included/excluded; API changes required for HighLevelLanguageRepresentations; Update copywrite year; Increment version; Update minimum version and remove <3505 compatibility
1 parent 9692d53 commit 90623cc

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021-2022 Vector 35 Inc
1+
Copyright (c) 2021-2024 Vector 35 Inc
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For a more detailed explanation of what Tantō does, please check out [this blog
1212

1313
This plugin requires the following minimum version of Binary Ninja:
1414

15-
* 3.0.3223
15+
* 4.1.6249
1616

1717
## License
1818

__init__.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Copyright(c) 2021-2022 Vector 35 Inc
1+
# Copyright(c) 2021-2024 Vector 35 Inc
22
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy
4-
# of this software and associated documentation files(the "Software"), to
4+
# of this software and associated documentation files (the "Software"), to
55
# deal in the Software without restriction, including without limitation the
66
# rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
77
# sell copies of the Software, and to permit persons to whom the Software is
@@ -51,7 +51,7 @@ def get_bb(context: UIActionContext) -> Optional[Tuple[BinaryView, ILFunction, I
5151
return
5252

5353
bv = context.binaryView
54-
func = recover_current_function(context.function, view_context.getCurrentViewFrame().getViewLocation().getILViewType())
54+
func = recover_current_function(context.function, view_context.getCurrentViewFrame().getViewLocation().getILViewType().view_type)
5555
addr: int = context.address
5656

5757
if bv is None or func is None or addr == 0:
@@ -90,7 +90,7 @@ def get_var(context: UIActionContext) -> Optional[Tuple[BinaryView, ILFunction,
9090
return
9191

9292
bv = context.binaryView
93-
func = recover_current_function(context.function, view_context.getCurrentViewFrame().getViewLocation().getILViewType())
93+
func = recover_current_function(context.function, view_context.getCurrentViewFrame().getViewLocation().getILViewType().view_type)
9494
addr: int = context.address
9595

9696
if bv is None or func is None or addr == 0:
@@ -130,9 +130,7 @@ def add_actions(key: int = 0, force: bool = False):
130130
UIActionHandler.globalActions().bindAction(f"Tanto\\Remove Variable from Slice{postfix}", UIAction(function_wrapper(key, SlicePaneWidget.remove_variable_from_whitelist), function_wrapper()))
131131
UIActionHandler.globalActions().bindAction(f"Tanto\\Clear Selection{postfix}", UIAction(lambda context: PANES[key][1]().clear_selection(), lambda context: True))
132132

133-
parent_menu = "Tools"
134-
if int(core_version()[4:][:4]) >= 3505:
135-
parent_menu = "Plugins"
133+
parent_menu = "Plugins"
136134
Menu.mainMenu(parent_menu).addAction(f"Tanto\\Add Block to Slice{postfix}", "TantoGroup0", 0)
137135
Menu.mainMenu(parent_menu).addAction(f"Tanto\\Remove Block from Slice{postfix}", "TantoGroup0", 0)
138136
Menu.mainMenu(parent_menu).addAction(f"Tanto\\Add Variable to Slice{postfix}", "TantoGroup1", 1)
@@ -141,9 +139,7 @@ def add_actions(key: int = 0, force: bool = False):
141139

142140

143141
def setup_actions():
144-
parent_menu = "Tools"
145-
if int(core_version()[4:][:4]) >= 3505:
146-
parent_menu = "Plugins"
142+
parent_menu = "Plugins"
147143

148144
# Unregister interaction methods
149145
for action in UIAction.getAllRegisteredActions():
@@ -186,6 +182,7 @@ def get_disassembly_settings():
186182

187183

188184
def recover_current_basic_block(instr: LowLevelILInstruction, il_form: FunctionGraphType):
185+
assert isinstance(il_form, FunctionGraphType)
189186
if il_form == FunctionGraphType.NormalFunctionGraph:
190187
return instr.il_basic_block.source_block
191188
elif il_form == FunctionGraphType.LiftedILFunctionGraph:
@@ -207,10 +204,12 @@ def recover_current_basic_block(instr: LowLevelILInstruction, il_form: FunctionG
207204
elif il_form == FunctionGraphType.HighLevelILSSAFormFunctionGraph:
208205
return instr.hlil.ssa_form.il_basic_block
209206
else:
207+
log_error(f"IL form {il_form.name} not supported in Tanto")
210208
return None
211209

212210

213211
def recover_current_function(func: Function, il_form: FunctionGraphType):
212+
assert isinstance(il_form, FunctionGraphType)
214213
if il_form == FunctionGraphType.NormalFunctionGraph:
215214
return func
216215
elif il_form == FunctionGraphType.LowLevelILFunctionGraph:
@@ -232,6 +231,7 @@ def recover_current_function(func: Function, il_form: FunctionGraphType):
232231
elif il_form == FunctionGraphType.HighLevelILSSAFormFunctionGraph:
233232
return func.hlil.ssa_form
234233
else:
234+
log_error(f"IL form {il_form.name} not supported in Tanto")
235235
return None
236236

237237

@@ -297,9 +297,9 @@ def __init__(self, bv, n):
297297
# Slice vars
298298
self.bv: BinaryView = None
299299
self.func = None
300-
self.block_blacklist = []
301-
self.block_whitelist = []
302-
self.variable_whitelist = []
300+
self.excluded_blocks = []
301+
self.included_blocks = []
302+
self.included_variables = []
303303

304304
# Binary Graph Area
305305
self.flow_graph_widget = FlowGraphWidget(None, self.bv)
@@ -464,9 +464,9 @@ def clear_graph(self):
464464
self.flow_graph_widget.setGraph(None)
465465

466466
def clear_selection(self):
467-
self.block_blacklist.clear()
468-
self.block_whitelist.clear()
469-
self.variable_whitelist.clear()
467+
self.excluded_blocks.clear()
468+
self.included_blocks.clear()
469+
self.included_variables.clear()
470470

471471
if self.func is None:
472472
return
@@ -484,50 +484,50 @@ def clear_selection(self):
484484
self.clear_graph()
485485

486486
def add_block_to_whitelist(self, bv, func, bb):
487-
self.variable_whitelist = [] # Only do variable slices or block slices at any given time
487+
self.included_variables = [] # Only do variable slices or block slices at any given time
488488

489489
if self.bv is not None and self.func is not None and (self.bv != bv or self.func != func):
490490
self.clear_selection()
491491
self.bv = bv
492492
self.func = func
493493

494-
if bb in self.block_blacklist:
495-
self.block_blacklist.remove(bb)
496-
self.block_whitelist.append(bb)
494+
if bb in self.excluded_blocks:
495+
self.excluded_blocks.remove(bb)
496+
self.included_blocks.append(bb)
497497
self.update_graph()
498498

499499
def add_block_to_blacklist(self, bv, func, bb):
500-
self.variable_whitelist = [] # Only do variable slices or block slices at any given time
500+
self.included_variables = [] # Only do variable slices or block slices at any given time
501501

502502
if self.bv is not None and self.func is not None and (self.bv != bv or self.func != func):
503503
self.clear_selection()
504504
self.bv = bv
505505
self.func = func
506506

507-
if bb in self.block_whitelist:
508-
self.block_whitelist.remove(bb)
509-
self.block_blacklist.append(bb)
507+
if bb in self.included_blocks:
508+
self.included_blocks.remove(bb)
509+
self.excluded_blocks.append(bb)
510510
self.update_graph()
511511

512512
def add_variable_to_whitelist(self, bv, func, var):
513513
# Only do variable slices or block slices at any given time
514-
self.block_whitelist = []
515-
self.block_blacklist = []
514+
self.included_blocks = []
515+
self.excluded_blocks = []
516516

517517
if self.bv is not None and self.func is not None and (self.bv != bv or self.func != func):
518518
self.clear_selection()
519519
self.bv = bv
520520
self.func = func
521521

522522
if var is not None:
523-
if var not in self.variable_whitelist:
524-
self.variable_whitelist.append(var)
523+
if var not in self.included_variables:
524+
self.included_variables.append(var)
525525
self.update_graph()
526526

527527
def remove_variable_from_whitelist(self, bv, func, var):
528528
# Only do variable slices or block slices at any given time
529-
self.block_whitelist = []
530-
self.block_blacklist = []
529+
self.included_blocks = []
530+
self.excluded_blocks = []
531531

532532
if self.bv is not None and self.func is not None and (self.bv != bv or self.func != func):
533533
self.clear_selection()
@@ -538,13 +538,13 @@ def remove_variable_from_whitelist(self, bv, func, var):
538538
self.func = func
539539

540540
if var is not None:
541-
if var in self.variable_whitelist:
542-
self.variable_whitelist.remove(var)
541+
if var in self.included_variables:
542+
self.included_variables.remove(var)
543543
self.update_graph()
544544

545545
def calculate_basic_block_slice(self):
546546
def reach_up(il_bb, visited):
547-
if il_bb in visited or il_bb in self.block_blacklist:
547+
if il_bb in visited or il_bb in self.excluded_blocks:
548548
return []
549549
visited.append(il_bb)
550550

@@ -554,7 +554,7 @@ def reach_up(il_bb, visited):
554554
return result
555555

556556
def reach_down(il_bb, visited):
557-
if il_bb in visited or il_bb in self.block_blacklist:
557+
if il_bb in visited or il_bb in self.excluded_blocks:
558558
return []
559559
visited.append(il_bb)
560560

@@ -564,7 +564,7 @@ def reach_down(il_bb, visited):
564564
return result
565565

566566
result = set()
567-
for bb in self.block_whitelist:
567+
for bb in self.included_blocks:
568568
result.update(set(reach_up(bb, []) + reach_down(bb, [])))
569569
return result
570570

@@ -590,7 +590,7 @@ def reach_down(il_bb, function_slice, visited):
590590

591591
return reach_down(bb, function_slice, set())
592592

593-
@ staticmethod
593+
@staticmethod
594594
def update_all_graphs():
595595
for _, widget in PANES.values():
596596
widget().update_graph()
@@ -608,9 +608,9 @@ def update_graph(self):
608608
for inst in get_insts(bb):
609609
func.set_auto_instr_highlight(inst.address, HighlightStandardColor.NoHighlightColor)
610610

611-
if len(self.variable_whitelist) != 0:
611+
if len(self.included_variables) != 0:
612612
self.update_variables_slices_graph()
613-
elif len(self.block_whitelist) != 0:
613+
elif len(self.included_blocks) != 0:
614614
self.update_block_slices_graph()
615615

616616
def update_block_slices_graph(self):
@@ -637,12 +637,12 @@ def update_block_slices_graph(self):
637637
for inst in get_insts(bb):
638638
func.set_auto_instr_highlight(inst.address, HighlightStandardColor.RedHighlightColor)
639639
if self.decomp_block_selection_highlight:
640-
for bb in self.block_whitelist:
640+
for bb in self.included_blocks:
641641
bb.set_auto_highlight(HighlightStandardColor.GreenHighlightColor)
642642
if self.decomp_line_highlight:
643643
for inst in get_insts(bb):
644644
func.set_auto_instr_highlight(inst.address, HighlightStandardColor.GreenHighlightColor)
645-
for bb in self.block_blacklist:
645+
for bb in self.excluded_blocks:
646646
bb.set_auto_highlight(HighlightStandardColor.WhiteHighlightColor)
647647
if self.decomp_line_highlight:
648648
for inst in get_insts(bb):
@@ -668,7 +668,7 @@ def update_block_slices_graph(self):
668668
line.highlight = HighlightStandardColor.NoHighlightColor
669669

670670
# Duplicate selection highlight in new graph
671-
if self.slice_block_selection_highlight and basic_block in self.block_whitelist:
671+
if self.slice_block_selection_highlight and basic_block in self.included_blocks:
672672
new_node.highlight = HighlightStandardColor.GreenHighlightColor
673673

674674
new_graph.append(new_node)
@@ -703,7 +703,7 @@ def update_block_slices_graph(self):
703703

704704
def update_variables_slices_graph(self):
705705
keep_indexes = set()
706-
for var in self.variable_whitelist:
706+
for var in self.included_variables:
707707
for bb in self.func:
708708
for inst in bb:
709709
if self.func.il_form in [FunctionGraphType.LowLevelILSSAFormFunctionGraph, FunctionGraphType.MediumLevelILSSAFormFunctionGraph, FunctionGraphType.MappedMediumLevelILSSAFormFunctionGraph, FunctionGraphType.HighLevelILSSAFormFunctionGraph]:
@@ -734,7 +734,7 @@ def update_variables_slices_graph(self):
734734
saved_lines = []
735735
for inst in basic_block:
736736
if inst.instr_index in keep_indexes:
737-
if instruction_contains_var(self.variable_whitelist, inst):
737+
if instruction_contains_var(self.included_variables, inst):
738738
saved_lines += [line for line in lines if line.il_instruction == inst]
739739
inst.function.source_function.set_auto_instr_highlight(inst.address, HighlightStandardColor.GreenHighlightColor)
740740
elif isinstance(inst, ControlFlow) and not isinstance(inst, Terminal):

plugin.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"longdescription": "",
1313
"license": {
1414
"name": "MIT",
15-
"text": "Copyright (c) 2021-2022 Vector 35 Inc\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
15+
"text": "Copyright (c) 2021-2024 Vector 35 Inc\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
1616
},
1717
"platforms": [
1818
"Darwin",
1919
"Linux",
2020
"Windows"
2121
],
2222
"dependencies": {},
23-
"version": "1.0.1",
23+
"version": "1.0.2",
2424
"author": "Vector 35 Inc",
25-
"minimumbinaryninjaversion": 3164
25+
"minimumbinaryninjaversion": 6249
2626
}

0 commit comments

Comments
 (0)