summaryrefslogtreecommitdiff
path: root/plugins/warp/api/warp.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-01-31 12:59:42 -0500
committerMason Reed <mason@vector35.com>2025-07-02 01:58:31 -0400
commit110c06851bbbd09f78a3e87979d529d6e09df851 (patch)
tree7849015b26a14cd2b7be2d87fc1e0d5c101ef457 /plugins/warp/api/warp.cpp
parent7b1e8bbdb971aed21b6d889aa4a46f9ef54829c1 (diff)
WARP 1.0
- Added FFI - Added a sidebar to the UI - Added project, directory and archive processing - Added generic `Container` interface for extensible stores of WARP data - Fixed type references being constructed and pulled incorrectly - Added HTML, Markdown and JSON report generation - Made the WARP information added as an analysis activity - Flattened the signatures directory, the target information is stored in the file now - Matched function information is stored as function metadata in the database to reliably persist, alongside the function GUID - Split the matching out from the application, allowing you to match on a given function without applying it - Added more/better tests - Added support for binaries with multiple architectures, the functions are now also queried based off the Target, see WARP spec for more details - Greatly improved support for RISC architectures, see WARP spec for more details - Greatly improved UX when loading files after the fact, will now sanely rerun the matcher - Omitted the function type if not a user type, this greatly reduces file size - Improved support for functions that reference a page aligned base pointer, see WARP spec for more details - Removed some extra cache structures that were causing erroneous behavior - Fixed edge-case in LLIL traversal missing some constant pointers, this was a bug in the Rust bindings - Added support for function comments - Made long running tasks, such as generating, matching and loading signatures, cancellable where possible - Made function constraints more versatile, allowing for easy extensions in the future, see WARP spec for details - Added options to signature generation, such as what data to store, and whether to compress the data or not - Made all long running tasks prompt the user for required information before the task starts, allowing users to "set it and forget it" and not have to baby sit the finalization of the task - Myriad of other changes to the actual WARP format that impact performance, file size and general feature set, see https://github.com/Vector35/warp for more details
Diffstat (limited to 'plugins/warp/api/warp.cpp')
-rw-r--r--plugins/warp/api/warp.cpp336
1 files changed, 336 insertions, 0 deletions
diff --git a/plugins/warp/api/warp.cpp b/plugins/warp/api/warp.cpp
new file mode 100644
index 00000000..7d91c6e2
--- /dev/null
+++ b/plugins/warp/api/warp.cpp
@@ -0,0 +1,336 @@
+#include "warpcore.h"
+#include "warp.h"
+
+#include <utility>
+
+using namespace Warp;
+
+std::string WarpUUID::ToString() const
+{
+ char *str = BNWARPUUIDGetString(&uuid);
+ std::string result = str;
+ BNFreeString(str);
+ return result;
+}
+
+Target::Target(BNWARPTarget *target)
+{
+ m_object = target;
+}
+
+Ref<Target> Target::FromPlatform(const BinaryNinja::Platform &platform)
+{
+ BNWARPTarget *result = BNWARPGetTarget(platform.m_object);
+ if (!result)
+ return nullptr;
+ return new Target(result);
+}
+
+Constraint::Constraint(ConstraintGUID guid, std::optional<int64_t> offset)
+{
+ this->guid = guid;
+ this->offset = offset;
+}
+
+Constraint Constraint::FromAPIObject(BNWARPConstraint *constraint)
+{
+ auto offset = constraint->offset == INT64_MAX ? std::nullopt : std::optional(constraint->offset);
+ return {constraint->guid, offset};
+}
+
+FunctionComment::FunctionComment(std::string text, int64_t offset)
+{
+ this->text = std::move(text);
+ this->offset = offset;
+}
+
+FunctionComment FunctionComment::FromAPIObject(BNWARPFunctionComment *comment)
+{
+ return {comment->text, comment->offset};
+}
+
+Function::Function(BNWARPFunction *function)
+{
+ m_object = function;
+}
+
+FunctionGUID Function::GetGUID() const
+{
+ return BNWARPFunctionGetGUID(m_object);
+}
+
+std::string Function::GetSymbolName() const
+{
+ char *name = BNWARPFunctionGetSymbolName(m_object);
+ std::string result = name;
+ BNFreeString(name);
+ return result;
+}
+
+BinaryNinja::Ref<BinaryNinja::Symbol> Function::GetSymbol(const BinaryNinja::Function &function) const
+{
+ BNSymbol *symbol = BNWARPFunctionGetSymbol(m_object, function.m_object);
+ if (!symbol)
+ return nullptr;
+ return new BinaryNinja::Symbol(symbol);
+}
+
+BinaryNinja::Ref<BinaryNinja::Type> Function::GetType(const BinaryNinja::Function &function) const
+{
+ BNType *type = BNWARPFunctionGetType(m_object, function.m_object);
+ if (!type)
+ return nullptr;
+ return new BinaryNinja::Type(type);
+}
+
+std::vector<Constraint> Function::GetConstraints() const
+{
+ size_t count;
+ BNWARPConstraint *constraints = BNWARPFunctionGetConstraints(m_object, &count);
+ std::vector<Constraint> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.push_back(Constraint::FromAPIObject(&constraints[i]));
+ BNWARPFreeConstraintList(constraints, count);
+ return result;
+}
+
+std::vector<FunctionComment> Function::GetComments() const
+{
+ size_t count;
+ BNWARPFunctionComment *comments = BNWARPFunctionGetComments(m_object, &count);
+ std::vector<FunctionComment> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.push_back(FunctionComment::FromAPIObject(&comments[i]));
+ BNWARPFreeFunctionCommentList(comments, count);
+ return result;
+}
+
+Ref<Function> Function::Get(const BinaryNinja::Function &function)
+{
+ BNWARPFunction *result = BNWARPGetFunction(function.m_object);
+ if (!result)
+ return nullptr;
+ return new Function(result);
+}
+
+Ref<Function> Function::GetMatched(const BinaryNinja::Function &function)
+{
+ BNWARPFunction *result = BNWARPGetMatchedFunction(function.m_object);
+ if (!result)
+ return nullptr;
+ return new Function(result);
+}
+
+void Function::Apply(const BinaryNinja::Function &function) const
+{
+ BNWARPFunctionApply(m_object, function.m_object);
+}
+
+void Function::RemoveMatch(const BinaryNinja::Function &function)
+{
+ BNWARPFunctionApply(nullptr, function.m_object);
+}
+
+Container::Container(BNWARPContainer *container)
+{
+ m_object = container;
+}
+
+std::vector<Ref<Container> > Container::All()
+{
+ size_t count;
+ BNWARPContainer **containers = BNWARPGetContainers(&count);
+ std::vector<Ref<Container> > result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.push_back(new Container(BNWARPNewContainerReference(containers[i])));
+ BNWARPFreeContainerList(containers, count);
+ return result;
+}
+
+std::string Container::GetName() const
+{
+ char *rawName = BNWARPContainerGetName(m_object);
+ std::string name = rawName;
+ BNFreeString(rawName);
+ return name;
+}
+
+std::vector<Source> Container::GetSources() const
+{
+ size_t count;
+ BNWARPSource *sources = BNWARPContainerGetSources(m_object, &count);
+ std::vector<Source> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.emplace_back(sources[i]);
+ BNWARPFreeUUIDList(sources, count);
+ return result;
+}
+
+std::optional<Source> Container::AddSource(const std::string &sourcePath) const
+{
+ Source source;
+ if (!BNWARPContainerAddSource(m_object, sourcePath.c_str(), source.RawMut()))
+ return std::nullopt;
+ return source;
+}
+
+bool Container::CommitSource(const Source &source) const
+{
+ return BNWARPContainerCommitSource(m_object, source.Raw());
+}
+
+bool Container::IsSourceUncommitted(const Source &source) const
+{
+ return BNWARPContainerIsSourceUncommitted(m_object, source.Raw());
+}
+
+bool Container::IsSourceWritable(const Source &source) const
+{
+ return BNWARPContainerIsSourceWritable(m_object, source.Raw());
+}
+
+std::optional<std::string> Container::SourcePath(const Source &source) const
+{
+ char *rawPath = BNWARPContainerGetSourcePath(m_object, source.Raw());
+ if (!rawPath)
+ return std::nullopt;
+ std::string path = rawPath;
+ BNFreeString(rawPath);
+ return path;
+}
+
+bool Container::AddFunctions(const Target &target, const Source &source, const std::vector<Ref<Function> > &functions) const
+{
+ size_t count = functions.size();
+ BNWARPFunction **apiFunctions = new BNWARPFunction *[count];
+ for (size_t i = 0; i < count; i++)
+ apiFunctions[i] = functions[i]->m_object;
+ const bool result = BNWARPContainerAddFunctions(m_object, target.m_object, source.Raw(), apiFunctions, count);
+ delete[] apiFunctions;
+ return result;
+}
+
+bool Container::AddTypes(const BinaryNinja::BinaryView &view, const Source &source,
+ const std::vector<BinaryNinja::Ref<BinaryNinja::Type> > &types) const
+{
+ size_t count = types.size();
+ BNType **apiTypes = new BNType *[count];
+ for (size_t i = 0; i < count; i++)
+ apiTypes[i] = types[i]->m_object;
+ const bool result = BNWARPContainerAddTypes(view.m_object, m_object, source.Raw(), apiTypes, count);
+ delete[] apiTypes;
+ return result;
+}
+
+bool Container::RemoveFunctions(const Target &target, const Source &source,
+ const std::vector<Ref<Function>> &functions) const
+{
+ size_t count = functions.size();
+ BNWARPFunction **apiFunctions = new BNWARPFunction *[count];
+ for (size_t i = 0; i < count; i++)
+ apiFunctions[i] = functions[i]->m_object;
+ const bool result = BNWARPContainerRemoveFunctions(m_object, target.m_object, source.Raw(), apiFunctions, count);
+ delete[] apiFunctions;
+ return result;
+}
+
+bool Container::RemoveTypes(const Source &source, const std::vector<TypeGUID> &guids) const
+{
+ size_t count = guids.size();
+ BNWARPTypeGUID* apiGuids = new BNWARPTypeGUID[count];
+ for (size_t i = 0; i < count; i++)
+ apiGuids[i] = *guids[i].Raw();
+ const bool result = BNWARPContainerRemoveTypes(m_object, source.Raw(), apiGuids, count);
+ delete[] apiGuids;
+ return result;
+}
+
+std::vector<Source> Container::GetSourcesWithFunctionGUID(const Target& target, const FunctionGUID &guid) const
+{
+ size_t count;
+ BNWARPSource *sources = BNWARPContainerGetSourcesWithFunctionGUID(m_object, target.m_object, guid.Raw(), &count);
+ std::vector<Source> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.emplace_back(sources[i]);
+ BNWARPFreeUUIDList(sources, count);
+ return result;
+}
+
+std::vector<Source> Container::GetSourcesWithTypeGUID(const TypeGUID &guid) const
+{
+ size_t count;
+ BNWARPSource *sources = BNWARPContainerGetSourcesWithTypeGUID(m_object, guid.Raw(), &count);
+ std::vector<Source> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.emplace_back(sources[i]);
+ BNWARPFreeUUIDList(sources, count);
+ return result;
+}
+
+std::vector<Ref<Function> > Container::GetFunctionsWithGUID(const Target& target, const Source &source, const FunctionGUID &guid) const
+{
+ size_t count;
+ BNWARPFunction **functions = BNWARPContainerGetFunctionsWithGUID(m_object, target.m_object, source.Raw(), guid.Raw(), &count);
+ std::vector<Ref<Function> > result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.push_back(new Function(BNWARPNewFunctionReference(functions[i])));
+ BNWARPFreeFunctionList(functions, count);
+ return result;
+}
+
+BinaryNinja::Ref<BinaryNinja::Type> Container::GetTypeWithGUID(const BinaryNinja::Architecture &arch,
+ const Source &source, const TypeGUID &guid) const
+{
+ BNType *type = BNWARPContainerGetTypeWithGUID(arch.m_object, m_object, source.Raw(), guid.Raw());
+ return new BinaryNinja::Type(type);
+}
+
+std::vector<TypeGUID> Container::GetTypeGUIDsWithName(const Source &source, const std::string &name) const
+{
+ size_t count;
+ BNWARPTypeGUID *guids = BNWARPContainerGetTypeGUIDsWithName(m_object, source.Raw(), name.c_str(), &count);
+ std::vector<TypeGUID> result;
+ result.reserve(count);
+ for (int i = 0; i < count; i++)
+ result.emplace_back(guids[i]);
+ BNWARPFreeUUIDList(guids, count);
+ return result;
+}
+
+void Warp::RunMatcher(const BinaryNinja::BinaryView &view)
+{
+ BNWARPRunMatcher(view.m_object);
+}
+
+bool IsInstructionVariant(const BinaryNinja::LowLevelILFunction &function, BinaryNinja::ExprId idx)
+{
+ return BNWARPIsLiftedInstructionVariant(function.m_object, idx);
+}
+
+bool IsInstructionBlacklisted(const BinaryNinja::LowLevelILFunction &function, BinaryNinja::ExprId idx)
+{
+ return BNWARPIsLiftedInstructionBlacklisted(function.m_object, idx);
+}
+
+std::optional<FunctionGUID> Warp::GetAnalysisFunctionGUID(const BinaryNinja::Function &function)
+{
+ FunctionGUID guid;
+ if (!BNWARPGetAnalysisFunctionGUID(function.m_object, guid.RawMut()))
+ return std::nullopt;
+ return guid;
+}
+
+std::optional<BasicBlockGUID> Warp::GetBasicBlockGUID(const BinaryNinja::BasicBlock &basicBlock)
+{
+ BasicBlockGUID guid;
+ if (!BNWARPGetBasicBlockGUID(basicBlock.m_object, guid.RawMut()))
+ return std::nullopt;
+ return guid;
+}