Skip to content

Commit

Permalink
Fixes a bug where the wrong function was retrieved
Browse files Browse the repository at this point in the history
Fixes a bug where the wrong function was retrieved, when there were overlapping functions that both contained the same address but where only one of them had an instruction starting at `addr` (i.e. the other one had `addr` is the middle of an instruction).
  • Loading branch information
Vasco-jofra authored and withzombies committed Jun 4, 2021
1 parent 5e5412c commit c0b8fe6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions __init__.py
Expand Up @@ -273,9 +273,21 @@ def collect_ils(bv, func):
return lookup


def get_function_containing_instruction_at(bv, addr):
# Ensure that the `Function` returned contains an instruction starting at `addr`
# This is needed in the case of overlapping functions where instructions are not aligned
functions = bv.get_functions_containing(addr) # type: List[Function]
for func in functions:
instr_addrs = [instr_addr for _, instr_addr in func.instructions]
if addr in instr_addrs:
return func

# Should never be reached
log_error("Found no function with instruction at address {:#x})".format(addr))


def graph_bnil(bv, addr):
blocks = bv.get_basic_blocks_at(addr) # type: List[BasicBlock]
function = blocks[0].function # type: Function
function = get_function_containing_instruction_at(bv, addr) # type: Function
g = binaryninja.FlowGraph()

(tokens,) = [
Expand Down Expand Up @@ -367,8 +379,7 @@ def match_condition(name, o):


def match_bnil(bv, addr):
blocks = bv.get_basic_blocks_at(addr) # type: List[BasicBlock]
function = blocks[0].function # type: Function
function = get_function_containing_instruction_at(bv, addr) # type: Function

lookup = collect_ils(bv, function)

Expand Down

0 comments on commit c0b8fe6

Please sign in to comment.