Created
May 19, 2018 15:18
-
-
Save sl4v/9f4c813102aaa13afdcc5a9184628c2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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