diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-02-12 15:29:03 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-02-13 13:51:53 -0500 |
| commit | 1925885513166893508719453618249182735388 (patch) | |
| tree | 073055483454543f5e0043fb627c8514577fe6cc /binaryview.cpp | |
| parent | 88b364801d4d740435b5dfe5c6a07736a00d233d (diff) | |
StringRef and direct access to symbol names
Diffstat (limited to 'binaryview.cpp')
| -rw-r--r-- | binaryview.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/binaryview.cpp b/binaryview.cpp index e8638025..cb33d616 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -650,6 +650,83 @@ BinaryDataNotification::BinaryDataNotification(NotificationTypes notifications) } +StringRef::StringRef() +{ + m_ref = nullptr; +} + + +StringRef::StringRef(BNStringRef* ref) +{ + m_ref = ref; +} + + +StringRef::StringRef(const StringRef& other) +{ + m_ref = BNDuplicateStringRef(other.m_ref); +} + + +StringRef::StringRef(StringRef&& other) +{ + m_ref = other.m_ref; + other.m_ref = nullptr; +} + + +StringRef::~StringRef() +{ + if (m_ref) + { + BNFreeStringRef(m_ref); + } +} + + +StringRef& StringRef::operator=(const StringRef& other) +{ + if (m_ref) + { + BNFreeStringRef(m_ref); + m_ref = nullptr; + } + if (other.m_ref) + { + m_ref = BNDuplicateStringRef(other.m_ref); + } + return *this; +} + + +StringRef& StringRef::operator=(StringRef&& other) +{ + if (m_ref) + { + BNFreeStringRef(m_ref); + } + m_ref = other.m_ref; + other.m_ref = nullptr; + return *this; +} + + +const char* StringRef::c_str() const +{ + if (!m_ref) + return ""; // todo: nullptr? + return BNGetStringRefContents(m_ref); +} + + +size_t StringRef::size() const +{ + if (!m_ref) + return 0; + return BNGetStringRefSize(m_ref); +} + + Symbol::Symbol(BNSymbolType type, const string& shortName, const string& fullName, const string& rawName, uint64_t addr, BNSymbolBinding binding, const NameSpace& nameSpace, uint64_t ordinal) { @@ -710,6 +787,13 @@ string Symbol::GetShortName() const } +StringRef Symbol::GetShortNameRef() const +{ + BNStringRef* name = BNGetSymbolShortNameRef(m_object); + return StringRef(name); +} + + string Symbol::GetFullName() const { char* name = BNGetSymbolFullName(m_object); @@ -719,6 +803,13 @@ string Symbol::GetFullName() const } +StringRef Symbol::GetFullNameRef() const +{ + BNStringRef* name = BNGetSymbolFullNameRef(m_object); + return StringRef(name); +} + + string Symbol::GetRawName() const { char* name = BNGetSymbolRawName(m_object); @@ -728,6 +819,13 @@ string Symbol::GetRawName() const } +StringRef Symbol::GetRawNameRef() const +{ + BNStringRef* name = BNGetSymbolRawNameRef(m_object); + return StringRef(name); +} + + uint64_t Symbol::GetAddress() const { return BNGetSymbolAddress(m_object); |
