Created
March 8, 2020 22:05
-
-
Save stong/0f0329ba911d8d50cea7076402056b5b to your computer and use it in GitHub Desktop.
Highlight instructions containing relocations in Binary Ninja
This file contains 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
def annotate_relocs(): | |
def find_relocation(bv, start, end): | |
# assume that relocations can't straddle functions | |
funcs = bv.get_functions_containing(start) | |
if not funcs: return | |
for func in funcs: | |
bb = func.get_basic_block_at(start) | |
if not bb: continue | |
bb._buildStartCache() | |
for i, insn_start in enumerate(bb._instStarts): | |
insn_end = insn_start + bb._instLengths[i] | |
if (insn_start < end and start < insn_end) or (start == end and start >= insn_start and start < insn_end): | |
yield (func, insn_start, bb._instLengths[i]) | |
for start, end in bv.relocation_ranges: | |
for func, insn_start, insn_len in find_relocation(bv, start, end): | |
func.set_auto_instr_highlight(insn_start, HighlightStandardColor.YellowHighlightColor) | |
llil_expr = func.get_low_level_il_at(insn_start) | |
print('start:', hex(start), 'end:', hex(end), 'instr:', hex(insn_start)) | |
if llil_expr: | |
llil_insn = func.llil[llil_expr.instr_index] | |
llil_start = llil_insn.address | |
if llil_start == insn_start: | |
func.set_auto_instr_highlight(llil_start, HighlightStandardColor.OrangeHighlightColor) | |
else: | |
func.set_auto_instr_highlight(llil_start, HighlightStandardColor.RedHighlightColor) | |
annotate_relocs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment