Skip to content

Commit

Permalink
Core workflows feature update.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpotchik committed Jul 29, 2023
1 parent 8206f95 commit adb8194
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 79 deletions.
4 changes: 2 additions & 2 deletions activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ using namespace BinaryNinja;
using namespace std;


Activity::Activity(const string& name, const std::function<void(Ref<AnalysisContext> analysisContext)>& action) :
Activity::Activity(const string& configuration, const std::function<void(Ref<AnalysisContext> analysisContext)>& action) :
m_action(action)
{
// LogError("API-Side Activity Constructed!");
m_object = BNCreateActivity(name.c_str(), this, Run);
m_object = BNCreateActivity(configuration.c_str(), this, Run);
}


Expand Down
28 changes: 14 additions & 14 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8557,14 +8557,13 @@ namespace BinaryNinja {
...
// Create a clone of the default workflow named "core.function.myWorkflowName"
Ref<Workflow> wf = BinaryNinja::Workflow::Instance()->Clone("core.function.myWorkflowName");
wf->RegisterActivity(new BinaryNinja::Activity(
"core.function.myWorkflowName.resolveMethodCalls", &MyClass::MyActionMethod));
wf->RegisterActivity(new BinaryNinja::Activity("core.function.myWorkflowName.resolveMethodCalls", &MyClass::MyActionMethod));
\endcode

\param name Name of the activity to register
\param configuration a JSON representation of the activity configuration
\param action Workflow action, a function taking a Ref<AnalysisContext> as an argument.
*/
Activity(const std::string& name, const std::function<void(Ref<AnalysisContext>)>& action);
Activity(const std::string& configuration, const std::function<void(Ref<AnalysisContext>)>& action);
Activity(BNActivity* activity);
virtual ~Activity();

Expand Down Expand Up @@ -8628,20 +8627,23 @@ namespace BinaryNinja {
\param description A JSON description of the Activity
\return
*/
bool RegisterActivity(Ref<Activity> activity, const std::string& description = "");
bool RegisterActivity(Ref<Activity> activity, std::initializer_list<const char*> initializer)
{
return RegisterActivity(activity, std::vector<std::string>(initializer.begin(), initializer.end()));
}

/*! Register an Activity with this Workflow

\param configuration a JSON representation of the activity configuration
\param action Workflow action, a function taking a Ref<AnalysisContext> as an argument.
\param subactivities The list of Activities to assign
\return
*/
Ref<Activity> RegisterActivity(const std::string& configuration, const std::function<void(Ref<AnalysisContext>)>& action, const std::vector<std::string>& subactivities = {});

/*! Register an Activity with this Workflow

\param activity The Activity to register
\param subactivities The list of Activities to assign
\param description A JSON description of the Activity
\return
*/
bool RegisterActivity(
Ref<Activity> activity, const std::vector<std::string>& subactivities, const std::string& description = "");
Ref<Activity> RegisterActivity(Ref<Activity> activity, const std::vector<std::string>& subactivities = {});

/*! Determine if an Activity exists in this Workflow

Expand Down Expand Up @@ -8751,8 +8753,6 @@ namespace BinaryNinja {
*/
Ref<FlowGraph> GetGraph(const std::string& activity = "", bool sequential = false);
void ShowReport(const std::string& name);

// bool Run(const std::string& activity, Ref<AnalysisContext> analysisContext);
};

class DisassemblySettings :
Expand Down
26 changes: 7 additions & 19 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 37
#define BN_CURRENT_CORE_ABI_VERSION 38

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
#define BN_MINIMUM_CORE_ABI_VERSION 36
#define BN_MINIMUM_CORE_ABI_VERSION 38

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down Expand Up @@ -2371,16 +2371,6 @@ extern "C"
IncrementalAutoFunctionUpdate
} BNFunctionUpdateType;

typedef enum BNWorkflowState
{
WorkflowInitial,
WorkflowIdle,
WorkflowRun,
WorkflowHalt,
WorkflowHold,
WorkflowInvalid
} BNWorkflowState;

typedef enum BNAnalysisState
{
InitialState,
Expand Down Expand Up @@ -4415,6 +4405,8 @@ extern "C"

BINARYNINJACOREAPI BNWorkflow* BNGetWorkflowForBinaryView(BNBinaryView* view);
BINARYNINJACOREAPI BNWorkflow* BNGetWorkflowForFunction(BNFunction* func);
BINARYNINJACOREAPI char* BNPostWorkflowRequestForFunction(BNFunction* func, const char* request);
BINARYNINJACOREAPI char* BNGetProvenanceString(BNFunction* func);

BINARYNINJACOREAPI BNHighlightColor BNGetInstructionHighlight(
BNFunction* func, BNArchitecture* arch, uint64_t addr);
Expand Down Expand Up @@ -4618,8 +4610,7 @@ extern "C"
BINARYNINJACOREAPI bool BNAnalysisContextInform(BNAnalysisContext* analysisContext, const char* request);

// Activity
BINARYNINJACOREAPI BNActivity* BNCreateActivity(
const char* name, void* ctxt, void (*action)(void*, BNAnalysisContext*));
BINARYNINJACOREAPI BNActivity* BNCreateActivity(const char* configuration, void* ctxt, void (*action)(void*, BNAnalysisContext*));
BINARYNINJACOREAPI BNActivity* BNNewActivityReference(BNActivity* activity);
BINARYNINJACOREAPI void BNFreeActivity(BNActivity* activity);

Expand All @@ -4633,11 +4624,10 @@ extern "C"
BINARYNINJACOREAPI BNWorkflow** BNGetWorkflowList(size_t* count);
BINARYNINJACOREAPI void BNFreeWorkflowList(BNWorkflow** workflows, size_t count);
BINARYNINJACOREAPI BNWorkflow* BNWorkflowInstance(const char* name);
BINARYNINJACOREAPI bool BNRegisterWorkflow(BNWorkflow* workflow, const char* description);
BINARYNINJACOREAPI bool BNRegisterWorkflow(BNWorkflow* workflow, const char* configuration);

BINARYNINJACOREAPI BNWorkflow* BNWorkflowClone(BNWorkflow* workflow, const char* name, const char* activity);
BINARYNINJACOREAPI bool BNWorkflowRegisterActivity(
BNWorkflow* workflow, BNActivity* activity, const char** subactivities, size_t size, const char* description);
BINARYNINJACOREAPI BNActivity* BNWorkflowRegisterActivity(BNWorkflow* workflow, BNActivity* activity, const char** subactivities, size_t size);

BINARYNINJACOREAPI bool BNWorkflowContains(BNWorkflow* workflow, const char* activity);
BINARYNINJACOREAPI char* BNWorkflowGetConfiguration(BNWorkflow* workflow, const char* activity);
Expand All @@ -4661,8 +4651,6 @@ extern "C"
BINARYNINJACOREAPI BNFlowGraph* BNWorkflowGetGraph(BNWorkflow* workflow, const char* activity, bool sequential);
BINARYNINJACOREAPI void BNWorkflowShowReport(BNWorkflow* workflow, const char* name);

// BINARYNINJACOREAPI bool BNWorkflowRun(const char* activity, BNAnalysisContext* analysisContext);

// Disassembly settings
BINARYNINJACOREAPI BNDisassemblySettings* BNCreateDisassemblySettings(void);
BINARYNINJACOREAPI BNDisassemblySettings* BNNewDisassemblySettingsReference(BNDisassemblySettings* settings);
Expand Down
41 changes: 39 additions & 2 deletions docs/dev/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This capability is experimental with no guarantees of API stability or future co
- [Strategies](#strategies)
- [Core Analysis Descriptions](#core-analysis-descriptions)
- [Extended Analysis Descriptions](#extended-analysis-descriptions)
-->
-->

---
# What Is Workflows
Expand Down Expand Up @@ -116,7 +116,44 @@ The Analysis Context provides access to the current analysis hierarchy along wit
---

## State Graph

```plantuml
@startuml
[*] --> Idle
Idle : Pipeline Not Configured
Idle --> Ready: Run/Configure
Idle --> Suspend: Disable
Suspend : Pipeline Disabled
Suspend --> Idle: Enable
Ready : Pipeline Configured
Ready : * Abort --> Idle
Ready --> Ready: Configure
Ready --> Idle: Reset/<Error>
Ready --> Active: Run/Step/Next
Active : Pipeline Executing
Active : Break Conditions <Abort, Halt, Debug Command>
Active --> Wait: <Break Condition>
Active --> Idle: Finish
Active --> Stall: Transfer <Task>
Inactive : Pipeline Execution Paused
Inactive : Debug Commands {Step, Next, Breakpoint}
Inactive : * Abort --> Idle
Inactive --> Active: <Debug Command>
Inactive --> Active: Run
Wait : Waiting for Control
Wait --> Inactive: <Command Complete>
Stall : Waiting for Event
Stall : * Abort --> Idle
Stall --> Active: Run
@enduml
```
## Pipeline

## Task Queue
Expand Down
13 changes: 12 additions & 1 deletion python/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,18 @@ def workflow(self):
handle = core.BNGetWorkflowForFunction(self.handle)
if handle is None:
return None
return workflow.Workflow(handle=handle)
return workflow.Workflow(handle=handle, function_handle=self.handle)

@property
def provenance(self):
"""
``provenance`` returns a string representing the provenance. This portion of the API is under develoment.
Currently the provenance information is undocumented, not persistent, and not saved to a database.
:return: string representation of the provenance
:rtype: str
"""
return core.BNGetProvenanceString(self.handle)

def get_mlil_var_refs(self, var: 'variable.Variable') -> List[ILReferenceSource]:
"""
Expand Down
Loading

0 comments on commit adb8194

Please sign in to comment.