summaryrefslogtreecommitdiff
path: root/typecontainer.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2023-11-01 17:03:17 -0400
committerGlenn Smith <glenn@vector35.com>2024-02-07 17:23:49 -0500
commit8037455723546000448135499957273623776581 (patch)
tree268322ef34d16e067210df592dd782d50f294e3c /typecontainer.cpp
parente1542ed05f3f8c273206bb9ead8d39fea87430bb (diff)
Type Archives
Diffstat (limited to 'typecontainer.cpp')
-rw-r--r--typecontainer.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/typecontainer.cpp b/typecontainer.cpp
index ba411b83..bd31a134 100644
--- a/typecontainer.cpp
+++ b/typecontainer.cpp
@@ -50,6 +50,13 @@ TypeContainer::TypeContainer(Ref<TypeLibrary> library)
}
+TypeContainer::TypeContainer(Ref<TypeArchive> archive)
+{
+ auto container = archive->GetTypeContainer();
+ m_object = BNDuplicateTypeContainer(container.m_object);
+}
+
+
TypeContainer::TypeContainer(Ref<Platform> platform)
{
auto container = platform->GetTypeContainer();
@@ -322,6 +329,44 @@ std::optional<std::unordered_map<std::string, QualifiedName>> TypeContainer::Get
}
+bool TypeContainer::ParseTypeString(
+ const std::string& source,
+ BinaryNinja::QualifiedNameAndType& result,
+ std::vector<TypeParserError>& errors
+)
+{
+ BNQualifiedNameAndType apiResult;
+ BNTypeParserError* apiErrors;
+ size_t errorCount;
+
+ auto success = BNTypeContainerParseTypeString(m_object, source.c_str(), &apiResult,
+ &apiErrors, &errorCount);
+
+ for (size_t j = 0; j < errorCount; j ++)
+ {
+ TypeParserError error;
+ error.severity = apiErrors[j].severity,
+ error.message = apiErrors[j].message,
+ error.fileName = apiErrors[j].fileName,
+ error.line = apiErrors[j].line,
+ error.column = apiErrors[j].column,
+ errors.push_back(error);
+ }
+ BNFreeTypeParserErrors(apiErrors, errorCount);
+
+ if (!success)
+ {
+ return false;
+ }
+
+ result.type = new Type(BNNewTypeReference(apiResult.type));
+ result.name = QualifiedName::FromAPIObject(&apiResult.name);
+
+ BNFreeQualifiedNameAndType(&apiResult);
+ return true;
+}
+
+
bool TypeContainer::ParseTypesFromSource(
const std::string& text,
const std::string& fileName,