from idautils import *
from idc import *
const_startEA = [] # const startEA
const_endEA = [] # const endEA
got_startEA = [] # got startEA
got_endEA = [] # got endEA
stubs_startEA = [] # stubs startEA
stubs_endEA = [] # stubs endEA
#set_name(0xFFFFFFF0070015C0,"gggg")
def get_const_seg():
image_base = idaapi.get_imagebase()
end_addr = MaxEA()
start_addr = image_base
while True:
next_seg_addr = NextSeg(start_addr)
if SegName(next_seg_addr).rfind("__const") != -1:
const_startEA.append(next_seg_addr)
const_endEA.append(SegEnd(next_seg_addr))
start_addr = next_seg_addr
if start_addr == 0xFFFFFFFFFFFFFFFF:
break
def get_got_seg():
image_base = idaapi.get_imagebase()
end_addr = MaxEA()
start_addr = image_base
while True:
next_seg_addr = NextSeg(start_addr)
if SegName(next_seg_addr).rfind("__got") != -1:
got_startEA.append(next_seg_addr)
got_endEA.append(SegEnd(next_seg_addr))
start_addr = next_seg_addr
if start_addr == 0xFFFFFFFFFFFFFFFF:
break
def get_stubs_seg():
image_base = idaapi.get_imagebase()
end_addr = MaxEA()
start_addr = image_base
while True:
next_seg_addr = NextSeg(start_addr)
if SegName(next_seg_addr).rfind("__stubs") != -1:
stubs_startEA.append(next_seg_addr)
stubs_endEA.append(SegEnd(next_seg_addr))
start_addr = next_seg_addr
if start_addr == 0xFFFFFFFFFFFFFFFF:
break
def op_work():
func_name = ""
seg_count = 0
print "[+] Working op_offset"
for i in range(0,len(const_startEA)):
for const_addr in range(const_startEA[i], const_endEA[i], 8):
op_plain_offset(const_addr,0,0)
for i in range(0,len(got_startEA)):
for got_addr in range(got_startEA[i], got_endEA[i], 8):
op_plain_offset(got_addr,0,0)
func_name = GetOpnd(got_addr,0)
func_name = func_name + "_" + str(seg_count)
set_name(got_addr, func_name, SN_NOWARN)
# for xref in XrefsTo(got_addr,0):
# set_name(xref.frm, func_name, SN_NOWARN)
seg_count += 1
print hex(xref.frm)
print str(func_name)
# TODO, stubs code section parsing and renamed function, Demangle
get_const_seg()
get_got_seg()
get_stubs_seg()
op_work()