diff options
| author | rollsafe <rollsafe@users.noreply.github.com> | 2019-05-31 18:36:25 -0400 |
|---|---|---|
| committer | rollsafe <rollsafe@users.noreply.github.com> | 2019-06-05 18:00:02 -0400 |
| commit | 522b1b7395fb4cbdba40b49c73b1f7577524fb1a (patch) | |
| tree | 587300fe8fba597fffc22b9b148c63d2c9efc9c7 /python/binaryview.py | |
| parent | fec6e3390631beea8c4ea8c3098191f20565abc2 (diff) | |
Add BinaryView.get_code_refs_from
Diffstat (limited to 'python/binaryview.py')
| -rw-r--r-- | python/binaryview.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 2f7d39be..ac82dbc3 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2797,6 +2797,35 @@ class BinaryView(object): core.BNFreeCodeReferences(refs, count.value) return result + def get_code_refs_from(self, addr, func=None, arch=None, length=None): + """ + ``get_code_refs_from`` returns a list of virtual addresses referenced by code in the function ``func``, + of the architecture ``arch``, and at the address ``addr``. If no function is specified, references from + all functions and containing the address will be returned. If no architecture is specified, the + architecture of the function will be used. + This function returns both autoanalysis ("auto") and user-specified ("user") xrefs. + To add a user-specified reference, see :func:`~binaryninja.function.Function.add_user_code_ref`. + + todo: docs and make it not so difficult to call + """ + + result = [] + funcs = self.get_functions_containing(addr) if func is None else [func] + if not funcs: + return [] + for src_func in funcs: + src_arch = src_func.arch if arch is None else arch + ref_src = core.BNReferenceSource(src_func.handle, src_arch.handle, addr) + count = ctypes.c_ulonglong(0) + if length is None: + refs = core.BNGetCodeReferencesFrom(self.handle, ref_src, count) + else: + refs = core.BNGetCodeReferencesFromInRange(self.handle, ref_src, length, count) + for i in range(0, count.value): + result.append(refs[i]) + core.BNFreeCodeReferencesFrom(refs, count.value) + return result + def get_data_refs(self, addr, length=None): """ ``get_data_refs`` returns a list of virtual addresses of data which references ``addr``. Optionally specifying |
