mirror of
https://github.com/cemu-project/idapython.git
synced 2024-12-01 05:24:18 +01:00
idautils.py: Many functions converted to generators
This commit is contained in:
parent
864165a44c
commit
769e9d70f4
@ -18,23 +18,11 @@ def refs(ea, funcfirst, funcnext):
|
|||||||
"""
|
"""
|
||||||
Generic reference collector - INTERNAL USE ONLY.
|
Generic reference collector - INTERNAL USE ONLY.
|
||||||
"""
|
"""
|
||||||
reflist = []
|
|
||||||
|
|
||||||
ref = funcfirst(ea)
|
ref = funcfirst(ea)
|
||||||
|
while ref != idaapi.BADADDR:
|
||||||
if ref != idaapi.BADADDR:
|
yield ref
|
||||||
reflist.append(ref)
|
|
||||||
|
|
||||||
while 1:
|
|
||||||
ref = funcnext(ea, ref)
|
ref = funcnext(ea, ref)
|
||||||
|
|
||||||
if ref == idaapi.BADADDR:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
reflist.append(ref)
|
|
||||||
|
|
||||||
return reflist
|
|
||||||
|
|
||||||
|
|
||||||
def CodeRefsTo(ea, flow):
|
def CodeRefsTo(ea, flow):
|
||||||
"""
|
"""
|
||||||
@ -192,21 +180,11 @@ def Heads(start, end):
|
|||||||
|
|
||||||
@return: list of heads between start and end
|
@return: list of heads between start and end
|
||||||
"""
|
"""
|
||||||
headlist = []
|
|
||||||
headlist.append(start)
|
|
||||||
|
|
||||||
ea = start
|
ea = start
|
||||||
|
while ea != idaapi.BADADDR:
|
||||||
while 1:
|
yield ea
|
||||||
ea = idaapi.next_head(ea, end)
|
ea = idaapi.next_head(ea, end)
|
||||||
|
|
||||||
if ea == idaapi.BADADDR:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
headlist.append(ea)
|
|
||||||
|
|
||||||
return headlist
|
|
||||||
|
|
||||||
|
|
||||||
def Functions(start, end):
|
def Functions(start, end):
|
||||||
"""
|
"""
|
||||||
@ -220,26 +198,10 @@ def Functions(start, end):
|
|||||||
@note: The last function that starts before 'end' is included even
|
@note: The last function that starts before 'end' is included even
|
||||||
if it extends beyond 'end'.
|
if it extends beyond 'end'.
|
||||||
"""
|
"""
|
||||||
funclist = []
|
|
||||||
func = idaapi.get_func(start)
|
func = idaapi.get_func(start)
|
||||||
|
while func and func.startEA < end:
|
||||||
if func:
|
yield func.startEA
|
||||||
funclist.append(func.startEA)
|
func = idaapi.get_next_func(func.startEA)
|
||||||
|
|
||||||
ea = start
|
|
||||||
|
|
||||||
while 1:
|
|
||||||
func = idaapi.get_next_func(ea)
|
|
||||||
|
|
||||||
if not func: break
|
|
||||||
|
|
||||||
if func.startEA < end:
|
|
||||||
funclist.append(func.startEA)
|
|
||||||
ea = func.startEA
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
return funclist
|
|
||||||
|
|
||||||
|
|
||||||
def Chunks(start):
|
def Chunks(start):
|
||||||
@ -251,18 +213,13 @@ def Chunks(start):
|
|||||||
@return: list of funcion chunks (tuples of the form (start_ea, end_ea))
|
@return: list of funcion chunks (tuples of the form (start_ea, end_ea))
|
||||||
belonging to the function
|
belonging to the function
|
||||||
"""
|
"""
|
||||||
function_chunks = []
|
|
||||||
|
|
||||||
func_iter = idaapi.func_tail_iterator_t( idaapi.get_func( start ) )
|
func_iter = idaapi.func_tail_iterator_t( idaapi.get_func( start ) )
|
||||||
status = func_iter.main()
|
status = func_iter.main()
|
||||||
|
|
||||||
while status:
|
while status:
|
||||||
chunk = func_iter.chunk()
|
chunk = func_iter.chunk()
|
||||||
function_chunks.append((chunk.startEA, chunk.endEA))
|
yield (chunk.startEA, chunk.endEA)
|
||||||
status = func_iter.next()
|
status = func_iter.next()
|
||||||
|
|
||||||
return function_chunks
|
|
||||||
|
|
||||||
|
|
||||||
def Segments():
|
def Segments():
|
||||||
"""
|
"""
|
||||||
@ -270,17 +227,10 @@ def Segments():
|
|||||||
|
|
||||||
@return: List of segment start addresses.
|
@return: List of segment start addresses.
|
||||||
"""
|
"""
|
||||||
seglist = []
|
|
||||||
|
|
||||||
for n in range(idaapi.get_segm_qty()):
|
for n in range(idaapi.get_segm_qty()):
|
||||||
seg = idaapi.getnseg(n)
|
seg = idaapi.getnseg(n)
|
||||||
|
if seg:
|
||||||
if not seg:
|
yield seg.startEA
|
||||||
break
|
|
||||||
else:
|
|
||||||
seglist.append(seg.startEA)
|
|
||||||
|
|
||||||
return seglist
|
|
||||||
|
|
||||||
|
|
||||||
def GetDataList(ea, count, itemsize=1):
|
def GetDataList(ea, count, itemsize=1):
|
||||||
|
Loading…
Reference in New Issue
Block a user