Skip to content

Instantly share code, notes, and snippets.

@SiD3W4y
Created August 9, 2019 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SiD3W4y/bb65362d6a7fddb0f9a79edce4928286 to your computer and use it in GitHub Desktop.
Save SiD3W4y/bb65362d6a7fddb0f9a79edce4928286 to your computer and use it in GitHub Desktop.
Binary ninja snippet script to add trace based function detection on gba roms (through mgba)
# Trace function detection
#
# Binary ninja script for trace based function detection on gba using
# the 'tracing' branch of this fork: https://github.com/SiD3W4y/mgba
path = get_open_filename_input("mgba trace file")
if not path:
show_message_box("Function detection", "Please specify a file")
lines = open(path, "r").readlines()
funcs = []
for line in lines:
line = line.strip()
if len(line) > 5:
chks = line.split(" ")
if len(chks) == 2:
funcs.append(int(chks[0], 16))
duplicates = 0
for fnaddr in funcs:
fns = bv.get_functions_containing(fnaddr)
# We found a new function
if not fns:
bv.create_user_function(fnaddr, plat=Architecture["thumb2"].standalone_platform)
else:
duplicates += 1
show_message_box("Function detection", "{} functions found ({} duplicates)".format(len(funcs), duplicates))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment