# an example of a file loader in Python # The scripting loader must define at least two functions: accept_file and load_file # other optional functions are: save_file, move_segm, ... # # see also loader.hpp import idaapi import ida_idp import idc import struct ROM_SIGNATURE_OFFSET = 64 ROM_SIGNATURE = "ECEC" RomFormatName = "Windows CE ROM" # ----------------------------------------------------------------------- def dwordAt(li, off): li.seek(off) s = li.read(4) if len(s) < 4: return 0 return struct.unpack(' 1: print("warning: several potential imagebases detemined: " + ", ".join("%08X"%i for i in bases)) start = bases[-1] else: warning("Unable to determine load image base.") start = 0x80000000 print("Using imagebase %08X" % start) physlast = dwordAt(li, romhdr - start + 12) if physlast <= start: warning("Internal error") return 0 size = physlast - start idc.AddSeg(start, start+size, 0, 1, idaapi.saRelPara, idaapi.scPub) # copy bytes to the database li.seek(0) li.file2base(0, start, start+size, 0) idaapi.add_entry(start, start, "start", 1) print("Load OK") return 1 idc.warning("Unknown format name: '%s'" % format) return 0 # ----------------------------------------------------------------------- def move_segm(frm, to, sz, fileformatname): idc.warning("move_segm(from=%s, to=%s, sz=%d, formatname=%s" % (hex(frm), hex(to), sz, fileformatname)) return 0