def import_pseudocomments_to_fun(f_ea, d): if d == {}: #print "skipping %x, empty" % f_ea return print "Attempting to decompile %x" % f_ea try: ct = idaapi.decompile(f_ea) except idaapi.DecompilationFailure: print "error during decompilation (IDA API)" return # i dont know when this happens, but for 404E1404, which is not really a function # this is triggered if not ct or ct.user_cmts == None: print "failed obtaining user cmts at %x" % f_ea return user_cmts = ct.user_cmts it = idaapi.user_cmts_begin(user_cmts) for i in d.iterkeys(): t = idaapi.treeloc_t() t.ea = d[i]["ea"] t.itp = d[i]["itp"] c = idaapi.citem_cmt_t(d[i]["comment"]) idaapi.user_cmts_insert(user_cmts, t, c)
def __call__(self): cmts = idaapi.user_cmts_new() for (tl_ea, tl_itp), cmt in self.cmts: tl = idaapi.treeloc_t() tl.ea = tl_ea tl.itp = tl_itp cmts.insert(tl, idaapi.citem_cmt_t(cmt)) idaapi.save_user_cmts(self.ea, cmts) refresh_pseudocode_view()
def handle_function_comments(delta, segs): for f in get_all_funcs(): for cmt_type in (True, False): cmt = idaapi.get_func_cmt(f, cmt_type) if cmt: new_cmt = rebase_comment(segs, delta, cmt) if new_cmt: idaapi.set_func_cmt(f, cmt, cmt_type) cmts = idaapi.restore_user_cmts(f.start_ea) if not cmts: continue changed = False for (treeloc, citm) in cmts.items(): if citm: citm = citm.c_str() new_cmt = rebase_comment(segs, delta, citm) if new_cmt: changed = True it = cmts.find(treeloc) cmts.erase(it) cmts.insert(treeloc, idaapi.citem_cmt_t(new_cmt)) if changed: idaapi.save_user_cmts(f.start_ea, cmts)