summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2025-02-12 15:29:03 -0500
committerGlenn Smith <glenn@vector35.com>2025-02-13 13:51:53 -0500
commit1925885513166893508719453618249182735388 (patch)
tree073055483454543f5e0043fb627c8514577fe6cc /binaryninjaapi.h
parent88b364801d4d740435b5dfe5c6a07736a00d233d (diff)
StringRef and direct access to symbol names
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h66
1 files changed, 66 insertions, 0 deletions
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
*/
@@ -3935,16 +3964,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
*/
uint64_t GetAddress() const;
@@ -20662,6 +20706,15 @@ namespace std
return std::hash<decltype(T::GetObject(value.GetPtr()))>()(T::GetObject(value.GetPtr()));
}
};
+
+ template<> struct hash<BinaryNinja::StringRef>
+ {
+ typedef BinaryNinja::StringRef argument_type;
+ size_t operator()(argument_type const& value) const
+ {
+ return std::hash<std::string_view>()(value.operator std::string_view());
+ }
+ };
} // namespace std
@@ -20695,6 +20748,19 @@ template<> struct fmt::formatter<BinaryNinja::NameList>
constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { return ctx.begin(); }
};
+
+template<> struct fmt::formatter<BinaryNinja::StringRef> : fmt::formatter<std::string_view>
+{
+ format_context::iterator format(const BinaryNinja::StringRef& obj, format_context& ctx) const
+ {
+ return fmt::formatter<std::string_view>::format(obj.operator std::string_view(), ctx);
+ }
+ constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator
+ {
+ return fmt::formatter<std::string_view>::parse(ctx);
+ }
+};
+
template<typename T>
struct fmt::formatter<T, char, std::enable_if_t<std::is_enum_v<T>, void>>
{