idautils.py Do not import all symbols from idaapi to keep the namespace clean

init.py: Import the required symbols from idaapi
This commit is contained in:
gergely.erdelyi 2008-04-12 09:08:11 +00:00
parent a24d2753ec
commit 18b7a6b0ad
2 changed files with 24 additions and 23 deletions

View File

@ -11,7 +11,7 @@
""" """
idautils.py - High level utility functions for IDA idautils.py - High level utility functions for IDA
""" """
from idaapi import * import idaapi
def refs(ea, funcfirst, funcnext): def refs(ea, funcfirst, funcnext):
""" """
@ -21,13 +21,13 @@ def refs(ea, funcfirst, funcnext):
ref = funcfirst(ea) ref = funcfirst(ea)
if ref != BADADDR: if ref != idaapi.BADADDR:
reflist.append(ref) reflist.append(ref)
while 1: while 1:
ref = funcnext(ea, ref) ref = funcnext(ea, ref)
if ref == BADADDR: if ref == idaapi.BADADDR:
break break
else: else:
reflist.append(ref) reflist.append(ref)
@ -51,9 +51,9 @@ def CodeRefsTo(ea, flow):
print ref print ref
""" """
if flow == 1: if flow == 1:
return refs(ea, get_first_cref_to, get_next_cref_to) return refs(ea, idaapi.get_first_cref_to, idaapi.get_next_cref_to)
else: else:
return refs(ea, get_first_fcref_to, get_next_fcref_to) return refs(ea, idaapi.get_first_fcref_to, idaapi.get_next_fcref_to)
def CodeRefsFrom(ea, flow): def CodeRefsFrom(ea, flow):
@ -72,9 +72,9 @@ def CodeRefsFrom(ea, flow):
print ref print ref
""" """
if flow == 1: if flow == 1:
return refs(ea, get_first_cref_from, get_next_cref_from) return refs(ea, idaapi.get_first_cref_from, idaapi.get_next_cref_from)
else: else:
return refs(ea, get_first_fcref_from, get_next_fcref_from) return refs(ea, idaapi.get_first_fcref_from, idaapi.get_next_fcref_from)
def DataRefsTo(ea): def DataRefsTo(ea):
@ -90,7 +90,7 @@ def DataRefsTo(ea):
for ref in DataRefsTo(ScreenEA(), 1): for ref in DataRefsTo(ScreenEA(), 1):
print ref print ref
""" """
return refs(ea, get_first_dref_to, get_next_dref_to) return refs(ea, idaapi.get_first_dref_to, idaapi.get_next_dref_to)
def DataRefsFrom(ea): def DataRefsFrom(ea):
@ -106,7 +106,7 @@ def DataRefsFrom(ea):
for ref in DataRefsFrom(ScreenEA(), 1): for ref in DataRefsFrom(ScreenEA(), 1):
print ref print ref
""" """
return refs(ea, get_first_dref_from, get_next_dref_from) return refs(ea, idaapi.get_first_dref_from, idaapi.get_next_dref_from)
def Heads(start, end): def Heads(start, end):
@ -124,9 +124,9 @@ def Heads(start, end):
ea = start ea = start
while 1: while 1:
ea = next_head(ea, end) ea = idaapi.next_head(ea, end)
if ea == BADADDR: if ea == idaapi.BADADDR:
break break
else: else:
headlist.append(ea) headlist.append(ea)
@ -151,7 +151,7 @@ def Functions(start, end):
funclist = [] funclist = []
func = get_func(start) func = idaapi.get_func(start)
if func: if func:
funclist.append(func.startEA) funclist.append(func.startEA)
@ -159,7 +159,7 @@ def Functions(start, end):
ea = start ea = start
while 1: while 1:
func = get_next_func(ea) func = idaapi.get_next_func(ea)
if not func: break if not func: break
@ -180,8 +180,8 @@ def Segments():
""" """
seglist = [] seglist = []
for n in range(get_segm_qty()): for n in range(idaapi.get_segm_qty()):
seg = getnseg(n) seg = idaapi.getnseg(n)
if not seg: if not seg:
break break
@ -198,11 +198,11 @@ def GetDataList(ea, count, itemsize=1):
getdata = None getdata = None
if itemsize == 1: if itemsize == 1:
getdata = get_byte getdata = idaapi.get_byte
if itemsize == 2: if itemsize == 2:
getdata = get_word getdata = idaapi.get_word
if itemsize == 4: if itemsize == 4:
getdata = get_dword getdata = idaapi.get_dword
if getdata == None: if getdata == None:
raise ValueError, "Invalid data size! Must be 1, 2 or 4" raise ValueError, "Invalid data size! Must be 1, 2 or 4"
@ -223,11 +223,11 @@ def PutDataList(ea, list, itemsize=1):
putdata = None putdata = None
if itemsize == 1: if itemsize == 1:
putdata = patch_byte putdata = idaapi.patch_byte
if itemsize == 2: if itemsize == 2:
putdata = patch_word putdata = idaapi.patch_word
if itemsize == 4: if itemsize == 4:
putdata = patch_dword putdata = idaapi.patch_dword
if putdata == None: if putdata == None:
raise ValueError, "Invalid data size! Must be 1, 2 or 4" raise ValueError, "Invalid data size! Must be 1, 2 or 4"
@ -257,8 +257,8 @@ def GetInputFileMD5():
@return: MD5 string or None on error @return: MD5 string or None on error
""" """
ua=ucharArray(16) ua=idaapi.ucharArray(16)
if retrieve_input_file_md5(ua.cast()): if idaapi.retrieve_input_file_md5(ua.cast()):
md5str="" md5str=""
for i in range(16): for i in range(16):
md5str += "%02x" % ua[i] md5str += "%02x" % ua[i]

View File

@ -94,6 +94,7 @@ print_banner()
#----------------------------------------------------------- #-----------------------------------------------------------
# Import all the required modules # Import all the required modules
#----------------------------------------------------------- #-----------------------------------------------------------
from idaapi import Choose, get_user_idadir, cvar
from idc import * from idc import *
from idautils import * from idautils import *