diff options
| author | Zichuan Li <lizic@iu.edu> | 2024-05-21 17:56:03 -0400 |
|---|---|---|
| committer | Zichuan Li <34680029+river-li@users.noreply.github.com> | 2024-05-28 12:22:23 -0400 |
| commit | 9537f33da6b8de883a45c4b7758f0dc5c1438ed7 (patch) | |
| tree | 08e9844aab5b9e830d9b30303b59fd0f022bea5a /python | |
| parent | 2a6cef7eac64dc3df4a17ba3dc73fb5e1046fc29 (diff) | |
Solved issue #1180 by adding new APIs
1. Add two new APIs for multiple entry functions `GetAllAnalysisEntryFunctions` and `AddToEntryFunctions`
2. Add Python APIs `entry_functions` and `add_to_entry_functions`. `entry_functions` resturns a list of functions, which supports parsing functions in `init_array`, `fini_array` and TLS callbacks.
3. Modify bin-info, it now prints all entry functions
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 0df5a2b1..154b4f8e 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3035,6 +3035,39 @@ class BinaryView: return _function.Function(self, func) @property + def entry_functions(self) -> FunctionList: + """A List of entry functions (read-only) + This list contains vanilla entry function, and functions like init_array, fini_arry, and TLS callbacks etc. + User-added entry functions(via `add_entry_point`) are also included. + + We see `entry_functions` as good starting points for analysis, these functions normally don't have internal references. + However, note that exported functions in a dll/so file are not included. + + Note the difference with `entry_function` + + :Example: + + >>> bv.entry_function + <func: x86@0x4014c8> + >>> bv.entry_functions + [<func: x86@0x4014c8>, <func: x86@0x401618>] + + :return: a list of functions, containing the vanilla entry and other platform-specific entry functions + :rtype: list(Function) + """ + count = ctypes.c_ulonglong(0) + funcs = core.BNGetAllEntryFunctions(self.handle, count) + + assert funcs is not None, "core.BNGetAllEntryFunctions returned None" + result = [] + try: + for i in range(0, count.value): + result.append(_function.Function(self, core.BNNewFunctionReference(funcs[i]))) + return result + finally: + core.BNFreeFunctionList(funcs, count.value) + + @property def symbols(self) -> SymbolMapping: """ Dict of symbols (read-only) @@ -4406,6 +4439,21 @@ class BinaryView: raise ValueError("Provided platform is not of type `Platform`") core.BNAddEntryPointForAnalysis(self.handle, plat.handle, addr) + def add_to_entry_functions(self, func: '_function.Function') -> None: + """ + ``add_to_entry_functions`` adds a function to the `entry_functions` list. + + :param Function func: a Function object + :rtype: None + :Example: + >>> bv.entry_functions + [<func: x86@0x4014c8>, <func: x86@0x401618>] + >>> bv.add_to_entry_functions(bv.get_function_at(0x4014da)) + >>> bv.entry_functions + [<func: x86@0x4014c8>, <func: x86@0x401618>, <func: x86@0x4014da>] + """ + core.BNAddToEntryFunctions(self.handle, func.handle) + def remove_function(self, func: '_function.Function', update_refs = False) -> None: """ ``remove_function`` removes the function ``func`` from the list of functions |
