This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API refactoring. find_all_calls_to(_within)
- Loading branch information
Carl OS
committed
Feb 18, 2020
1 parent
486613c
commit 88fe71a
Showing
11 changed files
with
64 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,7 @@ | |
# <[email protected]> | ||
# =========================================================================== | ||
|
||
__version__ = '1.0' | ||
__codename__ = 'nerdilicious' | ||
__version__ = '1.1' | ||
|
||
from idc import * | ||
from idaapi import * | ||
|
@@ -2247,7 +2246,7 @@ def get_all_vars_in_node(cex): | |
return var_indexes | ||
|
||
|
||
def find_all_calls_to(f_name, ea): | ||
def find_all_calls_to_within(f_name, ea): | ||
"""Finds all calls to a function with the given name \ | ||
within the function containing the ``ea`` address. | ||
|
@@ -2266,7 +2265,7 @@ def find_all_calls_to(f_name, ea): | |
try: | ||
c = controlFlowinator(ea=ea, fast=False) | ||
except Exception as e: | ||
print("Failed to find_all_calls_to {}".format(f_name)) | ||
print("Failed to find_all_calls_to_within {}".format(f_name)) | ||
print(e) | ||
return [] | ||
|
||
|
@@ -2285,6 +2284,43 @@ def find_all_calls_to(f_name, ea): | |
return call_objs | ||
|
||
|
||
def find_all_calls_to(f_name): | ||
"""Finds all calls to a function with the given name | ||
Note that the string comparison is relaxed to find variants of it, that is, | ||
searching for ``malloc`` will match as well ``_malloc``, ``malloc_0``, etc. | ||
:param f_name: the function name to search for | ||
:type f_name: string | ||
:return: a list of :class:`callObj` | ||
:rtype: list | ||
""" | ||
|
||
f_ea = get_name_ea_simple(f_name) | ||
if f_ea == BADADDR: | ||
print("Failed to resolve address for {}".format(f_name)) | ||
return [] | ||
|
||
callz = [] | ||
callers = set() | ||
|
||
for ref in XrefsTo(f_ea, True): | ||
if not ref.iscode: | ||
continue | ||
|
||
# Get a set of unique *function* callers | ||
f = get_func(ref.frm) | ||
f_ea = f.start_ea | ||
callers.add(f_ea) | ||
|
||
for caller_ea in callers: | ||
c = find_all_calls_to_within(f_name, caller_ea) | ||
print("{:X}".format(caller_ea), len(c)) | ||
callz += c | ||
|
||
return callz | ||
|
||
|
||
def find_elements_of_type(cex, element_type, elements=None): | ||
"""Recursively extracts expression elements until \ | ||
a :class:`cexpr_t` from a specific group is found | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.