Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5098,6 +5098,30 @@ namespace BinaryNinja {
Ref<Function> func;
Ref<Architecture> arch;
uint64_t addr;

BNReferenceSource ToAPIStruct() const;
static ReferenceSource FromAPIStruct(const BNReferenceSource* source);
static void FreeAPIStruct(BNReferenceSource* source);
};

struct CodeXref
{
ReferenceSource source;
uint64_t target;

BNCodeXref ToAPIStruct() const;
static CodeXref FromAPIStruct(const BNCodeXref* ref);
static void FreeAPIStruct(BNCodeXref* ref);
};

struct DataXref
{
uint64_t source;
uint64_t target;

BNDataXref ToAPIStruct() const;
static DataXref FromAPIStruct(const BNDataXref* ref);
static void FreeAPIStruct(BNDataXref* ref);
};

struct TypeFieldReference
Expand Down Expand Up @@ -6699,6 +6723,47 @@ namespace BinaryNinja {
*/
std::vector<uint64_t> GetDataReferencesFrom(uint64_t addr, uint64_t len);

/*! Get references made by code (instructions) to a range of addresses, each with its source and target

\param addr Start of the range
\param len Length of the range
\param maxItems Optional maximum number of items to fetch
\return References whose target is in the range
*/
std::vector<CodeXref> GetIncomingCodeReferences(
uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt);

/*! Get references made by data ('DataVariables') to a range of addresses, each with its source and target

\param addr Start of the range
\param len Length of the range
\param maxItems Optional maximum number of items to fetch
\return References whose target is in the range
*/
std::vector<DataXref> GetIncomingDataReferences(
uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt);

/*! Get references made by code (instructions) in a range of addresses, each with its source and target

\param addr Start of the range
\param len Length of the range
\param func Function whose references are returned, or nullptr for every function with code in the range
\param maxItems Optional maximum number of items to fetch
\return References whose source is in the range
*/
std::vector<CodeXref> GetOutgoingCodeReferences(uint64_t addr, uint64_t len, Ref<Function> func = nullptr,
std::optional<size_t> maxItems = std::nullopt);

/*! Get references made by data ('DataVariables') in a range of addresses, each with its source and target

\param addr Start of the range
\param len Length of the range
\param maxItems Optional maximum number of items to fetch
\return References whose source is in the range
*/
std::vector<DataXref> GetOutgoingDataReferences(
uint64_t addr, uint64_t len, std::optional<size_t> maxItems = std::nullopt);


/*! Add an auto Data Reference from a virtual address to another virtual address

Expand Down
24 changes: 23 additions & 1 deletion binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 189
#define BN_CURRENT_CORE_ABI_VERSION 190

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
Expand Down Expand Up @@ -2637,6 +2637,18 @@ extern "C"
uint64_t addr;
} BNReferenceSource;

typedef struct BNCodeXref
{
BNReferenceSource source;
uint64_t target;
} BNCodeXref;

typedef struct BNDataXref
{
uint64_t source;
uint64_t target;
} BNDataXref;

typedef struct BNTypeFieldReference
{
BNFunction* func;
Expand Down Expand Up @@ -6313,6 +6325,16 @@ extern "C"
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);
BINARYNINJACOREAPI BNCodeXref* BNGetIncomingCodeReferences(
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
BINARYNINJACOREAPI BNDataXref* BNGetIncomingDataReferences(
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
BINARYNINJACOREAPI BNCodeXref* BNGetOutgoingCodeReferences(BNBinaryView* view, uint64_t addr, uint64_t len,
BNFunction* func, size_t* count, bool limit, size_t maxItems);
BINARYNINJACOREAPI BNDataXref* BNGetOutgoingDataReferences(
BNBinaryView* view, uint64_t addr, uint64_t len, size_t* count, bool limit, size_t maxItems);
BINARYNINJACOREAPI void BNFreeCodeXrefs(BNCodeXref* refs, size_t count);
BINARYNINJACOREAPI void BNFreeDataXrefs(BNDataXref* refs, size_t count);
BINARYNINJACOREAPI void BNAddDataReference(BNBinaryView* view, uint64_t fromAddr, uint64_t toAddr);
BINARYNINJACOREAPI void BNRemoveDataReference(BNBinaryView* view, uint64_t fromAddr, uint64_t toAddr);
BINARYNINJACOREAPI void BNAddUserDataReference(BNBinaryView* view, uint64_t fromAddr, uint64_t toAddr);
Expand Down
Loading
Loading