示例#1
0
def export_pseudocomments_from_fun(f_ea):
    d = {}
    d[f_ea] = {}

    #f_ea = 0x040033EC
    print "Attempting to decompile %x" % f_ea
    try:
        ct = idaapi.decompile(f_ea)
    except idaapi.DecompilationFailure:
        print "error during decompilation (IDA API)"
        return d

    user_cmts = ct.user_cmts
    num_cmts = idaapi.user_cmts_size(user_cmts)

    #export_user_variables(ct, f_ea)

    print "Function 0x%08x has %d pseudocomments" % (f_ea, num_cmts)

    it = idaapi.user_cmts_begin(user_cmts)

    #while it != idaapi.user_cmts_end(user_cmts)
    i = 0
    while (i < num_cmts):
        t = idaapi.user_cmts_first(it)  #treeloc_t
        c = idaapi.user_cmts_second(it)  #user_cmts_t

        print "Comment: %s at addr: 0x%08x itp: %d" % (c.c_str(), t.ea, t.itp)

        d[f_ea][i] = {"ea": t.ea, "comment": c.c_str(), "itp": t.itp}

        i += 1
        it = idaapi.user_cmts_next(it)

    return d
示例#2
0
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)
示例#3
0
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)
示例#4
0
def export_pseudocomments_from_fun(f_ea):
	d = {}
	d[f_ea] = {}

	#f_ea = 0x040033EC
	print "Attempting to decompile %x" % f_ea
	try:
		ct = idaapi.decompile(f_ea)
	except idaapi.DecompilationFailure:
		print "error during decompilation (IDA API)"
		return d

	user_cmts = ct.user_cmts
	num_cmts = idaapi.user_cmts_size(user_cmts)

	#export_user_variables(ct, f_ea)

	print "Function 0x%08x has %d pseudocomments" % (f_ea, num_cmts)

	it = idaapi.user_cmts_begin(user_cmts)

	#while it != idaapi.user_cmts_end(user_cmts)
	i = 0
	while (i < num_cmts):
		t = idaapi.user_cmts_first(it)  #treeloc_t
		c = idaapi.user_cmts_second(it) #user_cmts_t

		print "Comment: %s at addr: 0x%08x itp: %d" % (c.c_str(), t.ea, t.itp)

		d[f_ea][i] = {"ea" : t.ea, "comment": c.c_str(), "itp": t.itp}

		i += 1
		it = idaapi.user_cmts_next(it)

	return d
示例#5
0
 def _get_user_cmts(ea):
     user_cmts = idaapi.restore_user_cmts(ea)
     if user_cmts is None:
         user_cmts = idaapi.user_cmts_new()
     cmts = []
     it = idaapi.user_cmts_begin(user_cmts)
     while it != idaapi.user_cmts_end(user_cmts):
         tl = idaapi.user_cmts_first(it)
         cmt = idaapi.user_cmts_second(it)
         cmts.append(((tl.ea, tl.itp), str(cmt)))
         it = idaapi.user_cmts_next(it)
     idaapi.user_cmts_free(user_cmts)
     return cmts