|
48 | 48 | #include "binaryninjacore.h" |
49 | 49 | #include "exceptions.h" |
50 | 50 | #include "json/json.h" |
| 51 | +#include "rapidjsonwrapper.h" |
51 | 52 | #include "vendor/nlohmann/json.hpp" |
52 | 53 | #include <fmt/format.h> |
53 | 54 | #include <fmt/ranges.h> |
@@ -10014,12 +10015,8 @@ namespace BinaryNinja { |
10014 | 10015 | /*! |
10015 | 10016 | \ingroup workflow |
10016 | 10017 | */ |
10017 | | - class AnalysisContext : |
10018 | | - public CoreRefCountObject<BNAnalysisContext, BNNewAnalysisContextReference, BNFreeAnalysisContext> |
| 10018 | + class AnalysisContext : public CoreRefCountObject<BNAnalysisContext, BNNewAnalysisContextReference, BNFreeAnalysisContext> |
10019 | 10019 | { |
10020 | | - std::unique_ptr<Json::CharReader> m_reader; |
10021 | | - Json::StreamWriterBuilder m_builder; |
10022 | | - |
10023 | 10020 | public: |
10024 | 10021 | AnalysisContext(BNAnalysisContext* analysisContext); |
10025 | 10022 | virtual ~AnalysisContext(); |
@@ -10084,27 +10081,34 @@ namespace BinaryNinja { |
10084 | 10081 | */ |
10085 | 10082 | void SetHighLevelILFunction(Ref<HighLevelILFunction> highLevelIL); |
10086 | 10083 |
|
| 10084 | + bool Inform(const char* request); |
10087 | 10085 | bool Inform(const std::string& request); |
10088 | 10086 |
|
10089 | | -#if ((__cplusplus >= 201403L) || (_MSVC_LANG >= 201703L)) |
10090 | 10087 | template <typename... Args> |
10091 | 10088 | bool Inform(Args... args) |
10092 | 10089 | { |
10093 | | - // using T = std::variant<Args...>; // FIXME: remove type duplicates |
10094 | | - using T = std::variant<std::string, const char*, uint64_t, Ref<Architecture>>; |
10095 | | - std::vector<T> unpackedArgs {args...}; |
10096 | | - Json::Value request(Json::arrayValue); |
10097 | | - for (auto& arg : unpackedArgs) |
10098 | | - std::visit(overload {[&](Ref<Architecture> arch) { request.append(Json::Value(arch->GetName())); }, |
10099 | | - [&](uint64_t val) { request.append(Json::Value(val)); }, |
10100 | | - [&](auto& val) { |
10101 | | - request.append(Json::Value(std::forward<decltype(val)>(val))); |
10102 | | - }}, |
10103 | | - arg); |
10104 | | - |
10105 | | - return Inform(Json::writeString(m_builder, request)); |
| 10090 | + rapidjson::Document request(rapidjson::kArrayType); |
| 10091 | + rapidjson::Document::AllocatorType& allocator = request.GetAllocator(); |
| 10092 | + request.Reserve(sizeof...(args), allocator); |
| 10093 | + ([&] { |
| 10094 | + using T = std::decay_t<decltype(args)>; |
| 10095 | + if constexpr (std::is_same_v<T, Ref<Architecture>>) |
| 10096 | + { |
| 10097 | + auto archName = args->GetName(); |
| 10098 | + request.PushBack(rapidjson::Value(archName.c_str(), archName.length(), allocator), allocator); |
| 10099 | + } |
| 10100 | + else if constexpr (std::is_same_v<T, std::string>) |
| 10101 | + request.PushBack(rapidjson::Value(args.c_str(), args.length(), allocator), allocator); |
| 10102 | + else if constexpr (std::is_same_v<T, const char*>) |
| 10103 | + request.PushBack(rapidjson::Value(args, allocator), allocator); |
| 10104 | + else |
| 10105 | + request.PushBack(rapidjson::Value(args), allocator); |
| 10106 | + }(), ...); |
| 10107 | + rapidjson::StringBuffer buffer; |
| 10108 | + rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
| 10109 | + request.Accept(writer); |
| 10110 | + return Inform(buffer.GetString()); |
10106 | 10111 | } |
10107 | | -#endif |
10108 | 10112 | }; |
10109 | 10113 |
|
10110 | 10114 | /*! |
|
0 commit comments