From c74fa0d5f974efa4ccd569a821701956063a31e9 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Fri, 22 Nov 2024 08:20:14 -0500 Subject: C++ and Python API for Firmware Ninja --- binaryninjaapi.h | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 2de2aa63..762cd275 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -18369,6 +18369,129 @@ namespace BinaryNinja { bool IsAborted(); }; + + /*! + \ingroup firmwareninja + */ + struct FirmwareNinjaDevice + { + std::string name; + uint64_t start; + uint64_t end; + std::string info; + }; + + /*! + \ingroup firmwareninja + */ + struct FirmwareNinjaFunctionMemoryAccesses + { + uint64_t start; + size_t count; + std::vector accesses; + }; + + /*! + \ingroup firmwareninja + */ + struct FirmwareNinjaDeviceAccesses + { + std::string name; + size_t total; + size_t unique; + }; + + /*! FirmwareNinja is a class containing features specific to embedded firmware analysis. This class is only + available in the Ultimate Edition of Binary Ninja. + + \ingroup firmwareninja + */ + class FirmwareNinja + { + Ref m_view; + BNFirmwareNinja* m_object; + + public: + FirmwareNinja(Ref view); + ~FirmwareNinja(); + + /*! Store a user-defined Firmware Ninja device to the binary view metadata + + \param device Hardware device information + \return true on success, false otherwise + */ + bool StoreCustomDevice(FirmwareNinjaDevice& device); + + /*! Remove a user-defined Firmware Ninja device from the binary view metadata + + \param name Name of the device to remove + \return true on success, false otherwise + */ + bool RemoveCustomDevice(const std::string& name); + + /*! Query all user-defined Firmware Ninja devices from the binary view metadata + + \return Vector of user-defined Firmware Ninja devices + */ + std::vector QueryCustomDevices(); + + /*! Query names of all boards that are compatable with the current binary view and contain bundled device + definitions + + \return Vector of board names + */ + std::vector QueryBoardNames(); + + /*! Query Firmware Ninja device definitions for the specified board + + \param board Name of the board to query devices for + \return Vector of Firmware Ninja device definitions + */ + std::vector QueryDevicesForBoard(const std::string& board); + + /*! Find sections in the binary with Firmware Ninja heuristics and entropy analysis + + \param board highCodeEntropyThreshold High threshold for code entropy value range + \param board lowCodeEntropyThreshold Low threshold for code entropy value range + \param blockSize Size of blocks to analyze + \param mode Analysis mode of operation + \return Vector of Firmware Ninja section information + */ + std::vector FindSections(float highCodeEntropyThreshold, float lowCodeEntropyThreshold, + size_t blockSize, BNFirmwareNinjaSectionAnalysisMode mode); + + /*! Find functions that access memory-mapped I/O and other non-file backed memory regions + + \param progress Progress callback function + \param progressContext Progress context + \return Vector of Firmware Ninja function memory accesses information + */ + std::vector GetFunctionMemoryAccesses(BNProgressFunction progress, + void* progressContext); + + /*! Store Firmware Ninja function memory accesses information in the binary view metadata + + \param fma Vector of Firmware Ninja function memory accesses information + */ + void StoreFunctionMemoryAccesses(const std::vector& fma); + + /*! Query cached Firmware Ninja function memory accesses information from the binary view metadata + + \return Vector of Firmware Ninja memory analyis information + */ + std::vector QueryFunctionMemoryAccesses(); + + /*! Compute number of accesses mad to memory-mapped hardware devices for each board that is compatible with the + current architecture + + \param fma Vector of Firmware Ninja function memory accesses information + \return Vector of Firmware Ninja device accesses information for each board + */ + std::vector GetBoardDeviceAccesses( + const std::vector& fma); + }; + + /*! \ingroup demangler */ -- cgit v1.3.1