From dc1094fb4a1f416a5e56bef4941a35bca3506865 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 4 Sep 2025 18:21:25 -0400 Subject: Add type attribute APIs --- type.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'type.cpp') diff --git a/type.cpp b/type.cpp index 9dccede1..6ee0e1cb 100644 --- a/type.cpp +++ b/type.cpp @@ -753,6 +753,29 @@ std::vector Type::GetPointerSuffixTokens(uint8_t baseConfi } +std::vector Type::GetAttributes() const +{ + size_t count = 0; + BNTypeAttribute* attributes = BNGetTypeAttributes(m_object, &count); + std::vector result; + for (size_t i = 0; i < count; i++) + result.emplace_back(attributes[i].name, attributes[i].value); + BNFreeTypeAttributeList(attributes, count); + return result; +} + + +std::optional Type::GetAttribute(const std::string& name) const +{ + char* result = BNGetTypeAttributeByName(m_object, name.c_str()); + if (!result) + return std::nullopt; + std::string resultStr(result); + BNFreeString(result); + return resultStr; +} + + string Type::GetString(Platform* platform, BNTokenEscapingType escaping) const { char* str = BNGetTypeString(m_object, platform ? platform->GetObject() : nullptr, escaping); @@ -2189,6 +2212,55 @@ TypeBuilder& TypeBuilder::SetPointerSuffix(const std::set& suff } +void TypeBuilder::SetAttribute(const std::string& name, const std::string& value) +{ + BNSetTypeBuilderAttribute(m_object, name.c_str(), value.c_str()); +} + + +void TypeBuilder::SetAttributes(const std::map& values) +{ + BNTypeAttribute* attrs = new BNTypeAttribute[values.size()]; + size_t i = 0; + for (auto& [name, value] : values) + { + attrs[i].name = (char*)name.c_str(); + attrs[i].value = (char*)value.c_str(); + i++; + } + BNSetTypeBuilderAttributeList(m_object, attrs, values.size()); +} + + +void TypeBuilder::RemoveAttribute(const std::string& name) +{ + BNRemoveTypeBuilderAttribute(m_object, name.c_str()); +} + + +std::vector TypeBuilder::GetAttributes() const +{ + size_t count; + BNTypeAttribute* attributes = BNGetTypeBuilderAttributes(m_object, &count); + std::vector result; + for (size_t i = 0; i < count; i++) + result.emplace_back(attributes[i].name, attributes[i].value); + BNFreeTypeAttributeList(attributes, count); + return result; +} + + +std::optional TypeBuilder::GetAttribute(const std::string& name) const +{ + char* result = BNGetTypeBuilderAttributeByName(m_object, name.c_str()); + if (!result) + return std::nullopt; + std::string resultStr(result); + BNFreeString(result); + return resultStr; +} + + QualifiedName TypeBuilder::GetTypeName() const { BNQualifiedName name = BNTypeBuilderGetTypeName(m_object); -- cgit v1.3.1