Skip to content

Commit 44c8af1

Browse files
committed
Add interim workflow C++ apis for logging.
1 parent 84dc3cb commit 44c8af1

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

binaryninjaapi.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10126,12 +10126,13 @@ namespace BinaryNinja {
1012610126
*/
1012710127
bool Step();
1012810128

10129-
/*! Get the current state of the workflow machine
10130-
10131-
Returns the current state of the workflow machine.
10132-
\return The current state of the workflow machine
10133-
*/
10129+
// TODO: Add new BNWorkflowMachineStatus structure and cooresponding API
10130+
// BNWorkflowMachineStatus GetStatus();
10131+
// TODO remove the following APIs once the above is implemented
1013410132
std::string GetState();
10133+
std::pair<bool, bool> GetLogStatus();
10134+
10135+
bool SetLogEnabled(bool enable, bool global = false);
1013510136

1013610137
std::optional<bool> QueryOverride(const std::string& activity);
1013710138
bool SetOverride(const std::string& activity, bool enable);

ui/uitypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ typedef BinaryNinja::Ref<BinaryNinja::TypeArchive> TypeArchiveRef;
112112
typedef BinaryNinja::Ref<BinaryNinja::TypeLibrary> TypeLibraryRef;
113113
typedef BinaryNinja::Ref<BinaryNinja::WebsocketClient> WebsocketClientRef;
114114
typedef BinaryNinja::Ref<BinaryNinja::WebsocketProvider> WebsocketProviderRef;
115+
typedef BinaryNinja::Ref<BinaryNinja::Workflow> WorkflowRef;
115116
typedef BinaryNinja::Ref<BinaryNinja::RepoPlugin> RepoPluginRef;
116117
typedef BinaryNinja::Ref<BinaryNinja::Repository> RepositoryRef;
117118
typedef BinaryNinja::Ref<BinaryNinja::RepositoryManager> RepositoryManagerRef;

workflow.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,56 @@ string WorkflowMachine::GetState()
207207
}
208208

209209

210+
std::pair<bool, bool> WorkflowMachine::GetLogStatus()
211+
{
212+
rapidjson::Document request(rapidjson::kObjectType);
213+
rapidjson::Document::AllocatorType& allocator = request.GetAllocator();
214+
request.AddMember("command", "status", allocator);
215+
rapidjson::StringBuffer buffer;
216+
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
217+
request.Accept(writer);
218+
219+
string jsonResult;
220+
if (m_function)
221+
jsonResult = BNPostWorkflowRequestForFunction(m_function->GetObject(), buffer.GetString());
222+
else
223+
jsonResult = BNPostWorkflowRequestForBinaryView(m_view->GetObject(), buffer.GetString());
224+
225+
rapidjson::Document response(rapidjson::kObjectType);
226+
response.Parse(jsonResult.c_str());
227+
if (response.HasMember("logStatus") && response["logStatus"].HasMember("local") && response["logStatus"].HasMember("global"))
228+
return {response["logStatus"]["local"].GetBool(), response["logStatus"]["global"].GetBool()};
229+
230+
return {false, false};
231+
}
232+
233+
234+
bool WorkflowMachine::SetLogEnabled(bool enable, bool global)
235+
{
236+
rapidjson::Document request(rapidjson::kObjectType);
237+
rapidjson::Document::AllocatorType& allocator = request.GetAllocator();
238+
request.AddMember("command", "log", allocator);
239+
request.AddMember("enable", enable, allocator);
240+
request.AddMember("global", global, allocator);
241+
rapidjson::StringBuffer buffer;
242+
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
243+
request.Accept(writer);
244+
245+
string jsonResult;
246+
if (m_function)
247+
jsonResult = BNPostWorkflowRequestForFunction(m_function->GetObject(), buffer.GetString());
248+
else
249+
jsonResult = BNPostWorkflowRequestForBinaryView(m_view->GetObject(), buffer.GetString());
250+
251+
rapidjson::Document response(rapidjson::kObjectType);
252+
response.Parse(jsonResult.c_str());
253+
if (response.HasMember("commandStatus") && response["commandStatus"].HasMember("accepted"))
254+
return response["commandStatus"]["accepted"].GetBool();
255+
256+
return false;
257+
}
258+
259+
210260
std::optional<bool> WorkflowMachine::QueryOverride(const string& activity)
211261
{
212262
rapidjson::Document request(rapidjson::kObjectType);

0 commit comments

Comments
 (0)