-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathida.py
52 lines (45 loc) · 1.33 KB
/
ida.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
import idc
import idaapi
import idautils
import ida_segment
# 获取指定地址所在的段
def get_segment(address):
seg = ida_segment.getseg(address)
if seg:
return seg
else:
print("No segment found at address: 0x{:X}".format(address))
return None
def has_execution_permission(segment):
if segment.perm & ida_segment.SEGPERM_EXEC:
return True
else:
return False
skip_func=['__libc_csu_init',
'__libc_csu_fini',
'_fini',
'__do_global_dtors_aux',
'_start',
'_init']
flag=False
for seg in idautils.Segments():
segname = idc.get_segm_name(seg)
segstart = idc.get_segm_start(seg)
segend = idc.get_segm_end(seg)
seg_address=get_segment(seg)
if not flag:
if has_execution_permission(seg_address):
base=segstart
flag=True
else:
if has_execution_permission(seg_address):
for funcaddr in Functions(segstart,segend):
funname = idc.get_func_name(funcaddr)
if funname not in skip_func:
offset=funcaddr-base
print(offset)
#print(hex(offset))
# print(segname)
# print(funname)
# print(hex(base))
#print(offset)