summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2024-05-30 22:20:36 -0400
committerJosh Ferrell <josh@vector35.com>2024-06-04 13:29:16 -0400
commitdcd9cc4f62138ef94c6c496fc214045f44e62d4d (patch)
tree5fa9e6bcd63256b87ac342e1cbef61a1b540a6a0
parentba88ba867035e7cd32ac967075d6e4df0dcb18d3 (diff)
Fix crash in AnalysisMergeConflict::GetPathItem
-rw-r--r--binaryninjaapi.h7
-rw-r--r--binaryninjacore.h1
-rw-r--r--collaboration.cpp54
3 files changed, 59 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index bb243e52..b5ce7010 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -18409,13 +18409,18 @@ namespace BinaryNinja::Collaboration
Ref<Snapshot> GetFirstSnapshot();
Ref<Snapshot> GetSecondSnapshot();
- std::any GetPathItem(const std::string& path);
+ template<typename T> T GetPathItem(const std::string& key);
bool Success(std::nullopt_t value);
bool Success(std::optional<const nlohmann::json*> value);
bool Success(const std::optional<nlohmann::json>& value);
};
+ template<> std::any AnalysisMergeConflict::GetPathItem<std::any>(const std::string& path);
+ template<> std::string AnalysisMergeConflict::GetPathItem<std::string>(const std::string& path);
+ template<> uint64_t AnalysisMergeConflict::GetPathItem<uint64_t>(const std::string& path);
+ template<> nlohmann::json AnalysisMergeConflict::GetPathItem<nlohmann::json>(const std::string& path);
+
class TypeArchiveMergeConflict : public CoreRefCountObject<BNTypeArchiveMergeConflict, BNNewTypeArchiveMergeConflictReference, BNFreeTypeArchiveMergeConflict>
{
public:
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 77471530..d9636c02 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -7490,6 +7490,7 @@ extern "C"
BINARYNINJACOREAPI BNSnapshot* BNAnalysisMergeConflictGetBaseSnapshot(BNAnalysisMergeConflict* conflict);
BINARYNINJACOREAPI BNSnapshot* BNAnalysisMergeConflictGetFirstSnapshot(BNAnalysisMergeConflict* conflict);
BINARYNINJACOREAPI BNSnapshot* BNAnalysisMergeConflictGetSecondSnapshot(BNAnalysisMergeConflict* conflict);
+ BINARYNINJACOREAPI char* BNAnalysisMergeConflictGetPathItemString(BNAnalysisMergeConflict* conflict, const char* path);
BINARYNINJACOREAPI void* BNAnalysisMergeConflictGetPathItem(BNAnalysisMergeConflict* conflict, const char* path);
BINARYNINJACOREAPI bool BNAnalysisMergeConflictSuccess(BNAnalysisMergeConflict* conflict, const char* value);
diff --git a/collaboration.cpp b/collaboration.cpp
index 7b0057c3..b4f7d659 100644
--- a/collaboration.cpp
+++ b/collaboration.cpp
@@ -2101,15 +2101,65 @@ Ref<Snapshot> AnalysisMergeConflict::GetSecondSnapshot()
}
-std::any AnalysisMergeConflict::GetPathItem(const std::string& path)
+template <>
+std::any AnalysisMergeConflict::GetPathItem<std::any>(const std::string& path)
{
void* val = BNAnalysisMergeConflictGetPathItem(m_object, path.c_str());
if (val == nullptr)
- return {};
+ throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path));
return *(std::any*)val;
}
+template <>
+uint64_t AnalysisMergeConflict::GetPathItem<uint64_t>(const std::string& path)
+{
+ std::any anyVal = GetPathItem<std::any>(path);
+ try
+ {
+ return std::any_cast<uint64_t>(anyVal);
+ }
+ catch (const std::exception& e)
+ {
+ throw SyncException(fmt::format(
+ "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}",
+ path, anyVal.type().name(), typeid(uint64_t).name(), e.what()
+ ));
+ }
+}
+
+
+template <>
+std::string AnalysisMergeConflict::GetPathItem<std::string>(const std::string& path)
+{
+ char* val = BNAnalysisMergeConflictGetPathItemString(m_object, path.c_str());
+ if (val == nullptr)
+ throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path));
+
+ std::string strVal = val;
+ BNFreeString(val);
+ return strVal;
+}
+
+
+template <>
+nlohmann::json AnalysisMergeConflict::GetPathItem<nlohmann::json>(const std::string& path)
+{
+ std::any anyVal = GetPathItem<std::any>(path);
+ try
+ {
+ return std::any_cast<nlohmann::json>(anyVal);
+ }
+ catch (const std::exception& e)
+ {
+ throw SyncException(fmt::format(
+ "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}",
+ path, anyVal.type().name(), typeid(nlohmann::json).name(), e.what()
+ ));
+ }
+}
+
+
bool AnalysisMergeConflict::Success(std::nullopt_t value)
{
return BNAnalysisMergeConflictSuccess(m_object, nullptr);