def apply_jni_func_sig(): """ Apply the standard JNIEnv* and jobject signature to a function. """ print("Function: {}".format(idc.get_func_name(here()))) func = ida_hexrays.decompile(here()) func_type = func.type funcdata = ida_typeinf.func_type_data_t() func_type.get_func_details(funcdata) jnienv = ida_typeinf.tinfo_t() jnienv.get_named_type(ida_typeinf.get_idati(), "JNIEnv") jnienv_ptr = ida_typeinf.tinfo_t() jnienv_ptr.create_ptr(jnienv) jobject = ida_typeinf.tinfo_t() jobject.get_named_type(ida_typeinf.get_idati(), "jobject") funcdata[0].type = jnienv_ptr funcdata[0].name = "env" funcdata[1].type = jobject funcdata[1].name = "thiz" new_tinfo = ida_typeinf.tinfo_t() new_tinfo.create_func(funcdata) ida_typeinf.apply_tinfo(here(), new_tinfo, ida_typeinf.TINFO_DEFINITE)
def post_struct_member_type_change(member): xrefs = idautils.XrefsFrom(member.id) xrefs = filter(lambda x: x.type == ida_xref.dr_I and x.user == 1, xrefs) for xref in xrefs: if utils.is_func(xref.to): function_ptr_tinfo = idaapi.tinfo_t() ida_struct.get_member_tinfo(function_ptr_tinfo, member) if function_ptr_tinfo.is_funcptr(): function_tinfo = function_ptr_tinfo.get_pointed_object() if function_tinfo is not None: ida_typeinf.apply_tinfo( xref.to, function_tinfo, idaapi.TINFO_DEFINITE )
def update_func_details(func_ea, func_details): function_tinfo = idaapi.tinfo_t() function_tinfo.create_func(func_details) if not ida_typeinf.apply_tinfo(func_ea, function_tinfo, idaapi.TINFO_DEFINITE): return None return function_tinfo
def apply_func_details(func_ea, func_details, flags=idaapi.TINFO_DEFINITE): func_tif = idaapi.tinfo_t() if not func_tif.create_func(func_details): log.warning("%08X Couldn't create func from details", func_ea) return False if not ida_typeinf.apply_tinfo(func_ea, func_tif, flags): log.warning("%08X Couldn't apply new func details", func_ea) return False return True
def replay(self): self.replaying = True try: for ea, typ, fields in self.memo: tif = self._deser(typ, fields) if tif: print("%x: applying type: %s" % (ea, tif._print(None, ida_typeinf.PRTYPE_1LINE))) # Since that type information was remembered from a change # the user made, we'll re-apply it as a definite type (i.e., # can't be overriden by IDA's auto-analysis/heuristics.) apply_flags = ida_typeinf.TINFO_DEFINITE if not ida_typeinf.apply_tinfo(ea, tif, apply_flags): print("FAILED") finally: self.replaying = False
def set_at(self, ea, flags=1): """ Function which try to set the type of the current object at a given position, in particular this will work for global data and function. If an error occur when trying to set the type a :class:`RuntimeError` will be raised. This create a copy of the ``tinfo_t`` in this object. .. todo:: delete flags and make something better here. :param int ea: The address at which set the type. :param int flags: This are the ``TINFO_*`` flags from ida_typeinf, by default ``TINFO_DEFINITE`` . """ if not apply_tinfo(ea, self._get_tinfo_copy(), flags): raise RuntimeError("Unable to set type {} at address {}".format( self.str, ea))