From ede39aee7e00c40a43b67ca18dd8ab80ee863d85 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 26 Aug 2025 23:59:38 -0400 Subject: [WARP] Enhanced network support --- plugins/warp/api/warp.h | 96 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 16 deletions(-) (limited to 'plugins/warp/api/warp.h') diff --git a/plugins/warp/api/warp.h b/plugins/warp/api/warp.h index 807ba998..14be9a0d 100644 --- a/plugins/warp/api/warp.h +++ b/plugins/warp/api/warp.h @@ -68,7 +68,7 @@ namespace Warp { { T *m_obj; #ifdef BN_REF_COUNT_DEBUG - void* m_assignmentTrace = nullptr; + void *m_assignmentTrace = nullptr; #endif public: @@ -230,8 +230,12 @@ namespace Warp { public: WarpUUID() = default; - - WarpUUID(BNWARPUUID uuid) : uuid(uuid) {} + + WarpUUID(BNWARPUUID uuid) : uuid(uuid) + { + } + + static std::optional FromString(const std::string &str); std::string ToString() const; @@ -245,12 +249,12 @@ namespace Warp { return !(*this == other); } - BNWARPUUID* RawMut() + BNWARPUUID *RawMut() { return &uuid; } - const BNWARPUUID* Raw() const + const BNWARPUUID *Raw() const { return &uuid; } @@ -261,6 +265,7 @@ namespace Warp { typedef WarpUUID FunctionGUID; typedef WarpUUID ConstraintGUID; typedef WarpUUID TypeGUID; + typedef std::string SourceTag; class Target : public WarpRefCountObject @@ -268,9 +273,9 @@ namespace Warp { public: explicit Target(BNWARPTarget *target); - static Ref FromPlatform(const BinaryNinja::Platform& platform); + static Ref FromPlatform(const BinaryNinja::Platform &platform); }; - + struct Constraint { ConstraintGUID guid; @@ -278,7 +283,7 @@ namespace Warp { Constraint(ConstraintGUID guid, std::optional offset); - static Constraint FromAPIObject(BNWARPConstraint* constraint); + static Constraint FromAPIObject(BNWARPConstraint *constraint); }; struct FunctionComment @@ -288,7 +293,7 @@ namespace Warp { FunctionComment(std::string text, int64_t offset); - static FunctionComment FromAPIObject(BNWARPFunctionComment* comment); + static FunctionComment FromAPIObject(BNWARPFunctionComment *comment); }; class Function : public WarpRefCountObject @@ -322,6 +327,51 @@ namespace Warp { static void RemoveMatch(const BinaryNinja::Function &function); }; + class ContainerSearchQuery : public WarpRefCountObject + { + public: + explicit ContainerSearchQuery(BNWARPContainerSearchQuery *query); + + explicit ContainerSearchQuery(const std::string &query); + + ContainerSearchQuery(const std::string &query, const Source &source); + + ContainerSearchQuery(const std::string &query, size_t offset, size_t limit, + const std::optional &source = std::nullopt, + const std::vector &tags = {}); + }; + + class ContainerSearchItem : public WarpRefCountObject + { + public: + explicit ContainerSearchItem(BNWARPContainerSearchItem *item); + + BNWARPContainerSearchItemKind GetKind() const; + + Source GetSource() const; + + BinaryNinja::Ref GetType(const BinaryNinja::Ref &arch) const; + + std::string GetName() const; + + Ref GetFunction() const; + }; + + struct ContainerSearchResponse + { + std::vector > items; + size_t offset; + size_t total; + + ContainerSearchResponse(std::vector > &&items, size_t offset, size_t total); + + static ContainerSearchResponse FromAPIObject(BNWARPContainerSearchResponse *response); + }; + class Container : public WarpRefCountObject { @@ -345,36 +395,50 @@ namespace Warp { std::optional SourcePath(const Source &source) const; - bool AddFunctions(const Target &target, const Source &source, const std::vector > &functions) const; + bool AddFunctions(const Target &target, const Source &source, + const std::vector > &functions) const; bool AddTypes(const BinaryNinja::BinaryView &view, const Source &source, const std::vector > &types) const; - bool RemoveFunctions(const Target &target, const Source &source, const std::vector > &functions) const; + bool RemoveFunctions(const Target &target, const Source &source, + const std::vector > &functions) const; bool RemoveTypes(const Source &source, const std::vector &guids) const; - void FetchFunctions(const Target& target, const std::vector &guids) const; + void FetchFunctions(const Target &target, const std::vector &guids, const std::vector &tags = {}) const; - std::vector GetSourcesWithFunctionGUID(const Target& target, const FunctionGUID &guid) const; + std::vector GetSourcesWithFunctionGUID(const Target &target, const FunctionGUID &guid) const; std::vector GetSourcesWithTypeGUID(const TypeGUID &guid) const; - std::vector > GetFunctionsWithGUID(const Target& target, const Source &source, const FunctionGUID &guid) const; + std::vector > GetFunctionsWithGUID(const Target &target, const Source &source, + const FunctionGUID &guid) const; BinaryNinja::Ref GetTypeWithGUID(const BinaryNinja::Architecture &arch, const Source &source, const TypeGUID &guid) const; std::vector GetTypeGUIDsWithName(const Source &source, const std::string &name) const; + + std::optional Search(const ContainerSearchQuery &query) const; }; - void RunMatcher(const BinaryNinja::BinaryView& view); + void RunMatcher(const BinaryNinja::BinaryView &view); bool IsInstructionVariant(const BinaryNinja::LowLevelILFunction &function, BinaryNinja::ExprId idx); bool IsInstructionBlacklisted(const BinaryNinja::LowLevelILFunction &function, BinaryNinja::ExprId idx); - + std::optional GetAnalysisFunctionGUID(const BinaryNinja::Function &function); std::optional GetBasicBlockGUID(const BinaryNinja::BasicBlock &basicBlock); } + +template<> struct std::hash +{ + size_t operator()(Warp::WarpUUID const& item) const noexcept + { + // TODO: Use the raw bytes instead. + return std::hash()(item.ToString()); + } +}; \ No newline at end of file -- cgit v1.3.1