Skip to content

Commit c41b80e

Browse files
committed
Add the ability to limit the number of results in the cross reference APIs
1 parent 6894a94 commit c41b80e

5 files changed

Lines changed: 249 additions & 83 deletions

File tree

binaryninjaapi.h

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5520,9 +5520,27 @@ namespace BinaryNinja {
55205520
*/
55215521
std::vector<ReferenceSource> GetCodeReferences(uint64_t addr, uint64_t len);
55225522

5523+
/*! Get a list of references made from code (instructions) to a virtual address
5524+
5525+
\param addr Address to check
5526+
\param maxItems Optional maximum number of items to fetch
5527+
\return vector of ReferenceSources referencing the virtual address
5528+
*/
5529+
std::vector<ReferenceSource> GetCodeReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems = std::nullopt);
5530+
5531+
/*! Get a list of references from code (instructions) to a range of addresses
5532+
5533+
\param addr Address to check
5534+
\param len Length of query
5535+
\param maxItems Optional maximum number of items to fetch
5536+
\return vector of ReferenceSources referencing the virtual address range
5537+
*/
5538+
std::vector<ReferenceSource> GetCodeReferencesInRangeWithLimit(
5539+
uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt);
5540+
55235541
/*! Get code references made by a particular "ReferenceSource"
55245542

5525-
A ReferenceSource contains a given function, architecture of that function, and an address within it.
5543+
A ReferenceSource contains a given function, architecture of that function, and an address within it.
55265544

55275545
\param src reference source
55285546
\return List of virtual addresses referenced by this source
@@ -5556,6 +5574,24 @@ namespace BinaryNinja {
55565574
*/
55575575
std::vector<uint64_t> GetDataReferences(uint64_t addr, uint64_t len);
55585576

5577+
/*! Get references made by data ('DataVariables') to a virtual address
5578+
5579+
\param addr Address to check
5580+
\param maxItems Optional maximum number of items to fetch
5581+
\return vector of virtual addresses referencing the virtual address
5582+
*/
5583+
std::vector<uint64_t> GetDataReferencesWithLimit(uint64_t addr, std::optional<size_t> maxItems = std::nullopt);
5584+
5585+
/*! Get references made by data ('DataVariables') in a given range, to a virtual address
5586+
5587+
\param addr Address to check
5588+
\param len Length of query
5589+
\param maxItems Optional maximum number of items to fetch
5590+
\return vector of virtual addresses referencing the virtual address range
5591+
*/
5592+
std::vector<uint64_t> GetDataReferencesInRangeWithLimit(
5593+
uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt);
5594+
55595595
/*! Get references made by data ('DataVariables') located at a virtual address.
55605596

55615597
\param src reference source
@@ -5605,76 +5641,94 @@ namespace BinaryNinja {
56055641
/*! Get code references to a Type
56065642

56075643
\param type QualifiedName for a Type
5644+
\param maxItems Optional maximum number of items to fetch
56085645
\return vector of ReferenceSources
56095646
*/
5610-
std::vector<ReferenceSource> GetCodeReferencesForType(const QualifiedName& type);
5647+
std::vector<ReferenceSource> GetCodeReferencesForType(
5648+
const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt);
56115649

56125650
/*! Get data references to a Type
56135651

56145652
\param type QualifiedName for a Type
5653+
\param maxItems Optional maximum number of items to fetch
56155654
\return vector of virtual addresses referencing this Type
56165655
*/
5617-
std::vector<uint64_t> GetDataReferencesForType(const QualifiedName& type);
5656+
std::vector<uint64_t> GetDataReferencesForType(
5657+
const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt);
56185658

56195659
/*! Get Type references to a Type
56205660

56215661
\param type QualifiedName for a Type
5662+
\param maxItems Optional maximum number of items to fetch
56225663
\return vector of TypeReferenceSources to this Type
56235664
*/
5624-
std::vector<TypeReferenceSource> GetTypeReferencesForType(const QualifiedName& type);
5665+
std::vector<TypeReferenceSource> GetTypeReferencesForType(
5666+
const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt);
56255667

56265668
/*! Returns a list of references to a specific type field
56275669

5628-
\param type QualifiedName of the type
5629-
\param offset Offset of the field, relative to the start of the type
5630-
\return vector of TypeFieldReferences
5670+
\param type QualifiedName of the type
5671+
\param offset Offset of the field, relative to the start of the type
5672+
\param maxItems Optional maximum number of items to fetch
5673+
\return vector of TypeFieldReferences
56315674
*/
5632-
std::vector<TypeFieldReference> GetCodeReferencesForTypeField(const QualifiedName& type, uint64_t offset);
5675+
std::vector<TypeFieldReference> GetCodeReferencesForTypeField(
5676+
const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt);
56335677

56345678
/*! Returns a list of virtual addresses of data which references the type \c type .
56355679

5636-
Note, the returned addresses are the actual start of the queried type field. For example, suppose there is a
5637-
DataVariable at \c 0x1000 that has type \c A , and type \c A contains type \c B at offset \c 0x10 .
5638-
Then <tt>GetDataReferencesForTypeField(bQualifiedName, 0x8)</tt> will return \c 0x1018 for it.
5680+
Note, the returned addresses are the actual start of the queried type field. For example, suppose there is a
5681+
DataVariable at \c 0x1000 that has type \c A , and type \c A contains type \c B at offset \c 0x10 .
5682+
Then <tt>GetDataReferencesForTypeField(bQualifiedName, 0x8)</tt> will return \c 0x1018 for it.
56395683

5640-
\param type QualifiedName of the type
5641-
\param offset Offset of the field, relative to the start of the type
5642-
\return List of DataVariable start addresses containing references to the type field
5684+
\param type QualifiedName of the type
5685+
\param offset Offset of the field, relative to the start of the type
5686+
\param maxItems Optional maximum number of items to fetch
5687+
\return List of DataVariable start addresses containing references to the type field
56435688
*/
5644-
std::vector<uint64_t> GetDataReferencesForTypeField(const QualifiedName& type, uint64_t offset);
5689+
std::vector<uint64_t> GetDataReferencesForTypeField(
5690+
const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt);
56455691

56465692
/*! Returns a list of virtual addresses of data which are referenced from the type \c type .
56475693

56485694
Only data referenced by structures with the \c __data_var_refs attribute are included.
56495695

56505696
\param type QualifiedName of the type
56515697
\param offset Offset of the field, relative to the start of the type
5698+
\param maxItems Optional maximum number of items to fetch
56525699
\return List of addresses referenced from the type field
56535700
*/
5654-
std::vector<uint64_t> GetDataReferencesFromForTypeField(const QualifiedName& type, uint64_t offset);
5701+
std::vector<uint64_t> GetDataReferencesFromForTypeField(
5702+
const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt);
56555703

56565704
/*! Returns a list of type references to a specific type field
56575705

5658-
\param type QualifiedName of the type
5659-
\param offset Offset of the field, relative to the start of the type
5660-
\return vector of TypeReferenceSources
5706+
\param type QualifiedName of the type
5707+
\param offset Offset of the field, relative to the start of the type
5708+
\param maxItems Optional maximum number of items to fetch
5709+
\return vector of TypeReferenceSources
56615710
*/
5662-
std::vector<TypeReferenceSource> GetTypeReferencesForTypeField(const QualifiedName& type, uint64_t offset);
5711+
std::vector<TypeReferenceSource> GetTypeReferencesForTypeField(
5712+
const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt);
56635713

56645714
/*! Returns a all references to a specific type. This includes code, data, and type references.
56655715

56665716
\param type QualifiedName of the type
5717+
\param maxItems Optional maximum number of items to fetch
56675718
\return AllTypeReferences structure with all references
56685719
*/
5669-
AllTypeReferences GetAllReferencesForType(const QualifiedName& type);
5720+
AllTypeReferences GetAllReferencesForType(
5721+
const QualifiedName& type, std::optional<size_t> maxItems = std::nullopt);
56705722

56715723
/*! Returns a all references to a specific type field. This includes code, data, and type references.
56725724

56735725
\param type QualifiedName of the type
56745726
\param offset Offset of the field, relative to the start of the type
5727+
\param maxItems Optional maximum number of items to fetch
56755728
\return AllTypeFieldReferences structure with all references
56765729
*/
5677-
AllTypeFieldReferences GetAllReferencesForTypeField(const QualifiedName& type, uint64_t offset);
5730+
AllTypeFieldReferences GetAllReferencesForTypeField(
5731+
const QualifiedName& type, uint64_t offset, std::optional<size_t> maxItems = std::nullopt);
56785732

56795733
/*! Returns a list of types referenced by code at ReferenceSource \c src
56805734

binaryninjacore.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,19 +5020,21 @@ extern "C"
50205020
BINARYNINJACOREAPI void BNMarkFunctionAsRecentlyUsed(BNFunction* func);
50215021
BINARYNINJACOREAPI void BNMarkBasicBlockAsRecentlyUsed(BNBasicBlock* block);
50225022

5023-
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences(BNBinaryView* view, uint64_t addr, size_t* count);
5023+
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences(
5024+
BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems);
50245025
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesInRange(
5025-
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
5026+
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
50265027
BINARYNINJACOREAPI void BNFreeCodeReferences(BNReferenceSource* refs, size_t count);
50275028
BINARYNINJACOREAPI void BNFreeTypeFieldReferences(BNTypeFieldReference* refs, size_t count);
50285029
BINARYNINJACOREAPI void BNFreeILReferences(BNILReferenceSource* refs, size_t count);
50295030
BINARYNINJACOREAPI uint64_t* BNGetCodeReferencesFrom(BNBinaryView* view, BNReferenceSource* src, size_t* count);
50305031
BINARYNINJACOREAPI uint64_t* BNGetCodeReferencesFromInRange(
50315032
BNBinaryView* view, BNReferenceSource* src, uint64_t len, size_t* count);
50325033

5033-
BINARYNINJACOREAPI uint64_t* BNGetDataReferences(BNBinaryView* view, uint64_t addr, size_t* count);
5034+
BINARYNINJACOREAPI uint64_t* BNGetDataReferences(
5035+
BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems);
50345036
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesInRange(
5035-
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
5037+
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
50365038
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFrom(BNBinaryView* view, uint64_t addr, size_t* count);
50375039
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromInRange(
50385040
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
@@ -5050,25 +5052,27 @@ extern "C"
50505052

50515053
// References to type
50525054
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesForType(
5053-
BNBinaryView* view, BNQualifiedName* type, size_t* count);
5054-
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType(BNBinaryView* view, BNQualifiedName* type, size_t* count);
5055+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
5056+
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType(
5057+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
50555058
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForType(
5056-
BNBinaryView* view, BNQualifiedName* type, size_t* count);
5059+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
50575060

50585061
// References to type field
50595062
BINARYNINJACOREAPI BNTypeFieldReference* BNGetCodeReferencesForTypeField(
5060-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5063+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50615064
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForTypeField(
5062-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5065+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50635066
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromForTypeField(
5064-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5067+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50655068
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForTypeField(
5066-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5069+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50675070

5068-
BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(BNBinaryView* view, BNQualifiedName* type);
5071+
BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(
5072+
BNBinaryView* view, BNQualifiedName* type, bool limit, size_t maxItems);
50695073
BINARYNINJACOREAPI void BNFreeAllTypeReferences(BNAllTypeReferences* refs);
50705074
BINARYNINJACOREAPI BNAllTypeFieldReferences BNGetAllReferencesForTypeField(
5071-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset);
5075+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, bool limit, size_t maxItems);
50725076
BINARYNINJACOREAPI void BNFreeAllTypeFieldReferences(BNAllTypeFieldReferences* refs);
50735077

50745078
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetCodeReferencesForTypeFrom(

0 commit comments

Comments
 (0)