diff options
| author | Brian Potchik <brian@vector35.com> | 2025-05-28 08:16:45 -0400 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2025-05-28 08:16:45 -0400 |
| commit | b13d50bac18c341b98e6a3002ac9f17f6c8a8df4 (patch) | |
| tree | b097fb768e97a9c9bd049605a162eec5631969d7 /binaryninjaapi.h | |
| parent | d5080db92c4081f15629aade5ac0ae7ce23c32bc (diff) | |
Eliminate jsoncpp usage from the AnalysisContext C++ API object.
Diffstat (limited to 'binaryninjaapi.h')
| -rw-r--r-- | binaryninjaapi.h | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index cba3c874..ca5b630c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -48,6 +48,7 @@ #include "binaryninjacore.h" #include "exceptions.h" #include "json/json.h" +#include "rapidjsonwrapper.h" #include "vendor/nlohmann/json.hpp" #include <fmt/format.h> #include <fmt/ranges.h> @@ -10014,12 +10015,8 @@ namespace BinaryNinja { /*! \ingroup workflow */ - class AnalysisContext : - public CoreRefCountObject<BNAnalysisContext, BNNewAnalysisContextReference, BNFreeAnalysisContext> + class AnalysisContext : public CoreRefCountObject<BNAnalysisContext, BNNewAnalysisContextReference, BNFreeAnalysisContext> { - std::unique_ptr<Json::CharReader> m_reader; - Json::StreamWriterBuilder m_builder; - public: AnalysisContext(BNAnalysisContext* analysisContext); virtual ~AnalysisContext(); @@ -10084,27 +10081,34 @@ namespace BinaryNinja { */ void SetHighLevelILFunction(Ref<HighLevelILFunction> highLevelIL); + bool Inform(const char* request); bool Inform(const std::string& request); -#if ((__cplusplus >= 201403L) || (_MSVC_LANG >= 201703L)) template <typename... Args> bool Inform(Args... args) { - // using T = std::variant<Args...>; // FIXME: remove type duplicates - using T = std::variant<std::string, const char*, uint64_t, Ref<Architecture>>; - std::vector<T> unpackedArgs {args...}; - Json::Value request(Json::arrayValue); - for (auto& arg : unpackedArgs) - std::visit(overload {[&](Ref<Architecture> arch) { request.append(Json::Value(arch->GetName())); }, - [&](uint64_t val) { request.append(Json::Value(val)); }, - [&](auto& val) { - request.append(Json::Value(std::forward<decltype(val)>(val))); - }}, - arg); - - return Inform(Json::writeString(m_builder, request)); + rapidjson::Document request(rapidjson::kArrayType); + rapidjson::Document::AllocatorType& allocator = request.GetAllocator(); + request.Reserve(sizeof...(args), allocator); + ([&] { + using T = std::decay_t<decltype(args)>; + if constexpr (std::is_same_v<T, Ref<Architecture>>) + { + auto archName = args->GetName(); + request.PushBack(rapidjson::Value(archName.c_str(), archName.length(), allocator), allocator); + } + else if constexpr (std::is_same_v<T, std::string>) + request.PushBack(rapidjson::Value(args.c_str(), args.length(), allocator), allocator); + else if constexpr (std::is_same_v<T, const char*>) + request.PushBack(rapidjson::Value(args, allocator), allocator); + else + request.PushBack(rapidjson::Value(args), allocator); + }(), ...); + rapidjson::StringBuffer buffer; + rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); + request.Accept(writer); + return Inform(buffer.GetString()); } -#endif }; /*! |
