Skip to content

Commit

Permalink
IDA 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyuidesu authored Dec 5, 2024
2 parents 41b2a8f + 97d9212 commit dc4a22e
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions sephelper.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import sys
import idc
import idaapi
import ida_search
import ida_segment
import ida_bytes
import ida_funcs

def func64(base_ea, base_end_ea, name, sequence):
seq_ea = ida_search.find_binary(base_ea, base_end_ea, sequence, 0x10, ida_search.SEARCH_DOWN)
# Check the IDA version and Python version
ida_version = float(idaapi.get_kernel_version())
python_version = sys.version_info

if ida_version < 9.0:
# For IDA versions under 9.0, use additional imports
import ida_search

def search_for_bytes(prologue_bytes, ea, segment_end):
if ida_version < 9.0:
# For IDA versions under 9.0, use idc.search_bytes
return ida_search.find_binary(ea, segment_end, prologue_bytes, 0x10, ida_search.SEARCH_DOWN)
else:
# For IDA versions 9.0 and above, use ida_bytes.search
return idc.find_bytes(prologue_bytes, ea, range_end=segment_end)

if seq_ea != ida_idaapi.BADADDR:
def func64(base_ea, base_end_ea, name, sequence):
seq_ea = search_for_bytes(sequence, base_ea, base_end_ea)

if seq_ea != idc.BADADDR:
func = idaapi.get_func(seq_ea)
if func is not None:
print(" [sephelper]: %s = 0x%x" % (name, func.start_ea))
idc.set_name(func.start_ea, name, idc.SN_CHECK)
return func.start_ea

print(" [sephelper]: %s = NULL" % name)
return ida_idaapi.BADADDR
return idc.BADADDR

# Registers.
# https://siguza.github.io/APRR/
Expand Down Expand Up @@ -89,19 +104,19 @@ def accept_file(fd, fname):
fd.seek(0xc00) # 64bit SEPROM versions are located at 0xC00
search = fd.read(0x1A)

if search.startswith("private_build...("):
if search.startswith(b"private_build...("):
segbit = 2
base_addr = 0x240000000 # 64bit (A11+)
return { "format": "SEPROM (AArch64)", "processor": "arm" }
elif search.startswith("AppleSEPROM-"):
elif search.startswith(b"AppleSEPROM-"):
version = search[12:]
segbit, base_addr = file_info(version)
return { "format": "SEPROM (AArch64)", "processor": "arm" }

fd.seek(0x800) # 32bit SEPROM versions are located at 0x800
search = fd.read(0x10)

if search.startswith("AppleSEPROM-"):
if search.startswith(b"AppleSEPROM-"):
version = search[12:]
segbit, base_addr = file_info(version)
return { "format": "SEPROM (AArch32)", "processor": "arm" }
Expand All @@ -117,11 +132,9 @@ def load_file(fd, flags, format):
if segbit == 1:
print("[sephelper]: detected a 32bit SEPROM !")
idaapi.set_processor_type("arm:armv7-m", idaapi.SETPROC_LOADER_NON_FATAL)
idaapi.get_inf_structure().lflags |= idaapi.LFLG_PC_FLAT
else:
print("[sephelper]: detected a 64bit SEPROM !")
idaapi.set_processor_type("arm", idaapi.SETPROC_LOADER_NON_FATAL)
idaapi.get_inf_structure().lflags |= idaapi.LFLG_64BIT
idc.set_processor_type("arm:armv8-a", idc.SETPROC_LOADER_NON_FATAL)

if (flags & idaapi.NEF_RELOAD) != 0: return 1

Expand Down Expand Up @@ -162,16 +175,19 @@ def load_file(fd, flags, format):
hexcode = ["03 AF", "02 AF", "01 AF"]

for prologue in hexcode:
while ea != idc.BADADDR:
ea = ida_search.find_binary(ea, segment_end, prologue, 0x10, ida_search.SEARCH_DOWN)
if python_version >= (3, 0):
prologue = bytes.fromhex(prologue.replace(" ", ""))

while ea < segment_end:
ea = search_for_bytes(prologue, ea, segment_end)

if ea != idc.BADADDR:
ea = ea - 0x2
if ea != idc.BADADDR:
ea = ea - 0x2

if (ea % 0x4) == 0 and ida_bytes.get_full_flags(ea) < 0x200:
ida_funcs.add_func(ea)
if (ea % 0x4) == 0 and ida_bytes.get_full_flags(ea) < 0x200:
ida_funcs.add_func(ea)

ea = ea + 0x4
ea = ea + 0x4

idc.plan_and_wait(base_addr, segment_end)

Expand Down

0 comments on commit dc4a22e

Please sign in to comment.