Skip to content

Commit

Permalink
Merge pull request #49 from UsernameFodder/extract-function
Browse files Browse the repository at this point in the history
Handle blx instructions in extract_function.py
  • Loading branch information
AnonymousRandomPerson authored Dec 27, 2023
2 parents 76e5d10 + 75934d8 commit a7f3f00
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tools/extract_function/extract_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def get_line_address(line: str):
lsf_lines[i] += f'\tObject asm/{file_prefix}{new_file_address}.o\n'
break


BRANCH_LABEL_INSTRUCTION = '\tbl '
BRANCH_LINK_INSTRUCTION = '\tbl '
BRANCH_LINK_EXCHANGE_INSTRUCTION = '\tblx '
BRANCH_INSTRUCTION = '\tb '
WORD_KEY = '.word '
WORD_PLUS_OFFSET = ' + 0x'
Expand All @@ -124,13 +124,19 @@ def write_inc_file(lines: List[str], file_path: str):
for line in lines:
if line.startswith(ARM_FUNC_START):
defined_functions.add(line[len(ARM_FUNC_START) : -1])
elif line.startswith(BRANCH_LABEL_INSTRUCTION):
used_functions.add(line[len(BRANCH_LABEL_INSTRUCTION) : -1])
elif line.startswith(BRANCH_LINK_INSTRUCTION):
used_functions.add(line[len(BRANCH_LINK_INSTRUCTION) : -1])
elif line.startswith(BRANCH_INSTRUCTION):
function = line[len(BRANCH_INSTRUCTION) : -1]
if function[0] != '_':
semicolon_index = function.index(' ; ')
used_functions.add(function[:semicolon_index])
elif line.startswith(BRANCH_LINK_EXCHANGE_INSTRUCTION):
function = line[len(BRANCH_LINK_EXCHANGE_INSTRUCTION) : -1]
if function not in {'fp', 'ip', 'lr', 'sb', 'sl'} and not (
function.startswith('r') and function[1:].isdigit() # rN
):
used_functions.add(function)
else:
word_index = line.find(WORD_KEY)
if word_index >= 0 and f'{WORD_KEY}0x' not in line:
Expand Down

0 comments on commit a7f3f00

Please sign in to comment.