Skip to content

Instantly share code, notes, and snippets.

@sl4v
Created May 19, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sl4v/9f4c813102aaa13afdcc5a9184628c2c to your computer and use it in GitHub Desktop.
Save sl4v/9f4c813102aaa13afdcc5a9184628c2c to your computer and use it in GitHub Desktop.
from binaryninja import *
class Slicer():
def __init__(self, instruction):
self.visited = set()
self.instruction = instruction
self.function = instruction.function
def visit_backward(self, instruction):
for var in instruction.vars_read:
if type(var) != mediumlevelil.SSAVariable:
return
var_def = self.function.get_ssa_var_definition(var)
if var_def is not None and var_def not in self.visited:
self.visited.add(var_def)
self.visit_backward(self.function[var_def])
def bw_slice(bv,instruction):
do_slice(bv, instruction, 'BW')
def do_slice(bv,instruction, action):
sl = Slicer(instruction.ssa_form)
if action == 'BW':
sl.visit_backward(instruction.ssa_form)
print('[Slicer] Visited: ' + ','.join(str(v) for v in sl.visited))
color = HighlightStandardColor.WhiteHighlightColor
bv.begin_undo_actions()
sl.function.source_function.set_user_instr_highlight(instruction.address, color)
for vr in sl.visited:
inst = sl.function[vr]
sl.function.source_function.set_user_instr_highlight(inst.address, color)
bv.commit_undo_actions()
PluginCommand.register_for_medium_level_il_instruction("BW Slice", "", bw_slice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment