Skip to content

Commit c0b8fe6

Browse files
Vasco-jofrawithzombies
authored andcommitted
Fixes a bug where the wrong function was retrieved
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).
1 parent 5e5412c commit c0b8fe6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,21 @@ def collect_ils(bv, func):
273273
return lookup
274274

275275

276+
def get_function_containing_instruction_at(bv, addr):
277+
# Ensure that the `Function` returned contains an instruction starting at `addr`
278+
# This is needed in the case of overlapping functions where instructions are not aligned
279+
functions = bv.get_functions_containing(addr) # type: List[Function]
280+
for func in functions:
281+
instr_addrs = [instr_addr for _, instr_addr in func.instructions]
282+
if addr in instr_addrs:
283+
return func
284+
285+
# Should never be reached
286+
log_error("Found no function with instruction at address {:#x})".format(addr))
287+
288+
276289
def graph_bnil(bv, addr):
277-
blocks = bv.get_basic_blocks_at(addr) # type: List[BasicBlock]
278-
function = blocks[0].function # type: Function
290+
function = get_function_containing_instruction_at(bv, addr) # type: Function
279291
g = binaryninja.FlowGraph()
280292

281293
(tokens,) = [
@@ -367,8 +379,7 @@ def match_condition(name, o):
367379

368380

369381
def match_bnil(bv, addr):
370-
blocks = bv.get_basic_blocks_at(addr) # type: List[BasicBlock]
371-
function = blocks[0].function # type: Function
382+
function = get_function_containing_instruction_at(bv, addr) # type: Function
372383

373384
lookup = collect_ils(bv, function)
374385

0 commit comments

Comments
 (0)