diff options
| -rw-r--r-- | binaryninjaapi.h | 98 | ||||
| -rw-r--r-- | binaryninjacore.h | 30 | ||||
| -rw-r--r-- | binaryview.cpp | 124 | ||||
| -rw-r--r-- | python/binaryview.py | 68 | ||||
| -rw-r--r-- | rust/src/binary_view.rs | 12 |
5 files changed, 249 insertions, 83 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 8d3fed9c..595c827e 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5520,9 +5520,27 @@ namespace BinaryNinja { */ std::vector<ReferenceSource> GetCodeReferences(uint64_t addr, uint64_t len); + /*! Get a list of references made from code (instructions) to a virtual address + + \param addr Address to check + \param maxItems Optional maximum number of items to fetch + \return vector of ReferenceSources referencing the virtual address + */ + std::vector<ReferenceSource> GetCodeReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems = std::nullopt); + + /*! Get a list of references from code (instructions) to a range of addresses + + \param addr Address to check + \param len Length of query + \param maxItems Optional maximum number of items to fetch + \return vector of ReferenceSources referencing the virtual address range + */ + std::vector<ReferenceSource> GetCodeReferencesInRangeWithLimit( + uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt); + /*! Get code references made by a particular "ReferenceSource" - A ReferenceSource contains a given function, architecture of that function, and an address within it. + A ReferenceSource contains a given function, architecture of that function, and an address within it. \param src reference source \return List of virtual addresses referenced by this source @@ -5556,6 +5574,24 @@ namespace BinaryNinja { */ std::vector<uint64_t> GetDataReferences(uint64_t addr, uint64_t len); + /*! Get references made by data ('DataVariables') to a virtual address + + \param addr Address to check + \param maxItems Optional maximum number of items to fetch + \return vector of virtual addresses referencing the virtual address + */ + std::vector<uint64_t> GetDataReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems = std::nullopt); + + /*! Get references made by data ('DataVariables') in a given range, to a virtual address + + \param addr Address to check + \param len Length of query + \param maxItems Optional maximum number of items to fetch + \return vector of virtual addresses referencing the virtual address range + */ + std::vector<uint64_t> GetDataReferencesInRangeWithLimit( + uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt); + /*! Get references made by data ('DataVariables') located at a virtual address. \param src reference source @@ -5605,43 +5641,53 @@ namespace BinaryNinja { /*! Get code references to a Type \param type QualifiedName for a Type + \param maxItems Optional maximum number of items to fetch \return vector of ReferenceSources */ - std::vector<ReferenceSource> GetCodeReferencesForType(const QualifiedName& type); + std::vector<ReferenceSource> GetCodeReferencesForType( + const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt); /*! Get data references to a Type \param type QualifiedName for a Type + \param maxItems Optional maximum number of items to fetch \return vector of virtual addresses referencing this Type */ - std::vector<uint64_t> GetDataReferencesForType(const QualifiedName& type); + std::vector<uint64_t> GetDataReferencesForType( + const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt); /*! Get Type references to a Type \param type QualifiedName for a Type + \param maxItems Optional maximum number of items to fetch \return vector of TypeReferenceSources to this Type */ - std::vector<TypeReferenceSource> GetTypeReferencesForType(const QualifiedName& type); + std::vector<TypeReferenceSource> GetTypeReferencesForType( + const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt); /*! Returns a list of references to a specific type field - \param type QualifiedName of the type - \param offset Offset of the field, relative to the start of the type - \return vector of TypeFieldReferences + \param type QualifiedName of the type + \param offset Offset of the field, relative to the start of the type + \param maxItems Optional maximum number of items to fetch + \return vector of TypeFieldReferences */ - std::vector<TypeFieldReference> GetCodeReferencesForTypeField(const QualifiedName& type, uint64_t offset); + std::vector<TypeFieldReference> GetCodeReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt); /*! Returns a list of virtual addresses of data which references the type \c type . - Note, the returned addresses are the actual start of the queried type field. For example, suppose there is a - DataVariable at \c 0x1000 that has type \c A , and type \c A contains type \c B at offset \c 0x10 . - Then <tt>GetDataReferencesForTypeField(bQualifiedName, 0x8)</tt> will return \c 0x1018 for it. + Note, the returned addresses are the actual start of the queried type field. For example, suppose there is a + DataVariable at \c 0x1000 that has type \c A , and type \c A contains type \c B at offset \c 0x10 . + Then <tt>GetDataReferencesForTypeField(bQualifiedName, 0x8)</tt> will return \c 0x1018 for it. - \param type QualifiedName of the type - \param offset Offset of the field, relative to the start of the type - \return List of DataVariable start addresses containing references to the type field + \param type QualifiedName of the type + \param offset Offset of the field, relative to the start of the type + \param maxItems Optional maximum number of items to fetch + \return List of DataVariable start addresses containing references to the type field */ - std::vector<uint64_t> GetDataReferencesForTypeField(const QualifiedName& type, uint64_t offset); + std::vector<uint64_t> GetDataReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt); /*! Returns a list of virtual addresses of data which are referenced from the type \c type . @@ -5649,32 +5695,40 @@ namespace BinaryNinja { \param type QualifiedName of the type \param offset Offset of the field, relative to the start of the type + \param maxItems Optional maximum number of items to fetch \return List of addresses referenced from the type field */ - std::vector<uint64_t> GetDataReferencesFromForTypeField(const QualifiedName& type, uint64_t offset); + std::vector<uint64_t> GetDataReferencesFromForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt); /*! Returns a list of type references to a specific type field - \param type QualifiedName of the type - \param offset Offset of the field, relative to the start of the type - \return vector of TypeReferenceSources + \param type QualifiedName of the type + \param offset Offset of the field, relative to the start of the type + \param maxItems Optional maximum number of items to fetch + \return vector of TypeReferenceSources */ - std::vector<TypeReferenceSource> GetTypeReferencesForTypeField(const QualifiedName& type, uint64_t offset); + std::vector<TypeReferenceSource> GetTypeReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt); /*! Returns a all references to a specific type. This includes code, data, and type references. \param type QualifiedName of the type + \param maxItems Optional maximum number of items to fetch \return AllTypeReferences structure with all references */ - AllTypeReferences GetAllReferencesForType(const QualifiedName& type); + AllTypeReferences GetAllReferencesForType( + const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt); /*! Returns a all references to a specific type field. This includes code, data, and type references. \param type QualifiedName of the type \param offset Offset of the field, relative to the start of the type + \param maxItems Optional maximum number of items to fetch \return AllTypeFieldReferences structure with all references */ - AllTypeFieldReferences GetAllReferencesForTypeField(const QualifiedName& type, uint64_t offset); + AllTypeFieldReferences GetAllReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt); /*! Returns a list of types referenced by code at ReferenceSource \c src diff --git a/binaryninjacore.h b/binaryninjacore.h index fbdcf4f5..dd1c8c56 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5020,9 +5020,10 @@ extern "C" BINARYNINJACOREAPI void BNMarkFunctionAsRecentlyUsed(BNFunction* func); BINARYNINJACOREAPI void BNMarkBasicBlockAsRecentlyUsed(BNBasicBlock* block); - BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences(BNBinaryView* view, uint64_t addr, size_t* count); + BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences( + BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesInRange( - BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count); + BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI void BNFreeCodeReferences(BNReferenceSource* refs, size_t count); BINARYNINJACOREAPI void BNFreeTypeFieldReferences(BNTypeFieldReference* refs, size_t count); BINARYNINJACOREAPI void BNFreeILReferences(BNILReferenceSource* refs, size_t count); @@ -5030,9 +5031,10 @@ extern "C" BINARYNINJACOREAPI uint64_t* BNGetCodeReferencesFromInRange( BNBinaryView* view, BNReferenceSource* src, uint64_t len, size_t* count); - BINARYNINJACOREAPI uint64_t* BNGetDataReferences(BNBinaryView* view, uint64_t addr, size_t* count); + BINARYNINJACOREAPI uint64_t* BNGetDataReferences( + BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI uint64_t* BNGetDataReferencesInRange( - BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count); + BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFrom(BNBinaryView* view, uint64_t addr, size_t* count); BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromInRange( BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count); @@ -5050,25 +5052,27 @@ extern "C" // References to type BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesForType( - BNBinaryView* view, BNQualifiedName* type, size_t* count); - BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType(BNBinaryView* view, BNQualifiedName* type, size_t* count); + BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems); + BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType( + BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForType( - BNBinaryView* view, BNQualifiedName* type, size_t* count); + BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems); // References to type field BINARYNINJACOREAPI BNTypeFieldReference* BNGetCodeReferencesForTypeField( - BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count); + BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForTypeField( - BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count); + BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromForTypeField( - BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count); + BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems); BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForTypeField( - BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count); + BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems); - BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(BNBinaryView* view, BNQualifiedName* type); + BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType( + BNBinaryView* view, BNQualifiedName* type, bool limit, size_t maxItems); BINARYNINJACOREAPI void BNFreeAllTypeReferences(BNAllTypeReferences* refs); BINARYNINJACOREAPI BNAllTypeFieldReferences BNGetAllReferencesForTypeField( - BNBinaryView* view, BNQualifiedName* type, uint64_t offset); + BNBinaryView* view, BNQualifiedName* type, uint64_t offset, bool limit, size_t maxItems); BINARYNINJACOREAPI void BNFreeAllTypeFieldReferences(BNAllTypeFieldReferences* refs); BINARYNINJACOREAPI BNTypeReferenceSource* BNGetCodeReferencesForTypeFrom( diff --git a/binaryview.cpp b/binaryview.cpp index 665228c1..21266886 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -2423,7 +2423,7 @@ vector<Ref<BasicBlock>> BinaryView::GetBasicBlocksStartingAtAddress(uint64_t add vector<ReferenceSource> BinaryView::GetCodeReferences(uint64_t addr) { size_t count; - BNReferenceSource* refs = BNGetCodeReferences(m_object, addr, &count); + BNReferenceSource* refs = BNGetCodeReferences(m_object, addr, &count, false, 0); vector<ReferenceSource> result; result.reserve(count); @@ -2444,7 +2444,51 @@ vector<ReferenceSource> BinaryView::GetCodeReferences(uint64_t addr) vector<ReferenceSource> BinaryView::GetCodeReferences(uint64_t addr, uint64_t len) { size_t count; - BNReferenceSource* refs = BNGetCodeReferencesInRange(m_object, addr, len, &count); + BNReferenceSource* refs = BNGetCodeReferencesInRange(m_object, addr, len, &count, false, 0); + + vector<ReferenceSource> result; + result.reserve(count); + for (size_t i = 0; i < count; i++) + { + ReferenceSource src; + src.func = new Function(BNNewFunctionReference(refs[i].func)); + src.arch = new CoreArchitecture(refs[i].arch); + src.addr = refs[i].addr; + result.push_back(src); + } + + BNFreeCodeReferences(refs, count); + return result; +} + + +vector<ReferenceSource> BinaryView::GetCodeReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems) +{ + size_t count; + BNReferenceSource* refs = BNGetCodeReferences(m_object, addr, &count, maxItems.has_value(), maxItems.value_or(0)); + + vector<ReferenceSource> result; + result.reserve(count); + for (size_t i = 0; i < count; i++) + { + ReferenceSource src; + src.func = new Function(BNNewFunctionReference(refs[i].func)); + src.arch = new CoreArchitecture(refs[i].arch); + src.addr = refs[i].addr; + result.push_back(src); + } + + BNFreeCodeReferences(refs, count); + return result; +} + + +vector<ReferenceSource> BinaryView::GetCodeReferencesInRangeWithLimit( + uint64_t addr, uint64_t len, std::optional<size_t> maxItems) +{ + size_t count; + BNReferenceSource* refs = + BNGetCodeReferencesInRange(m_object, addr, len, &count, maxItems.has_value(), maxItems.value_or(0)); vector<ReferenceSource> result; result.reserve(count); @@ -2487,7 +2531,7 @@ vector<uint64_t> BinaryView::GetCodeReferencesFrom(ReferenceSource src, uint64_t vector<uint64_t> BinaryView::GetDataReferences(uint64_t addr) { size_t count; - uint64_t* refs = BNGetDataReferences(m_object, addr, &count); + uint64_t* refs = BNGetDataReferences(m_object, addr, &count, false, 0); vector<uint64_t> result(refs, &refs[count]); BNFreeDataReferences(refs); return result; @@ -2497,7 +2541,29 @@ vector<uint64_t> BinaryView::GetDataReferences(uint64_t addr) vector<uint64_t> BinaryView::GetDataReferences(uint64_t addr, uint64_t len) { size_t count; - uint64_t* refs = BNGetDataReferencesInRange(m_object, addr, len, &count); + uint64_t* refs = BNGetDataReferencesInRange(m_object, addr, len, &count, false, 0); + vector<uint64_t> result(refs, &refs[count]); + BNFreeDataReferences(refs); + return result; +} + + +vector<uint64_t> BinaryView::GetDataReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems) +{ + size_t count; + uint64_t* refs = BNGetDataReferences(m_object, addr, &count, maxItems.has_value(), maxItems.value_or(0)); + vector<uint64_t> result(refs, &refs[count]); + BNFreeDataReferences(refs); + return result; +} + + +vector<uint64_t> BinaryView::GetDataReferencesInRangeWithLimit( + uint64_t addr, uint64_t len, std::optional<size_t> maxItems) +{ + size_t count; + uint64_t* refs = + BNGetDataReferencesInRange(m_object, addr, len, &count, maxItems.has_value(), maxItems.value_or(0)); vector<uint64_t> result(refs, &refs[count]); BNFreeDataReferences(refs); return result; @@ -2548,12 +2614,13 @@ void BinaryView::RemoveUserDataReference(uint64_t fromAddr, uint64_t toAddr) } -vector<ReferenceSource> BinaryView::GetCodeReferencesForType(const QualifiedName& type) +vector<ReferenceSource> BinaryView::GetCodeReferencesForType(const QualifiedName& type, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - BNReferenceSource* refs = BNGetCodeReferencesForType(m_object, &nameObj, &count); + BNReferenceSource* refs = + BNGetCodeReferencesForType(m_object, &nameObj, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<ReferenceSource> result; @@ -2572,11 +2639,11 @@ vector<ReferenceSource> BinaryView::GetCodeReferencesForType(const QualifiedName } -vector<uint64_t> BinaryView::GetDataReferencesForType(const QualifiedName& type) +vector<uint64_t> BinaryView::GetDataReferencesForType(const QualifiedName& type, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - uint64_t* refs = BNGetDataReferencesForType(m_object, &nameObj, &count); + uint64_t* refs = BNGetDataReferencesForType(m_object, &nameObj, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<uint64_t> result(refs, &refs[count]); @@ -2585,12 +2652,14 @@ vector<uint64_t> BinaryView::GetDataReferencesForType(const QualifiedName& type) } -vector<TypeReferenceSource> BinaryView::GetTypeReferencesForType(const QualifiedName& type) +vector<TypeReferenceSource> BinaryView::GetTypeReferencesForType( + const QualifiedName& type, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - BNTypeReferenceSource* refs = BNGetTypeReferencesForType(m_object, &nameObj, &count); + BNTypeReferenceSource* refs = + BNGetTypeReferencesForType(m_object, &nameObj, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<TypeReferenceSource> result; @@ -2609,11 +2678,13 @@ vector<TypeReferenceSource> BinaryView::GetTypeReferencesForType(const Qualified } -vector<TypeFieldReference> BinaryView::GetCodeReferencesForTypeField(const QualifiedName& type, uint64_t offset) +vector<TypeFieldReference> BinaryView::GetCodeReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - BNTypeFieldReference* refs = BNGetCodeReferencesForTypeField(m_object, &nameObj, offset, &count); + BNTypeFieldReference* refs = + BNGetCodeReferencesForTypeField(m_object, &nameObj, offset, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<TypeFieldReference> result; @@ -2636,11 +2707,13 @@ vector<TypeFieldReference> BinaryView::GetCodeReferencesForTypeField(const Quali } -vector<uint64_t> BinaryView::GetDataReferencesForTypeField(const QualifiedName& type, uint64_t offset) +vector<uint64_t> BinaryView::GetDataReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - uint64_t* refs = BNGetDataReferencesForTypeField(m_object, &nameObj, offset, &count); + uint64_t* refs = + BNGetDataReferencesForTypeField(m_object, &nameObj, offset, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<uint64_t> result(refs, &refs[count]); @@ -2649,11 +2722,13 @@ vector<uint64_t> BinaryView::GetDataReferencesForTypeField(const QualifiedName& } -vector<uint64_t> BinaryView::GetDataReferencesFromForTypeField(const QualifiedName& type, uint64_t offset) +vector<uint64_t> BinaryView::GetDataReferencesFromForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - uint64_t* refs = BNGetDataReferencesFromForTypeField(m_object, &nameObj, offset, &count); + uint64_t* refs = BNGetDataReferencesFromForTypeField( + m_object, &nameObj, offset, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<uint64_t> result(refs, &refs[count]); @@ -2662,11 +2737,13 @@ vector<uint64_t> BinaryView::GetDataReferencesFromForTypeField(const QualifiedNa } -vector<TypeReferenceSource> BinaryView::GetTypeReferencesForTypeField(const QualifiedName& type, uint64_t offset) +vector<TypeReferenceSource> BinaryView::GetTypeReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems) { size_t count; BNQualifiedName nameObj = type.GetAPIObject(); - BNTypeReferenceSource* refs = BNGetTypeReferencesForTypeField(m_object, &nameObj, offset, &count); + BNTypeReferenceSource* refs = + BNGetTypeReferencesForTypeField(m_object, &nameObj, offset, &count, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); vector<TypeReferenceSource> result; @@ -2685,10 +2762,11 @@ vector<TypeReferenceSource> BinaryView::GetTypeReferencesForTypeField(const Qual } -AllTypeReferences BinaryView::GetAllReferencesForType(const QualifiedName& type) +AllTypeReferences BinaryView::GetAllReferencesForType(const QualifiedName& type, std::optional<size_t> maxItems) { BNQualifiedName nameObj = type.GetAPIObject(); - BNAllTypeReferences refs = BNGetAllReferencesForType(m_object, &nameObj); + BNAllTypeReferences refs = + BNGetAllReferencesForType(m_object, &nameObj, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); AllTypeReferences result; @@ -2720,10 +2798,12 @@ AllTypeReferences BinaryView::GetAllReferencesForType(const QualifiedName& type) } -AllTypeFieldReferences BinaryView::GetAllReferencesForTypeField(const QualifiedName& type, uint64_t offset) +AllTypeFieldReferences BinaryView::GetAllReferencesForTypeField( + const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems) { BNQualifiedName nameObj = type.GetAPIObject(); - BNAllTypeFieldReferences refs = BNGetAllReferencesForTypeField(m_object, &nameObj, offset); + BNAllTypeFieldReferences refs = + BNGetAllReferencesForTypeField(m_object, &nameObj, offset, maxItems.has_value(), maxItems.value_or(0)); QualifiedName::FreeAPIObject(&nameObj); AllTypeFieldReferences result; diff --git a/python/binaryview.py b/python/binaryview.py index 918fff0e..bb220b3a 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -5333,7 +5333,7 @@ class BinaryView: return None return basicblock.BasicBlock(block, self) - def get_code_refs(self, addr: int, length: Optional[int] = None) -> Generator['ReferenceSource', None, None]: + def get_code_refs(self, addr: int, length: Optional[int] = None, max_items: Optional[int] = None) -> Generator['ReferenceSource', None, None]: """ ``get_code_refs`` returns a generator of :py:class:`~binaryninja.binaryview.ReferenceSource` objects (xrefs or cross-references) that point to the provided virtual address. This function returns both autoanalysis ("auto") and user-specified ("user") xrefs. @@ -5347,6 +5347,7 @@ class BinaryView: :param int addr: virtual address to query for references :param int length: optional length of query + :param int max_items: optional maximum number of references to fetch :return: A generator of References for the given virtual address :rtype: Generator[ReferenceSource, None, None] :Example: @@ -5357,11 +5358,13 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 if length is None: - refs = core.BNGetCodeReferences(self.handle, addr, count) + refs = core.BNGetCodeReferences(self.handle, addr, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetCodeReferences returned None" else: - refs = core.BNGetCodeReferencesInRange(self.handle, addr, length, count) + refs = core.BNGetCodeReferencesInRange(self.handle, addr, length, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetCodeReferencesInRange returned None" try: @@ -5409,7 +5412,7 @@ class BinaryView: core.BNFreeAddressList(refs) return result - def get_data_refs(self, addr: int, length: Optional[int] = None) -> Generator[int, None, None]: + def get_data_refs(self, addr: int, length: Optional[int] = None, max_items: Optional[int] = None) -> Generator[int, None, None]: """ ``get_data_refs`` returns a list of virtual addresses of _data_ (not code) which references ``addr``, optionally specifying a length. When ``length`` is set ``get_data_refs`` returns the data which references in the range ``addr``-``addr``+``length``. @@ -5432,11 +5435,13 @@ class BinaryView: >>> """ count = ctypes.c_ulonglong(0) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 if length is None: - refs = core.BNGetDataReferences(self.handle, addr, count) + refs = core.BNGetDataReferences(self.handle, addr, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetDataReferences returned None" else: - refs = core.BNGetDataReferencesInRange(self.handle, addr, length, count) + refs = core.BNGetDataReferencesInRange(self.handle, addr, length, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetDataReferencesInRange returned None" try: @@ -5477,11 +5482,12 @@ class BinaryView: finally: core.BNFreeDataReferences(refs) - def get_code_refs_for_type(self, name: str) -> Generator[ReferenceSource, None, None]: + def get_code_refs_for_type(self, name: str, max_items: Optional[int] = None) -> Generator[ReferenceSource, None, None]: """ ``get_code_refs_for_type`` returns a Generator[ReferenceSource] objects (xrefs or cross-references) that reference the provided QualifiedName. :param QualifiedName name: name of type to query for references + :param int max_items: optional maximum number of references to fetch :return: List of References for the given type :rtype: list(ReferenceSource) :Example: @@ -5493,7 +5499,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetCodeReferencesForType(self.handle, _name, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetCodeReferencesForType(self.handle, _name, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetCodeReferencesForType returned None" try: @@ -5502,13 +5510,13 @@ class BinaryView: finally: core.BNFreeCodeReferences(refs, count.value) - def get_code_refs_for_type_field(self, name: str, - offset: int) -> Generator['_types.TypeFieldReference', None, None]: + def get_code_refs_for_type_field(self, name: str, offset: int, max_items: Optional[int] = None) -> Generator['_types.TypeFieldReference', None, None]: """ ``get_code_refs_for_type`` returns a Generator[TypeFieldReference] objects (xrefs or cross-references) that reference the provided type field. :param QualifiedName name: name of type to query for references :param int offset: offset of the field, relative to the type + :param int max_items: optional maximum number of references to fetch :return: Generator of References for the given type :rtype: Generator[TypeFieldReference] :Example: @@ -5520,7 +5528,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetCodeReferencesForTypeField(self.handle, _name, offset, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetCodeReferencesForTypeField(self.handle, _name, offset, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetCodeReferencesForTypeField returned None" try: @@ -5544,7 +5554,7 @@ class BinaryView: finally: core.BNFreeTypeFieldReferences(refs, count.value) - def get_data_refs_for_type(self, name: str) -> Generator[int, None, None]: + def get_data_refs_for_type(self, name: str, max_items: Optional[int] = None) -> Generator[int, None, None]: """ ``get_data_refs_for_type`` returns a list of virtual addresses of data which references the type ``name``. Note, the returned addresses are the actual start of the queried type. For example, suppose there is a DataVariable @@ -5552,6 +5562,7 @@ class BinaryView: return 0x1010 for it. :param QualifiedName name: name of type to query for references + :param int max_items: optional maximum number of references to fetch :return: list of integers :rtype: list(integer) :Example: @@ -5562,7 +5573,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetDataReferencesForType(self.handle, _name, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetDataReferencesForType(self.handle, _name, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetDataReferencesForType returned None" try: @@ -5571,7 +5584,7 @@ class BinaryView: finally: core.BNFreeDataReferences(refs) - def get_data_refs_for_type_field(self, name: '_types.QualifiedNameType', offset: int) -> List[int]: + def get_data_refs_for_type_field(self, name: '_types.QualifiedNameType', offset: int, max_items: Optional[int] = None) -> List[int]: """ ``get_data_refs_for_type_field`` returns a list of virtual addresses of data which references the type ``name``. Note, the returned addresses are the actual start of the queried type field. For example, suppose there is a @@ -5580,6 +5593,7 @@ class BinaryView: :param QualifiedName name: name of type to query for references :param int offset: offset of the field, relative to the type + :param int max_items: optional maximum number of references to fetch :return: list of integers :rtype: list(integer) :Example: @@ -5590,7 +5604,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetDataReferencesForTypeField(self.handle, _name, offset, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetDataReferencesForTypeField(self.handle, _name, offset, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetDataReferencesForTypeField returned None" result = [] @@ -5601,7 +5617,7 @@ class BinaryView: finally: core.BNFreeDataReferences(refs) - def get_data_refs_from_for_type_field(self, name: '_types.QualifiedNameType', offset: int) -> List[int]: + def get_data_refs_from_for_type_field(self, name: '_types.QualifiedNameType', offset: int, max_items: Optional[int] = None) -> List[int]: """ ``get_data_refs_from_for_type_field`` returns a list of virtual addresses of data which are referenced by the type ``name``. @@ -5609,6 +5625,7 @@ class BinaryView: :param QualifiedName name: name of type to query for references :param int offset: offset of the field, relative to the type + :param int max_items: optional maximum number of references to fetch :return: list of integers :rtype: list(integer) :Example: @@ -5619,7 +5636,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetDataReferencesFromForTypeField(self.handle, _name, offset, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetDataReferencesFromForTypeField(self.handle, _name, offset, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetDataReferencesFromForTypeField returned None" result = [] @@ -5630,11 +5649,12 @@ class BinaryView: finally: core.BNFreeDataReferences(refs) - def get_type_refs_for_type(self, name: '_types.QualifiedNameType') -> List['_types.TypeReferenceSource']: + def get_type_refs_for_type(self, name: '_types.QualifiedNameType', max_items: Optional[int] = None) -> List['_types.TypeReferenceSource']: """ ``get_type_refs_for_type`` returns a list of TypeReferenceSource objects (xrefs or cross-references) that reference the provided QualifiedName. :param QualifiedName name: name of type to query for references + :param int max_items: optional maximum number of references to fetch :return: List of references for the given type :rtype: list(TypeReferenceSource) :Example: @@ -5646,7 +5666,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetTypeReferencesForType(self.handle, _name, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetTypeReferencesForType(self.handle, _name, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetTypeReferencesForType returned None" result = [] @@ -5660,13 +5682,13 @@ class BinaryView: finally: core.BNFreeTypeReferences(refs, count.value) - def get_type_refs_for_type_field(self, name: '_types.QualifiedNameType', - offset: int) -> List['_types.TypeReferenceSource']: + def get_type_refs_for_type_field(self, name: '_types.QualifiedNameType', offset: int, max_items: Optional[int] = None) -> List['_types.TypeReferenceSource']: """ ``get_type_refs_for_type`` returns a list of TypeReferenceSource objects (xrefs or cross-references) that reference the provided type field. :param QualifiedName name: name of type to query for references :param int offset: offset of the field, relative to the type + :param int max_items: optional maximum number of references to fetch :return: List of references for the given type :rtype: list(TypeReferenceSource) :Example: @@ -5678,7 +5700,9 @@ class BinaryView: """ count = ctypes.c_ulonglong(0) _name = _types.QualifiedName(name)._to_core_struct() - refs = core.BNGetTypeReferencesForTypeField(self.handle, _name, offset, count) + has_max_items = max_items is not None + max_items_value = max_items if has_max_items else 0 + refs = core.BNGetTypeReferencesForTypeField(self.handle, _name, offset, count, has_max_items, max_items_value) assert refs is not None, "core.BNGetTypeReferencesForTypeField returned None" result = [] diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index 2db833c4..2ff7caf9 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -1645,7 +1645,7 @@ pub trait BinaryViewExt: BinaryViewBase { fn code_refs_to_addr(&self, addr: u64) -> Array<CodeReference> { unsafe { let mut count = 0; - let handle = BNGetCodeReferences(self.as_ref().handle, addr, &mut count); + let handle = BNGetCodeReferences(self.as_ref().handle, addr, &mut count, false, 0); Array::new(handle, count, ()) } } @@ -1659,6 +1659,8 @@ pub trait BinaryViewExt: BinaryViewBase { range.start, range.end - range.start, &mut count, + false, + 0, ); Array::new(handle, count, ()) } @@ -1683,7 +1685,7 @@ pub trait BinaryViewExt: BinaryViewBase { fn data_refs_to_addr(&self, addr: u64) -> Array<DataReference> { unsafe { let mut count = 0; - let handle = BNGetDataReferences(self.as_ref().handle, addr, &mut count); + let handle = BNGetDataReferences(self.as_ref().handle, addr, &mut count, false, 0); Array::new(handle, count, ()) } } @@ -1697,6 +1699,8 @@ pub trait BinaryViewExt: BinaryViewBase { range.start, range.end - range.start, &mut count, + false, + 0, ); Array::new(handle, count, ()) } @@ -1717,7 +1721,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { let mut count = 0; let handle = - BNGetCodeReferencesForType(self.as_ref().handle, &mut raw_name, &mut count); + BNGetCodeReferencesForType(self.as_ref().handle, &mut raw_name, &mut count, false, 0); QualifiedName::free_raw(raw_name); Array::new(handle, count, ()) } @@ -1729,7 +1733,7 @@ pub trait BinaryViewExt: BinaryViewBase { unsafe { let mut count = 0; let handle = - BNGetDataReferencesForType(self.as_ref().handle, &mut raw_name, &mut count); + BNGetDataReferencesForType(self.as_ref().handle, &mut raw_name, &mut count, false, 0); QualifiedName::free_raw(raw_name); Array::new(handle, count, ()) } |
