Skip to content

Commit db4aece

Browse files
committed
Deprecate Workflow::Instance in favor of Workflow::Get and Workflow::GetOrCreate
Calls to `Workflow::Instance` that were looking up a built-in workflow name are updated to use `Workflow::Get`. Others use `Workflow::GetOrCreate`.
1 parent 5957643 commit db4aece

File tree

12 files changed

+55
-18
lines changed

12 files changed

+55
-18
lines changed

binaryninjaapi.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11307,13 +11307,40 @@ namespace BinaryNinja {
1130711307
*/
1130811308
static std::vector<Ref<Workflow>> GetList();
1130911309

11310-
/*! Get an instance of a workflow by name. If it is already registered, this will return the registered Workflow.
11311-
If not, it will create and return a new Workflow.
11310+
/*! Get an instance of an existing registered workflow by name.
11311+
If no registered workflow exists, nullptr will be returned.
1131211312

1131311313
\param name Workflow name
1131411314
\return The registered workflow.
1131511315
*/
11316-
static Ref<Workflow> Instance(const std::string& name = "");
11316+
static Ref<Workflow> Get(const std::string& name);
11317+
11318+
/*! Get an instance of a workflow by name. If it is already registered,
11319+
this will return the registered Workflow. If not, a new Workflow will
11320+
be created and returned.
11321+
11322+
\note If a new workflow is returned it will have no activities. Attempting
11323+
to register new activities on it via `Insert` and `InsertAfter` will fail.
11324+
11325+
\param name Workflow name
11326+
\return The workflow.
11327+
*/
11328+
static Ref<Workflow> GetOrCreate(const std::string& name);
11329+
11330+
/*! Get an instance of a workflow by name. If it is already registered,
11331+
this will return the registered Workflow. If not, a new Workflow will
11332+
be created and returned.
11333+
11334+
\deprecated Use `Get` or `GetOrCreate` instead.
11335+
11336+
\note If a new workflow is returned it will have no activities. Attempting
11337+
to register new activities on it via `Insert` and `InsertAfter` will fail.
11338+
11339+
\param name Workflow name
11340+
\return The workflow.
11341+
*/
11342+
static Ref<Workflow> Instance(const std::string& name = "") { return GetOrCreate(name); }
11343+
1131711344
/*! Register a workflow, making it immutable and available for use
1131811345

1131911346
\param workflow The workflow to register

binaryninjacore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 128
47+
#define BN_MINIMUM_CORE_ABI_VERSION 129
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -5757,7 +5757,8 @@ extern "C"
57575757

57585758
BINARYNINJACOREAPI BNWorkflow** BNGetWorkflowList(size_t* count);
57595759
BINARYNINJACOREAPI void BNFreeWorkflowList(BNWorkflow** workflows, size_t count);
5760-
BINARYNINJACOREAPI BNWorkflow* BNWorkflowInstance(const char* name);
5760+
BINARYNINJACOREAPI BNWorkflow* BNWorkflowGet(const char* name);
5761+
BINARYNINJACOREAPI BNWorkflow* BNWorkflowGetOrCreate(const char* name);
57615762
BINARYNINJACOREAPI bool BNRegisterWorkflow(BNWorkflow* workflow, const char* configuration);
57625763

57635764
BINARYNINJACOREAPI BNWorkflow* BNWorkflowClone(BNWorkflow* workflow, const char* name, const char* activity);

examples/workflows/inliner/inliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extern "C"
158158
},
159159
inlinerIsValid);
160160

161-
Ref<Workflow> inlinerWorkflow = Workflow::Instance("core.function.baseAnalysis")->Clone("InlinerWorkflow");
161+
Ref<Workflow> inlinerWorkflow = Workflow::Get("core.function.baseAnalysis")->Clone("InlinerWorkflow");
162162
inlinerWorkflow->RegisterActivity(new Activity("extension.functionInliner", &FunctionInliner));
163163
inlinerWorkflow->Insert("core.function.translateTailCalls", "extension.functionInliner");
164164
Workflow::RegisterWorkflow(inlinerWorkflow,

examples/workflows/tailcall/tailcall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extern "C"
117117

118118
BINARYNINJAPLUGIN bool CorePluginInit()
119119
{
120-
Ref<Workflow> customTailCallWorkflow = Workflow::Instance("core.function.baseAnalysis")->Clone("CustomTailCallWorkflow");
120+
Ref<Workflow> customTailCallWorkflow = Workflow::Get("core.function.baseAnalysis")->Clone("CustomTailCallWorkflow");
121121
customTailCallWorkflow->RegisterActivity(new Activity("extension.translateTailCalls", &TailCallTranslation));
122122
customTailCallWorkflow->Replace("core.function.translateTailCalls", "extension.translateTailCalls");
123123
customTailCallWorkflow->Remove("core.function.translateTailCalls");

examples/workflows/unflatten/library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ extern "C"
411411

412412
BINARYNINJAPLUGIN bool CorePluginInit()
413413
{
414-
auto wf = Workflow::Instance("core.function.metaAnalysis")->Clone("core.function.metaAnalysis");
414+
auto wf = Workflow::Get("core.function.metaAnalysis")->Clone("core.function.metaAnalysis");
415415
wf->RegisterActivity(new Activity(R"~(
416416
{
417417
"name": "extension.unflatten_limoncello_cpp.unflatten.dry_run",

plugins/efi_resolver/src/Plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern "C"
6161
BINARYNINJAPLUGIN bool CorePluginInit()
6262
{
6363
EfiGuidRenderer::Register();
64-
auto workflow = Workflow::Instance("core.module.metaAnalysis")->Clone();
64+
auto workflow = Workflow::Get("core.module.metaAnalysis")->Clone();
6565
workflow->RegisterActivity(R"~({
6666
"title": "EFI Resolver",
6767
"name": "analysis.efi.efiResolver",

plugins/rtti/plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ extern "C" {
9191
// TODO: 2. Identify if the function is unique to a class, renaming and retyping if true
9292
// TODO: 3. Identify functions which address a VFT and are probably a constructor (alloc use), retyping if true
9393
// TODO: 4. Identify functions which address a VFT and are probably a deconstructor (free use), retyping if true
94-
Ref<Workflow> rttiMetaWorkflow = Workflow::Instance("core.module.metaAnalysis")->Clone();
94+
Ref<Workflow> rttiMetaWorkflow = Workflow::Get("core.module.metaAnalysis")->Clone();
9595

9696
// Add RTTI analysis.
9797
rttiMetaWorkflow->RegisterActivity(R"~({

plugins/workflow_objc/Workflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static constexpr auto WorkflowInfo = R"({
307307

308308
void Workflow::registerActivities()
309309
{
310-
const auto wf = BinaryNinja::Workflow::Instance("core.function.baseAnalysis")->Clone("core.function.objectiveC");
310+
const auto wf = BinaryNinja::Workflow::Get("core.function.baseAnalysis")->Clone("core.function.objectiveC");
311311
wf->RegisterActivity(new BinaryNinja::Activity(
312312
ActivityID::ResolveMethodCalls, &Workflow::inlineMethodCalls));
313313
wf->InsertAfter("core.function.translateTailCalls", ActivityID::ResolveMethodCalls);

python/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def __iter__(self):
288288

289289
def __getitem__(self, value):
290290
binaryninja._init_plugins()
291-
workflow = core.BNWorkflowInstance(str(value))
291+
workflow = core.BNWorkflowGetOrCreate(str(value))
292292
return Workflow(handle=workflow)
293293

294294

@@ -344,7 +344,7 @@ class Workflow(metaclass=_WorkflowMetaclass):
344344
def __init__(self, name: str = "", handle: core.BNWorkflowHandle = None, query_registry: bool = True, object_handle: Union[core.BNFunctionHandle, core.BNBinaryViewHandle] = None):
345345
if handle is None:
346346
if query_registry:
347-
_handle = core.BNWorkflowInstance(str(name))
347+
_handle = core.BNWorkflowGetOrCreate(str(name))
348348
else:
349349
_handle = core.BNCreateWorkflow(name)
350350
else:

rust/src/workflow.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ impl Workflow {
204204

205205
/// Get an existing [Workflow] by name.
206206
pub fn get(name: &str) -> Option<Ref<Workflow>> {
207-
// TODO: BNWorkflowInstance has get-or-create semantics. There is currently no way to just get.
208207
let name = name.to_cstr();
209-
let result = unsafe { BNWorkflowInstance(name.as_ptr()) };
208+
let result = unsafe { BNWorkflowGet(name.as_ptr()) };
210209
let handle = NonNull::new(result)?;
211210
Some(unsafe { Workflow::ref_from_raw(handle) })
212211
}

0 commit comments

Comments
 (0)