Created
July 21, 2023 13:52
-
-
Save n4sm/b3205efa8f10ac09b2b38a500cb79dba to your computer and use it in GitHub Desktop.
ARM64 bootloader / secure monitor function finder.
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
import idaapi | |
def find_sig(segment, sig, callback): | |
seg = idaapi.get_segm_by_name(segment) | |
if not seg: | |
return | |
ea, maxea = seg.start_ea, seg.end_ea | |
while ea != idaapi.BADADDR: | |
ea = idaapi.find_binary(ea, maxea, sig, 16, idaapi.SEARCH_DOWN) | |
if ea != idaapi.BADADDR: | |
callback(ea) | |
ea += 4 | |
def is_prologue_insn(ea): | |
insn = idaapi.insn_t() | |
idaapi.decode_insn(insn, ea) | |
return insn.itype in [idaapi.ARM_stp, idaapi.ARM_mov, idaapi.ARM_sub] | |
def callback(ea): | |
flags = idaapi.get_flags(ea) | |
if idaapi.is_unknown(flags): | |
while ea != idaapi.BADADDR: | |
if is_prologue_insn(ea - 4): | |
ea -= 4 | |
else: | |
print("[*] New function discovered at %#lx" % (ea)) | |
idaapi.add_func(ea, idaapi.BADADDR) | |
break | |
if idaapi.is_data(flags): | |
print("[!] %#lx needs manual review" % (ea)) | |
mov_x29_sp = "fd 03 00 91" | |
find_sig("ROM", mov_x29_sp, callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment