I use this code snippet when I need to find, define, and do the auto-analysis of every function starting by a specific stub:
from idaapi import *
from ida_search import *
from ida_funcs import *
cnt = 0
my_pattern = '' # The hex value of the opcodes you are looking for
def is_function(start_addr):
content = get_bytes(start_addr, 4, False).hex()
if content == my_pattern:
return True
return False
addr = find_unknown(0, 1)
while addr != BADADDR
is_valid = is_function(addr)
if is_valid:
add_func(addr)
cnt += 1
addr = find_unknown(addr, 1)
print('A total of ' + str(cnt) + ' new functions where defined')
In your, case, replace my_pattern
by the opcodes of the pattern that you are looking for. For instance, in ARM, the "MOV R12, SP" instruction is a good indicator of a new function, so I set my_pattern = '0DC0A0E1'
More details on this through this similar question: How to know when a subroutine starts when reversing an ARM64 file?