티스토리 뷰

# IDA에서 분석하고 달아놨던 주석을 모두 가져오기 위해 디스어셈블된 상태에서 가져오는 주석인 idc.GetCommentEx 함수를 사용했지만 디컴파일된 수도코드에서 달아놨던 주석은 못가져온다.. 방법은 아래와 같다. 출처 코드에서 약간만 변경했음

출처 : https://github.com/Comsecuris/shannonRE/blob/master/idapython/plugins/pseudocomments.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from idautils import *
from idaapi import *
from idc import *
 
comment_lists = []
arguments_lists = []
 
def export_pseudocomments_from_fun(refs):
        
        for ea in refs:
            f_ea = GetFunctionAttr(ea, FUNCATTR_START)
            
            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
 
                    opnd_value = GetOpnd(t.ea, 0)
                    if opnd_value.find("F_Decrypt_401B71"!= -1:
                        print "%s" % (c.c_str())                            
                        comment_lists.append(c.c_str())
                        #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 comment_lists, arguments_lists
 
finded_function = 0x401B71
refs = CodeRefsTo(finded_function, 1)
a, b = export_pseudocomments_from_fun(refs)
print set(a)
print b
 
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함