summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2025-03-21 11:00:15 -0400
committerBrian Potchik <brian@vector35.com>2025-03-21 11:00:15 -0400
commitf9b8762d49ef16bf2dd7b814d6f1ef06594b2951 (patch)
tree1b6182e93d9560cc710ec82829edda7b00df8c54
parent4bb16e8329cd13efa76ecbf79e03525cf19e7b62 (diff)
Add some workflow machine control commands to the C++ API.
-rw-r--r--binaryninjaapi.h36
-rw-r--r--workflow.cpp73
2 files changed, 91 insertions, 18 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 5fc2f5a6..c83e8ee8 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -10077,10 +10077,33 @@ namespace BinaryNinja {
Ref<BinaryView> m_view;
Ref<Function> m_function;
+ bool PostRequest(const std::string& command);
+
public:
WorkflowMachine(Ref<BinaryView> view);
WorkflowMachine(Ref<Function> function);
+ /*! Start the workflow WorkflowMachine
+ Starts the workflow machine for the given BinaryView or Function.
+ \return true if the command is accepted, false otherwise.
+ */
+ bool Run();
+
+ /*! Halt the workflow machine
+
+ Halts analysis at a resumable point.
+ \return true if the command is accepted, false otherwise.
+ */
+ bool Halt();
+
+ /*! Reset the workflow machine
+
+ Resets the workflow machine to its initial state.
+ \return true if the command is accepted, false otherwise.
+ */
+ bool Reset();
+
+
/*! Enable the workflow machine
Re-enables the workflow machine if it is in the Suspend state.
@@ -10096,6 +10119,19 @@ namespace BinaryNinja {
*/
bool Disable();
+ /*! Step the workflow machine
+
+ Steps the workflow machine through a single activity.
+ \return true if the command is accepted, false otherwise.
+ */
+ bool Step();
+
+ /*! Get the current state of the workflow machine
+
+ Returns the current state of the workflow machine.
+ \return The current state of the workflow machine
+ */
+ std::string GetState();
std::optional<bool> QueryOverride(const std::string& activity);
bool SetOverride(const std::string& activity, bool enable);
diff --git a/workflow.cpp b/workflow.cpp
index 63066baa..9edb6ea6 100644
--- a/workflow.cpp
+++ b/workflow.cpp
@@ -110,23 +110,12 @@ bool AnalysisContext::Inform(const string& request)
}
-WorkflowMachine::WorkflowMachine(Ref<BinaryView> view): m_view(view)
-{
-
-}
-
-
-WorkflowMachine::WorkflowMachine(Ref<Function> function): m_function(function)
-{
-
-}
-
-
-bool WorkflowMachine::Enable()
+bool WorkflowMachine::PostRequest(const std::string& command)
{
rapidjson::Document request(rapidjson::kObjectType);
rapidjson::Document::AllocatorType& allocator = request.GetAllocator();
- request.AddMember("command", "enable", allocator);
+ rapidjson::Value commandValue(command.c_str(), command.size(), allocator);
+ request.AddMember("command", commandValue, allocator);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
request.Accept(writer);
@@ -146,11 +135,59 @@ bool WorkflowMachine::Enable()
}
+WorkflowMachine::WorkflowMachine(Ref<BinaryView> view): m_view(view)
+{
+
+}
+
+
+WorkflowMachine::WorkflowMachine(Ref<Function> function): m_function(function)
+{
+
+}
+
+
+bool WorkflowMachine::Run()
+{
+ return PostRequest("run");
+}
+
+
+bool WorkflowMachine::Halt()
+{
+ return PostRequest("halt");
+}
+
+
+bool WorkflowMachine::Reset()
+{
+ return PostRequest("reset");
+}
+
+
+bool WorkflowMachine::Enable()
+{
+ return PostRequest("enable");
+}
+
+
bool WorkflowMachine::Disable()
{
+ return PostRequest("disable");
+}
+
+
+bool WorkflowMachine::Step()
+{
+ return PostRequest("step");
+}
+
+
+string WorkflowMachine::GetState()
+{
rapidjson::Document request(rapidjson::kObjectType);
rapidjson::Document::AllocatorType& allocator = request.GetAllocator();
- request.AddMember("command", "disable", allocator);
+ request.AddMember("command", "status", allocator);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
request.Accept(writer);
@@ -163,10 +200,10 @@ bool WorkflowMachine::Disable()
rapidjson::Document response(rapidjson::kObjectType);
response.Parse(jsonResult.c_str());
- if (response.HasMember("commandStatus") && response["commandStatus"].HasMember("accepted"))
- return response["commandStatus"]["accepted"].GetBool();
+ if (response.HasMember("machineState") && response["machineState"].HasMember("state"))
+ return response["machineState"]["state"].GetString();
- return false;
+ return "Invalid";
}