diff options
| author | Mark Rowe <mark@vector35.com> | 2025-08-11 15:45:38 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-08-20 13:06:33 -0400 |
| commit | ff72f3be107e94a0be41a1e7ba113000a4e95089 (patch) | |
| tree | 1dec15cea9d5b8e5609b1006638fc5cea2eda974 | |
| parent | e15b6e8789bd791a201bdac031561dddb59a99e4 (diff) | |
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`.
| -rw-r--r-- | binaryninjaapi.h | 38 | ||||
| -rw-r--r-- | binaryninjacore.h | 7 | ||||
| -rw-r--r-- | examples/workflows/inliner/inliner.cpp | 2 | ||||
| -rw-r--r-- | examples/workflows/tailcall/tailcall.cpp | 2 | ||||
| -rw-r--r-- | examples/workflows/unflatten/library.cpp | 2 | ||||
| -rw-r--r-- | plugins/efi_resolver/src/Plugin.cpp | 2 | ||||
| -rw-r--r-- | plugins/rtti/plugin.cpp | 2 | ||||
| -rw-r--r-- | plugins/workflow_objc/Workflow.cpp | 2 | ||||
| -rw-r--r-- | python/workflow.py | 4 | ||||
| -rw-r--r-- | rust/src/workflow.rs | 3 | ||||
| -rw-r--r-- | view/sharedcache/workflow/SharedCacheWorkflow.cpp | 2 | ||||
| -rw-r--r-- | workflow.cpp | 14 |
12 files changed, 60 insertions, 20 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 93117eb8..589556f1 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -11307,13 +11307,43 @@ namespace BinaryNinja { */ static std::vector<Ref<Workflow>> GetList(); - /*! Get an instance of a workflow by name. If it is already registered, this will return the registered Workflow. - If not, it will create and return a new Workflow. + /*! Get an instance of an existing registered workflow by name. + If no registered workflow exists, nullptr will be returned. + + \note Be sure to handle the nullptr case if you're retrieving + anything other than a built-in workflow. \param name Workflow name - \return The registered workflow. + \return The registered workflow, or nullptr if none exists. */ - static Ref<Workflow> Instance(const std::string& name = ""); + static Ref<Workflow> Get(const std::string& name); + + /*! Get an instance of a workflow by name. If it is already registered, + this will return the registered Workflow. If not, a new Workflow will + be created and returned. + + \note If a new workflow is returned it will have no activities. Attempting + to register new activities on it via `Insert` and `InsertAfter` will fail. + + \param name Workflow name + \return The workflow. + */ + static Ref<Workflow> GetOrCreate(const std::string& name); + + /*! Get an instance of a workflow by name. If it is already registered, + this will return the registered Workflow. If not, a new Workflow will + be created and returned. + + \deprecated Use `Get` or `GetOrCreate` instead. + + \note If a new workflow is returned it will have no activities. Attempting + to register new activities on it via `Insert` and `InsertAfter` will fail. + + \param name Workflow name + \return The workflow. + */ + static Ref<Workflow> Instance(const std::string& name = "") { return GetOrCreate(name); } + /*! Register a workflow, making it immutable and available for use \param workflow The workflow to register diff --git a/binaryninjacore.h b/binaryninjacore.h index 47f47905..e278b446 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -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 129 +#define BN_CURRENT_CORE_ABI_VERSION 130 // 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 128 +#define BN_MINIMUM_CORE_ABI_VERSION 130 #ifdef __GNUC__ #ifdef BINARYNINJACORE_LIBRARY @@ -5757,7 +5757,8 @@ extern "C" BINARYNINJACOREAPI BNWorkflow** BNGetWorkflowList(size_t* count); BINARYNINJACOREAPI void BNFreeWorkflowList(BNWorkflow** workflows, size_t count); - BINARYNINJACOREAPI BNWorkflow* BNWorkflowInstance(const char* name); + BINARYNINJACOREAPI BNWorkflow* BNWorkflowGet(const char* name); + BINARYNINJACOREAPI BNWorkflow* BNWorkflowGetOrCreate(const char* name); BINARYNINJACOREAPI bool BNRegisterWorkflow(BNWorkflow* workflow, const char* configuration); BINARYNINJACOREAPI BNWorkflow* BNWorkflowClone(BNWorkflow* workflow, const char* name, const char* activity); diff --git a/examples/workflows/inliner/inliner.cpp b/examples/workflows/inliner/inliner.cpp index 7db6efec..882a23f0 100644 --- a/examples/workflows/inliner/inliner.cpp +++ b/examples/workflows/inliner/inliner.cpp @@ -158,7 +158,7 @@ extern "C" }, inlinerIsValid); - Ref<Workflow> inlinerWorkflow = Workflow::Instance("core.function.baseAnalysis")->Clone("InlinerWorkflow"); + Ref<Workflow> inlinerWorkflow = Workflow::Get("core.function.baseAnalysis")->Clone("InlinerWorkflow"); inlinerWorkflow->RegisterActivity(new Activity("extension.functionInliner", &FunctionInliner)); inlinerWorkflow->Insert("core.function.translateTailCalls", "extension.functionInliner"); Workflow::RegisterWorkflow(inlinerWorkflow, diff --git a/examples/workflows/tailcall/tailcall.cpp b/examples/workflows/tailcall/tailcall.cpp index 0fed369d..4282764d 100644 --- a/examples/workflows/tailcall/tailcall.cpp +++ b/examples/workflows/tailcall/tailcall.cpp @@ -117,7 +117,7 @@ extern "C" BINARYNINJAPLUGIN bool CorePluginInit() { - Ref<Workflow> customTailCallWorkflow = Workflow::Instance("core.function.baseAnalysis")->Clone("CustomTailCallWorkflow"); + Ref<Workflow> customTailCallWorkflow = Workflow::Get("core.function.baseAnalysis")->Clone("CustomTailCallWorkflow"); customTailCallWorkflow->RegisterActivity(new Activity("extension.translateTailCalls", &TailCallTranslation)); customTailCallWorkflow->Replace("core.function.translateTailCalls", "extension.translateTailCalls"); customTailCallWorkflow->Remove("core.function.translateTailCalls"); diff --git a/examples/workflows/unflatten/library.cpp b/examples/workflows/unflatten/library.cpp index cb4e9b9a..4cd899ed 100644 --- a/examples/workflows/unflatten/library.cpp +++ b/examples/workflows/unflatten/library.cpp @@ -411,7 +411,7 @@ extern "C" BINARYNINJAPLUGIN bool CorePluginInit() { - auto wf = Workflow::Instance("core.function.metaAnalysis")->Clone("core.function.metaAnalysis"); + auto wf = Workflow::Get("core.function.metaAnalysis")->Clone("core.function.metaAnalysis"); wf->RegisterActivity(new Activity(R"~( { "name": "extension.unflatten_limoncello_cpp.unflatten.dry_run", diff --git a/plugins/efi_resolver/src/Plugin.cpp b/plugins/efi_resolver/src/Plugin.cpp index e26ec171..2f43c4f3 100644 --- a/plugins/efi_resolver/src/Plugin.cpp +++ b/plugins/efi_resolver/src/Plugin.cpp @@ -61,7 +61,7 @@ extern "C" BINARYNINJAPLUGIN bool CorePluginInit() { EfiGuidRenderer::Register(); - auto workflow = Workflow::Instance("core.module.metaAnalysis")->Clone(); + auto workflow = Workflow::Get("core.module.metaAnalysis")->Clone(); workflow->RegisterActivity(R"~({ "title": "EFI Resolver", "name": "analysis.efi.efiResolver", diff --git a/plugins/rtti/plugin.cpp b/plugins/rtti/plugin.cpp index 6f1a3e2f..721a4418 100644 --- a/plugins/rtti/plugin.cpp +++ b/plugins/rtti/plugin.cpp @@ -91,7 +91,7 @@ extern "C" { // TODO: 2. Identify if the function is unique to a class, renaming and retyping if true // TODO: 3. Identify functions which address a VFT and are probably a constructor (alloc use), retyping if true // TODO: 4. Identify functions which address a VFT and are probably a deconstructor (free use), retyping if true - Ref<Workflow> rttiMetaWorkflow = Workflow::Instance("core.module.metaAnalysis")->Clone(); + Ref<Workflow> rttiMetaWorkflow = Workflow::Get("core.module.metaAnalysis")->Clone(); // Add RTTI analysis. rttiMetaWorkflow->RegisterActivity(R"~({ diff --git a/plugins/workflow_objc/Workflow.cpp b/plugins/workflow_objc/Workflow.cpp index e0986943..fb65f29a 100644 --- a/plugins/workflow_objc/Workflow.cpp +++ b/plugins/workflow_objc/Workflow.cpp @@ -307,7 +307,7 @@ static constexpr auto WorkflowInfo = R"({ void Workflow::registerActivities() { - const auto wf = BinaryNinja::Workflow::Instance("core.function.baseAnalysis")->Clone("core.function.objectiveC"); + const auto wf = BinaryNinja::Workflow::Get("core.function.baseAnalysis")->Clone("core.function.objectiveC"); wf->RegisterActivity(new BinaryNinja::Activity( ActivityID::ResolveMethodCalls, &Workflow::inlineMethodCalls)); wf->InsertAfter("core.function.translateTailCalls", ActivityID::ResolveMethodCalls); diff --git a/python/workflow.py b/python/workflow.py index 4db530f8..901a7cf9 100644 --- a/python/workflow.py +++ b/python/workflow.py @@ -288,7 +288,7 @@ class _WorkflowMetaclass(type): def __getitem__(self, value): binaryninja._init_plugins() - workflow = core.BNWorkflowInstance(str(value)) + workflow = core.BNWorkflowGetOrCreate(str(value)) return Workflow(handle=workflow) @@ -344,7 +344,7 @@ class Workflow(metaclass=_WorkflowMetaclass): def __init__(self, name: str = "", handle: core.BNWorkflowHandle = None, query_registry: bool = True, object_handle: Union[core.BNFunctionHandle, core.BNBinaryViewHandle] = None): if handle is None: if query_registry: - _handle = core.BNWorkflowInstance(str(name)) + _handle = core.BNWorkflowGetOrCreate(str(name)) else: _handle = core.BNCreateWorkflow(name) else: diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs index 2c03a482..49c5760e 100644 --- a/rust/src/workflow.rs +++ b/rust/src/workflow.rs @@ -204,9 +204,8 @@ impl Workflow { /// Get an existing [Workflow] by name. pub fn get(name: &str) -> Option<Ref<Workflow>> { - // TODO: BNWorkflowInstance has get-or-create semantics. There is currently no way to just get. let name = name.to_cstr(); - let result = unsafe { BNWorkflowInstance(name.as_ptr()) }; + let result = unsafe { BNWorkflowGet(name.as_ptr()) }; let handle = NonNull::new(result)?; Some(unsafe { Workflow::ref_from_raw(handle) }) } diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp index 3fce2e39..3844516f 100644 --- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp +++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp @@ -370,7 +370,7 @@ void AnalyzeFunction(Ref<AnalysisContext> ctx) void SharedCacheWorkflow::Register() { - Ref<Workflow> workflow = Workflow::Instance("core.function.metaAnalysis")->Clone("core.function.metaAnalysis"); + Ref<Workflow> workflow = Workflow::Get("core.function.metaAnalysis")->Clone("core.function.metaAnalysis"); // Register and insert activities here. ObjCActivity::Register(*workflow); diff --git a/workflow.cpp b/workflow.cpp index 13c180a5..3b0366db 100644 --- a/workflow.cpp +++ b/workflow.cpp @@ -454,9 +454,19 @@ vector<Ref<Workflow>> Workflow::GetList() } -Ref<Workflow> Workflow::Instance(const string& name) +Ref<Workflow> Workflow::Get(const string& name) { - return new Workflow(BNWorkflowInstance(name.c_str())); + auto result = BNWorkflowGet(name.c_str()); + if (!result) + return nullptr; + + return new Workflow(result); +} + + +Ref<Workflow> Workflow::GetOrCreate(const string& name) +{ + return new Workflow(BNWorkflowGetOrCreate(name.c_str())); } |
