@@ -16502,6 +16502,12 @@ namespace BinaryNinja {
1650216502 {
1650316503 BNPluginCommand m_command;
1650416504
16505+ struct RegisteredGlobalCommand
16506+ {
16507+ std::function<void()> action;
16508+ std::function<bool()> isValid;
16509+ };
16510+
1650516511 struct RegisteredDefaultCommand
1650616512 {
1650716513 std::function<void(BinaryView*)> action;
@@ -16568,6 +16574,7 @@ namespace BinaryNinja {
1656816574 std::function<bool(Project*)> isValid;
1656916575 };
1657016576
16577+ static void GlobalPluginCommandActionCallback(void* ctxt);
1657116578 static void DefaultPluginCommandActionCallback(void* ctxt, BNBinaryView* view);
1657216579 static void AddressPluginCommandActionCallback(void* ctxt, BNBinaryView* view, uint64_t addr);
1657316580 static void RangePluginCommandActionCallback(void* ctxt, BNBinaryView* view, uint64_t addr, uint64_t len);
@@ -16586,6 +16593,7 @@ namespace BinaryNinja {
1658616593 void* ctxt, BNBinaryView* view, BNHighLevelILFunction* func, size_t instr);
1658716594 static void ProjectPluginCommandActionCallback(void* ctxt, BNProject* project);
1658816595
16596+ static bool GlobalPluginCommandIsValidCallback(void* ctxt);
1658916597 static bool DefaultPluginCommandIsValidCallback(void* ctxt, BNBinaryView* view);
1659016598 static bool AddressPluginCommandIsValidCallback(void* ctxt, BNBinaryView* view, uint64_t addr);
1659116599 static bool RangePluginCommandIsValidCallback(void* ctxt, BNBinaryView* view, uint64_t addr, uint64_t len);
@@ -16611,9 +16619,74 @@ namespace BinaryNinja {
1661116619
1661216620 PluginCommand& operator=(const PluginCommand& cmd);
1661316621
16622+ /*! Register a command.
16623+
16624+ This will appear in the top menu.
16625+
16626+ \code{.cpp}
16627+
16628+ // Registering a command using a lambda expression
16629+ PluginCommand::RegisterGlobal("MyPlugin\\MyAction", "Perform an action", []() { });
16630+
16631+ // Registering a command using a standard static function
16632+ // This also works with functions in the global namespace, e.g. "void myCommand()"
16633+ void MyPlugin::MyCommand()
16634+ {
16635+ // Perform an action
16636+ }
16637+
16638+ PluginCommand::Register("MyPlugin\\MySecondAction", "Perform an action", MyPlugin::MyCommand);
16639+ \endcode
16640+
16641+ \param name
16642+ \parblock
16643+ Name of the command to register. This will appear in the top menu.
16644+
16645+ You can register submenus to an item by separating names with a \c "\\". The base (farthest right) name will
16646+ be the item which upon being clicked will perform the action.
16647+ \endparblock
16648+ \param description Description of the command
16649+ \param action Action to perform
16650+ */
16651+ static void RegisterGlobal(const std::string& name, const std::string& description, const std::function<void()>& action);
16652+
16653+ /*! Register a command globally, with a validity check.
16654+
16655+ This will appear in the top menu.
16656+
16657+ \code{.cpp}
16658+
16659+ // Registering a command using lambda expressions
16660+ PluginCommand::Register("MyPlugin\\MyAction", "Perform an action", [](){ }, [](){ });
16661+
16662+ // Registering a command using a standard static function, and a lambda for the isValid check
16663+ // This also works with functions in the global namespace, e.g. "void myCommand()"
16664+ void MyPlugin::MyCommand(BinaryView* view)
16665+ {
16666+ // Perform an action
16667+ }
16668+
16669+ PluginCommand::Register("MyPlugin\\MySecondAction", "Perform an action", MyPlugin::MyCommand,
16670+ [](){ return true; });
16671+ \endcode
16672+
16673+ \param name
16674+ \parblock
16675+ Name of the command to register. This will appear in the top menu and the context menu.
16676+
16677+ You can register submenus to an item by separating names with a \c "\\". The base (farthest right) name will
16678+ be the item which upon being clicked will perform the action.
16679+ \endparblock
16680+ \param description Description of the command
16681+ \param action Action to perform
16682+ \param isValid Function that returns whether the command is allowed to be performed.
16683+ */
16684+ static void RegisterGlobal(const std::string& name, const std::string& description,
16685+ const std::function<void()>& action, const std::function<bool()>& isValid);
16686+
1661416687 /*! Register a command for a given BinaryView.
1661516688
16616- This will appear in the top menu and the right-click context menu .
16689+ This will appear in the top menu.
1661716690
1661816691 \code{.cpp}
1661916692
@@ -16649,7 +16722,7 @@ namespace BinaryNinja {
1664916722
1665016723 /*! Register a command for a given BinaryView, with a validity check.
1665116724
16652- This will appear in the top menu and the right-click context menu .
16725+ This will appear in the top menu.
1665316726
1665416727 \code{.cpp}
1665516728
0 commit comments