diff options
| author | Peter LaFosse <peter@vector35.com> | 2018-10-23 22:29:15 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2018-10-24 21:31:48 -0400 |
| commit | 3cc05db3e42d402cb03fe3fb8ca582e3ded882f7 (patch) | |
| tree | 816b76258e18809da59f60a847ab6067a5ad5c67 | |
| parent | ec7d4ac5ecfb59ce98ac64f2ed889b73655df746 (diff) | |
Add new APIs for querying data references
| -rw-r--r-- | binaryninjaapi.h | 2 | ||||
| -rw-r--r-- | binaryninjacore.h | 3 | ||||
| -rw-r--r-- | binaryview.cpp | 20 | ||||
| -rw-r--r-- | python/binaryview.py | 14 |
4 files changed, 39 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 958697c7..1fdb74d2 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1357,6 +1357,8 @@ namespace BinaryNinja std::vector<ReferenceSource> GetCodeReferences(uint64_t addr); std::vector<ReferenceSource> GetCodeReferences(uint64_t addr, uint64_t len); + std::vector<uint64_t> GetDataReferences(uint64_t addr); + std::vector<uint64_t> GetDataReferences(uint64_t addr, uint64_t len); Ref<Symbol> GetSymbolByAddress(uint64_t addr, const NameSpace& nameSpace=NameSpace()); Ref<Symbol> GetSymbolByRawName(const std::string& name, const NameSpace& nameSpace=NameSpace()); diff --git a/binaryninjacore.h b/binaryninjacore.h index 161a23af..4e736e38 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2596,6 +2596,9 @@ extern "C" BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesInRange(BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count); BINARYNINJACOREAPI void BNFreeCodeReferences(BNReferenceSource* refs, size_t count); + BINARYNINJACOREAPI uint64_t* BNGetDataReferences(BNBinaryView* view, uint64_t addr, size_t* count); + BINARYNINJACOREAPI uint64_t* BNGetDataReferencesInRange(BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count); + BINARYNINJACOREAPI void BNFreeDataReferences(uint64_t* refs); BINARYNINJACOREAPI void BNRegisterGlobalFunctionRecognizer(BNFunctionRecognizer* rec); diff --git a/binaryview.cpp b/binaryview.cpp index 4447494e..1302b0cb 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1415,6 +1415,26 @@ vector<ReferenceSource> BinaryView::GetCodeReferences(uint64_t addr, uint64_t le } +vector<uint64_t> BinaryView::GetDataReferences(uint64_t addr) +{ + size_t count; + uint64_t* refs = BNGetDataReferences(m_object, addr, &count); + vector<uint64_t> result(refs, &refs[count]); + BNFreeDataReferences(refs); + return result; +} + + +vector<uint64_t> BinaryView::GetDataReferences(uint64_t addr, uint64_t len) +{ + size_t count; + uint64_t* refs = BNGetDataReferencesInRange(m_object, addr, len, &count); + vector<uint64_t> result(refs, &refs[count]); + BNFreeDataReferences(refs); + return result; +} + + Ref<Symbol> BinaryView::GetSymbolByAddress(uint64_t addr, const NameSpace& nameSpace) { BNNameSpace ns = nameSpace.GetAPIObject(); diff --git a/python/binaryview.py b/python/binaryview.py index fe7a9dc9..958318f7 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2476,6 +2476,20 @@ class BinaryView(object): core.BNFreeCodeReferences(refs, count.value) return result + def get_data_refs(self, addr, length=None): + count = ctypes.c_ulonglong(0) + if length is None: + refs = core.BNGetDataReferences(self.handle, addr, count) + else: + refs = core.BNGetDataReferencesInRange(self.handle, addr, length, count) + + result = [] + for i in range(0, count.value): + result.append(refs[i]) + core.BNFreeDataReferences(refs, count.value) + return result + + def get_symbol_at(self, addr, namespace=None): """ ``get_symbol_at`` returns the Symbol at the provided virtual address. |
