Skip to content

Commit ed08160

Browse files
committed
Firmware Ninja relationships API
1 parent 60ae03f commit ed08160

File tree

5 files changed

+954
-201
lines changed

5 files changed

+954
-201
lines changed

binaryninjaapi.h

Lines changed: 248 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18570,60 +18570,250 @@ namespace BinaryNinja {
1857018570
};
1857118571

1857218572

18573-
/*! FirmwareNinjaReferenceNode is a class used to build reference trees to memory regions, functions, and data
18573+
/*! FirmwareNinjaReferenceNode is a class used to build reference trees for memory regions, functions, and data
1857418574
variables. This class is only available in the Ultimate Edition of Binary Ninja.
1857518575

1857618576
\ingroup firmwareninja
1857718577
*/
1857818578
class FirmwareNinjaReferenceNode : public CoreRefCountObject<BNFirmwareNinjaReferenceNode, BNNewFirmwareNinjaReferenceNodeReference, BNFreeFirmwareNinjaReferenceNode>
1857918579
{
18580-
BNFirmwareNinjaReferenceNode* m_object;
1858118580
public:
1858218581
FirmwareNinjaReferenceNode(BNFirmwareNinjaReferenceNode* node);
1858318582
~FirmwareNinjaReferenceNode();
1858418583

18585-
/*! Determine if the reference tree node is for a function
18584+
/*! Returns true if the reference tree node contains a function
1858618585

18587-
\return true if the reference tree node is for a function, false otherwise
18586+
\return true if the reference tree node contains a function, false otherwise
1858818587
*/
1858918588
bool IsFunction();
1859018589

18591-
/*! Determine if the reference tree node is for a data variable
18590+
/*! Returns true if the reference tree node contains a data variable
1859218591

18593-
\return true if the reference tree node is for a data variable, false otherwise
18592+
\return true if the reference tree node contains a data variable, false otherwise
1859418593
*/
1859518594
bool IsDataVariable();
1859618595

18597-
/*! Determine if the reference tree node contains child nodes
18596+
/*! Returns true if the reference tree node contains child nodes
1859818597

1859918598
\return true if the reference tree node contains child nodes, false otherwise
1860018599
*/
1860118600
bool HasChildren();
1860218601

18603-
/*! Query the function contained in the reference tree node
18602+
/*! Get the function contained in the reference tree node
1860418603

1860518604
\param function Output function object
18606-
\return true if the function was queried successfully, false otherwise
18605+
\return true if the function was queried successfully, false if the reference tree node does not contain a function
1860718606
*/
1860818607
bool GetFunction(Ref<Function>& function);
1860918608

18610-
/*! Query the data variable contained in the reference tree node
18609+
/*! Get the data variable contained in the reference tree node
1861118610

1861218611
\param function Output data variable object
18613-
\return true if the data variable was queried successfully, false otherwise
18612+
\return true if the data variable was queried successfully, false if the reference tree node does not contain a data variable
1861418613
*/
1861518614
bool GetDataVariable(DataVariable& variable);
1861618615

18617-
/*! Query the child nodes contained in the reference tree node
18616+
/*! Get the child nodes contained in the reference tree node
1861818617

1861918618
\return Vector of child reference tree nodes
1862018619
*/
1862118620
std::vector<Ref<FirmwareNinjaReferenceNode>> GetChildren();
1862218621
};
1862318622

18623+
/*! FirmwareNinjaRelationship is a class used to represent inter-binary and cross-binary relationships. This class is
18624+
only available in the Ultimate Edition of Binary Ninja.
1862418625

18625-
/*! FirmwareNinja is a class containing features specific to embedded firmware analysis. This class is only
18626-
available in the Ultimate Edition of Binary Ninja.
18626+
\ingroup firmwareninja
18627+
*/
18628+
class FirmwareNinjaRelationship : public CoreRefCountObject<BNFirmwareNinjaRelationship, BNNewFirmwareNinjaRelationshipReference, BNFreeFirmwareNinjaRelationship>
18629+
{
18630+
public:
18631+
FirmwareNinjaRelationship(Ref<BinaryView> view, BNFirmwareNinjaRelationship* relationship = nullptr);
18632+
~FirmwareNinjaRelationship();
18633+
18634+
/*! Set the primary relationship object to an address
18635+
18636+
\param address Address in current binary view
18637+
*/
18638+
void SetPrimaryAddress(uint64_t address);
18639+
18640+
/*! Set the primary relationship object to a data variable
18641+
18642+
\param var DataVariable in current binary view
18643+
*/
18644+
void SetPrimaryDataVariable(DataVariable& variable);
18645+
18646+
/*! Set the primary relationship object to a function
18647+
18648+
\param function Function in current binary view
18649+
*/
18650+
void SetPrimaryFunction(Ref<Function> function);
18651+
18652+
/*! Determine if the primary object is an address
18653+
18654+
\return true if the primary object is an address, false otherwise
18655+
*/
18656+
bool PrimaryIsAddress() const;
18657+
18658+
/*! Returns true if the primary object is a data variable
18659+
18660+
\return true if the primary object is a data variable, false otherwise
18661+
*/
18662+
bool PrimaryIsDataVariable() const;
18663+
18664+
/*! Returns true if the primary object is a function
18665+
18666+
\return true if the primary object is a function, false otherwise
18667+
*/
18668+
bool PrimaryIsFunction() const;
18669+
18670+
/*! Get the primary data variable contained in the relationship
18671+
18672+
\param var Output data variable
18673+
\return true if the data variable was queried successfully, false if the primary object is not a data variable
18674+
*/
18675+
bool GetPrimaryDataVariable(DataVariable& var);
18676+
18677+
/*! Get the primary address contained in the relationship
18678+
18679+
\return Optional address with a value if the primary object is an address
18680+
*/
18681+
std::optional<uint64_t> GetPrimaryAddress() const;
18682+
18683+
/*! Get the primary function contained in the relationship
18684+
18685+
\return Function object if the primary object is a function, nullptr otherwise
18686+
*/
18687+
Ref<Function> GetPrimaryFunction() const;
18688+
18689+
/*! Set the secondary relationship object to an address
18690+
18691+
\param address Address in current binary view
18692+
*/
18693+
void SetSecondaryAddress(uint64_t address);
18694+
18695+
/*! Set the secondary relationship object to a data variable
18696+
18697+
\param var DataVariable in current binary view
18698+
*/
18699+
void SetSecondaryDataVariable(DataVariable& variable);
18700+
18701+
/*! Set the secondary relationship object to a function
18702+
18703+
\param function Function in current binary view
18704+
*/
18705+
void SetSecondaryFunction(Ref<Function> function);
18706+
18707+
/*! Set the secondary relationship object to an external address
18708+
18709+
\param projectFile Project file for external binary in the project
18710+
\param address Address in the external binary
18711+
*/
18712+
void SetSecondaryExternalAddress(Ref<ProjectFile> projectFile, uint64_t address);
18713+
18714+
/*! Set the secondary relationship object to an external symbol
18715+
18716+
\param projectFile Project file for the external binary in the project
18717+
\param sybmol Symbol in external binary
18718+
*/
18719+
void SetSecondaryExternalSymbol(Ref<ProjectFile> projectFile, const std::string& symbol);
18720+
18721+
/*! Determine if the secondary object is an address in the current binary view
18722+
18723+
\return true if the secondary object is an address in the current binary view, false otherwise
18724+
*/
18725+
bool SecondaryIsAddress() const;
18726+
18727+
/*! Returns true if the secondary object is a data variable in the current binary view
18728+
18729+
\return true if the secondary object is a data variable in the current binary view, false otherwise
18730+
*/
18731+
bool SecondaryIsDataVariable() const;
18732+
18733+
/*! Returns true if the secondary object is a function in the current binary view
18734+
18735+
\return true if the secondary object is a function in the current binary view, false otherwise
18736+
*/
18737+
bool SecondaryIsFunction() const;
18738+
18739+
/*! Returns true if the secondary object is an address contained in another binary in the project
18740+
18741+
\return true if the secondary object is an external address, false otherwise
18742+
*/
18743+
bool SecondaryIsExternalAddress() const;
18744+
18745+
/*! Returns true if the secondary object is a symbol contained in another binary in the project
18746+
18747+
\return true if the secondary object is an external symbol, false otherwise
18748+
*/
18749+
bool SecondaryIsExternalSymbol() const;
18750+
18751+
/*! Get the secondary object's external project file
18752+
18753+
\return The secondary object's external project file or nullptr if the secondary object is not an external address
18754+
*/
18755+
Ref<ProjectFile> GetSecondaryExternalProjectFile() const;
18756+
18757+
/*! Get the secondary address from the relationship
18758+
18759+
\return Optional address containing a value, if the secondary object is an address
18760+
*/
18761+
std::optional<uint64_t> GetSecondaryAddress() const;
18762+
18763+
/*! Get the secondary data variable from the relationship
18764+
18765+
\param var Output data variable
18766+
\return true if the data variable was queried successfully, false if the secondary object is not a data variable
18767+
*/
18768+
bool GetSecondaryDataVariable(DataVariable& variable);
18769+
18770+
/*! Get the secondary function from the relationship
18771+
18772+
\return Function object if the secondary object is a function, nullptr otherwise
18773+
*/
18774+
Ref<Function> GetSecondaryFunction() const;
18775+
18776+
18777+
/*! Get the secondary external address from the relationship
18778+
18779+
\return External symbol string, or empty string if the secondary object is not an external symbol
18780+
*/
18781+
std::string GetSecondaryExternalSymbol() const;
18782+
18783+
18784+
/*! Set the description of the relationship
18785+
18786+
\param description Description string
18787+
*/
18788+
void SetDescription(const std::string& description);
18789+
18790+
/*! Get the description of the relationship
18791+
18792+
\return Description string, or empty string if not set
18793+
*/
18794+
std::string GetDescription() const;
18795+
18796+
/*! Set the provenance for the relationship
18797+
18798+
\param provenance Provenance string
18799+
*/
18800+
void SetProvenance(const std::string& provenance);
18801+
18802+
/*! Get the provenance for the relationship
18803+
18804+
\return Provenance string, or empty string if not set
18805+
*/
18806+
std::string GetProvenance() const;
18807+
18808+
/*! Get the relationship identifier
18809+
18810+
\return Relationship GUID string
18811+
*/
18812+
std::string GetGuid() const;
18813+
};
18814+
18815+
/*! FirmwareNinja is a class containing features specific to firmware analysis. This class is only available in the
18816+
Ultimate Edition of Binary Ninja.
1862718817

1862818818
\ingroup firmwareninja
1862918819
*/
@@ -18666,7 +18856,7 @@ namespace BinaryNinja {
1866618856
/*! Query Firmware Ninja device definitions for the specified board
1866718857

1866818858
\param board Name of the board to query devices for
18669-
\return Vector of Firmware Ninja device definitions
18859+
\return Vector containing Firmware Ninja device definitions
1867018860
*/
1867118861
std::vector<FirmwareNinjaDevice> QueryDevicesForBoard(const std::string& board);
1867218862

@@ -18676,7 +18866,7 @@ namespace BinaryNinja {
1867618866
\param board lowCodeEntropyThreshold Low threshold for code entropy value range
1867718867
\param blockSize Size of blocks to analyze
1867818868
\param mode Analysis mode of operation
18679-
\return Vector of Firmware Ninja section information
18869+
\return Vector containing Firmware Ninja section information
1868018870
*/
1868118871
std::vector<BNFirmwareNinjaSection> FindSections(float highCodeEntropyThreshold, float lowCodeEntropyThreshold,
1868218872
size_t blockSize, BNFirmwareNinjaSectionAnalysisMode mode);
@@ -18685,39 +18875,40 @@ namespace BinaryNinja {
1868518875

1868618876
\param progress Progress callback function
1868718877
\param progressContext Progress context
18688-
\return Vector of Firmware Ninja function memory accesses information
18878+
\return Vector containing Firmware Ninja function memory accesses
1868918879
*/
1869018880
std::vector<FirmwareNinjaFunctionMemoryAccesses> GetFunctionMemoryAccesses(BNProgressFunction progress,
1869118881
void* progressContext);
1869218882

1869318883
/*! Store Firmware Ninja function memory accesses information in the binary view metadata
1869418884

18695-
\param fma Vector of Firmware Ninja function memory accesses information
18885+
\param fma Vector containin Firmware Ninja function memory accesses
1869618886
*/
1869718887
void StoreFunctionMemoryAccesses(const std::vector<FirmwareNinjaFunctionMemoryAccesses>& fma);
1869818888

18699-
/*! Query cached Firmware Ninja function memory accesses information from the binary view metadata
18889+
/*! Query Firmware Ninja function memory accesses that are stored in the binary view metadata
1870018890

18701-
\return Vector of Firmware Ninja memory analyis information
18891+
\return Vector containing Firmware Ninja function memory accesses
1870218892
*/
1870318893
std::vector<FirmwareNinjaFunctionMemoryAccesses> QueryFunctionMemoryAccesses();
1870418894

18705-
/*! Compute number of accesses mad to memory-mapped hardware devices for each board that is compatible with the
18706-
current architecture
18895+
/*! Compute number of accesses made to memory-mapped hardware devices for each bundled board that is compatible with
18896+
the current architecture
1870718897

18708-
\param fma Vector of Firmware Ninja function memory accesses information
18709-
\return Vector of Firmware Ninja device accesses information for each board
18898+
\param fma Vector containing Firmware Ninja function memory accesses
18899+
\return Vector containing Firmware Ninja device accesses for each board
1871018900
*/
1871118901
std::vector<FirmwareNinjaDeviceAccesses> GetBoardDeviceAccesses(
1871218902
const std::vector<FirmwareNinjaFunctionMemoryAccesses>& fma);
1871318903

1871418904

18715-
/*! Returns a tree of reference nodes that reference the memory region represented by the given device
18905+
/*! Returns a tree of reference nodes that reference the memory region represented by the given Firmware Ninja
18906+
device
1871618907

1871718908
\param device Firmware Ninja device
18718-
\param fma Vector of Firmware Ninja function memory accesses information
18719-
\param value (Optional) only include components that originate with a write of this value to the device
18720-
\return Root reference node of tree
18909+
\param fma Vector containing Firmware Ninja function memory accesses
18910+
\param value (Optional) only build reference trees that originate with a write of the specified value
18911+
\return Root reference node for the tree
1872118912
*/
1872218913
Ref<FirmwareNinjaReferenceNode> GetReferenceTree(
1872318914
FirmwareNinjaDevice& device,
@@ -18728,8 +18919,8 @@ namespace BinaryNinja {
1872818919
/*! Returns a tree of reference nodes that reference the memory region represented by the given section
1872918920

1873018921
\param device Firmware Ninja device
18731-
\param fma Vector of Firmware Ninja function memory accesses information
18732-
\param value (Optional) only include components that originate with a write of this value to the device
18922+
\param fma Vector containing Firmware Ninja function memory accesses
18923+
\param value (Optional) only build reference trees that originate with a write of the specified value
1873318924
\return Root reference node of tree
1873418925
*/
1873518926
Ref<FirmwareNinjaReferenceNode> GetReferenceTree(
@@ -18742,15 +18933,40 @@ namespace BinaryNinja {
1874218933
/*! Returns a tree of reference nodes that reference the given address
1874318934

1874418935
\param device Firmware Ninja device
18745-
\param fma Vector of Firmware Ninja function memory accesses information
18746-
\param value (Optional) only include components that originate with a write of this value to the device
18936+
\param fma Vector containing Firmware Ninja function memory accesses
18937+
\param value (Optional) only build reference trees that originate with a write of the specified value
1874718938
\return Root reference node of tree
1874818939
*/
1874918940
Ref<FirmwareNinjaReferenceNode> GetReferenceTree(
1875018941
uint64_t address,
1875118942
const std::vector<FirmwareNinjaFunctionMemoryAccesses>& fma,
1875218943
uint64_t* value = nullptr
1875318944
);
18945+
18946+
/*! Query Firmware Ninja relationships from the binary view metadata
18947+
18948+
\return Vector containing Firmware Ninja relationships
18949+
*/
18950+
std::vector<Ref<FirmwareNinjaRelationship>> QueryRelationships();
18951+
18952+
/*! Store a Firmware Ninja relationship in the binary view metadata
18953+
18954+
\param relationship Firmware Ninja relationship
18955+
*/
18956+
void AddRelationship(Ref<FirmwareNinjaRelationship> relationship);
18957+
18958+
/* Query a Firmware Ninja relationship by GUID
18959+
18960+
\param guid GUID of the relationship to query
18961+
\return Firmware Ninja relationship if found, nullptr otherwise
18962+
*/
18963+
Ref<FirmwareNinjaRelationship> GetRelationshipByGuid(const std::string& guid);
18964+
18965+
/*! Remove a Firmware Ninja relationship from the binary view metadata
18966+
18967+
\param guid GUID of the relationship to remove
18968+
*/
18969+
void RemoveRelationshipByGuid(const std::string& guid);
1875418970
};
1875518971

1875618972

0 commit comments

Comments
 (0)