Skip to content

Commit 9d7ef5d

Browse files
committed
Add the ability to limit the number of results in the cross reference APIs
1 parent 4f134f7 commit 9d7ef5d

File tree

5 files changed

+249
-83
lines changed

5 files changed

+249
-83
lines changed

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
@@ -5028,19 +5028,21 @@ extern "C"
50285028
BINARYNINJACOREAPI void BNMarkFunctionAsRecentlyUsed(BNFunction* func);
50295029
BINARYNINJACOREAPI void BNMarkBasicBlockAsRecentlyUsed(BNBasicBlock* block);
50305030

5031-
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences(BNBinaryView* view, uint64_t addr, size_t* count);
5031+
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferences(
5032+
BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems);
50325033
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesInRange(
5033-
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
5034+
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
50345035
BINARYNINJACOREAPI void BNFreeCodeReferences(BNReferenceSource* refs, size_t count);
50355036
BINARYNINJACOREAPI void BNFreeTypeFieldReferences(BNTypeFieldReference* refs, size_t count);
50365037
BINARYNINJACOREAPI void BNFreeILReferences(BNILReferenceSource* refs, size_t count);
50375038
BINARYNINJACOREAPI uint64_t* BNGetCodeReferencesFrom(BNBinaryView* view, BNReferenceSource* src, size_t* count);
50385039
BINARYNINJACOREAPI uint64_t* BNGetCodeReferencesFromInRange(
50395040
BNBinaryView* view, BNReferenceSource* src, uint64_t len, size_t* count);
50405041

5041-
BINARYNINJACOREAPI uint64_t* BNGetDataReferences(BNBinaryView* view, uint64_t addr, size_t* count);
5042+
BINARYNINJACOREAPI uint64_t* BNGetDataReferences(
5043+
BNBinaryView* view, uint64_t addr, size_t* count, bool limit, size_t maxItems);
50425044
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesInRange(
5043-
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
5045+
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
50445046
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFrom(BNBinaryView* view, uint64_t addr, size_t* count);
50455047
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromInRange(
50465048
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count);
@@ -5058,25 +5060,27 @@ extern "C"
50585060

50595061
// References to type
50605062
BINARYNINJACOREAPI BNReferenceSource* BNGetCodeReferencesForType(
5061-
BNBinaryView* view, BNQualifiedName* type, size_t* count);
5062-
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType(BNBinaryView* view, BNQualifiedName* type, size_t* count);
5063+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
5064+
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForType(
5065+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
50635066
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForType(
5064-
BNBinaryView* view, BNQualifiedName* type, size_t* count);
5067+
BNBinaryView* view, BNQualifiedName* type, size_t* count, bool limit, size_t maxItems);
50655068

50665069
// References to type field
50675070
BINARYNINJACOREAPI BNTypeFieldReference* BNGetCodeReferencesForTypeField(
5068-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5071+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50695072
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesForTypeField(
5070-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5073+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50715074
BINARYNINJACOREAPI uint64_t* BNGetDataReferencesFromForTypeField(
5072-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5075+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50735076
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForTypeField(
5074-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
5077+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count, bool limit, size_t maxItems);
50755078

5076-
BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(BNBinaryView* view, BNQualifiedName* type);
5079+
BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(
5080+
BNBinaryView* view, BNQualifiedName* type, bool limit, size_t maxItems);
50775081
BINARYNINJACOREAPI void BNFreeAllTypeReferences(BNAllTypeReferences* refs);
50785082
BINARYNINJACOREAPI BNAllTypeFieldReferences BNGetAllReferencesForTypeField(
5079-
BNBinaryView* view, BNQualifiedName* type, uint64_t offset);
5083+
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, bool limit, size_t maxItems);
50805084
BINARYNINJACOREAPI void BNFreeAllTypeFieldReferences(BNAllTypeFieldReferences* refs);
50815085

50825086
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetCodeReferencesForTypeFrom(

0 commit comments

Comments
 (0)