From 1925885513166893508719453618249182735388 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Wed, 12 Feb 2025 15:29:03 -0500 Subject: StringRef and direct access to symbol names --- binaryninjaapi.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 7ec05868..5ee30625 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3888,6 +3888,35 @@ namespace BinaryNinja { static NameSpace FromAPIObject(const BNNameSpace* name); }; + class StringRef + { + BNStringRef* m_ref; + + public: + StringRef(); + explicit StringRef(BNStringRef* ref); + StringRef(const StringRef& other); + StringRef(StringRef&& other); + ~StringRef(); + StringRef& operator=(const StringRef& other); + StringRef& operator=(StringRef&& other); + + operator std::string_view() const { return std::string_view(c_str(), size()); } + operator std::string const() { return c_str(); } + + const char* c_str() const; + size_t size() const; + BNStringRef* GetObject() { return m_ref; } + + bool operator==(const StringRef& other) const { return this->operator std::string_view() == other.operator std::string_view(); } + bool operator!=(const StringRef& other) const { return this->operator std::string_view() != other.operator std::string_view(); } + bool operator<(const StringRef& other) const { return this->operator std::string_view() < other.operator std::string_view(); } + bool operator==(const std::string& other) const { return this->operator std::string_view() == other; } + bool operator!=(const std::string& other) const { return this->operator std::string_view() != other; } + bool operator==(const std::string_view& other) const { return this->operator std::string_view() == other; } + bool operator!=(const std::string_view& other) const { return this->operator std::string_view() != other; } + }; + /*! \ingroup types */ @@ -3934,16 +3963,31 @@ namespace BinaryNinja { */ std::string GetShortName() const; + /*! + \return Symbol short name + */ + StringRef GetShortNameRef() const; + /*! \return Symbol full name */ std::string GetFullName() const; + /*! + \return Symbol full name + */ + StringRef GetFullNameRef() const; + /*! \return Symbol raw name */ std::string GetRawName() const; + /*! + \return Symbol raw name + */ + StringRef GetRawNameRef() const; + /*! \return Symbol Address */ @@ -20662,6 +20706,15 @@ namespace std return std::hash()(T::GetObject(value.GetPtr())); } }; + + template<> struct hash + { + typedef BinaryNinja::StringRef argument_type; + size_t operator()(argument_type const& value) const + { + return std::hash()(value.operator std::string_view()); + } + }; } // namespace std @@ -20695,6 +20748,19 @@ template<> struct fmt::formatter constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { return ctx.begin(); } }; + +template<> struct fmt::formatter : fmt::formatter +{ + format_context::iterator format(const BinaryNinja::StringRef& obj, format_context& ctx) const + { + return fmt::formatter::format(obj.operator std::string_view(), ctx); + } + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + return fmt::formatter::parse(ctx); + } +}; + template struct fmt::formatter, void>> { -- cgit v1.3.1