From 9537f33da6b8de883a45c4b7758f0dc5c1438ed7 Mon Sep 17 00:00:00 2001 From: Zichuan Li Date: Tue, 21 May 2024 17:56:03 -0400 Subject: 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 --- python/binaryview.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'python/binaryview.py') diff --git a/python/binaryview.py b/python/binaryview.py index 0df5a2b1..154b4f8e 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3034,6 +3034,39 @@ class BinaryView: return None 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 + + >>> bv.entry_functions + [, ] + + :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: """ @@ -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 + [, ] + >>> bv.add_to_entry_functions(bv.get_function_at(0x4014da)) + >>> bv.entry_functions + [, , ] + """ + 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 -- cgit v1.3.1