-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGlobalPluginCommand.cs
More file actions
39 lines (31 loc) · 1.19 KB
/
Copy pathGlobalPluginCommand.cs
File metadata and controls
39 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Runtime.InteropServices;
namespace BinaryNinja
{
/// <summary>Hosts a global plugin command with managed callbacks.</summary>
public abstract class GlobalPluginCommand
{
private BNPluginCommand.GlobalCommandDelegate? commandCallback;
private BNPluginCommand.GlobalIsValidDelegate? isValidCallback;
public void Register(string name, string description = "")
{
if (null == name)
{
throw new ArgumentNullException(nameof(name));
}
this.commandCallback = new BNPluginCommand.GlobalCommandDelegate(this.InvokeCommand);
this.isValidCallback = new BNPluginCommand.GlobalIsValidDelegate(this.InvokeIsValid);
NativeMethods.BNRegisterPluginCommandGlobal(
name,
description ?? string.Empty,
Marshal.GetFunctionPointerForDelegate<BNPluginCommand.GlobalCommandDelegate>(this.commandCallback),
Marshal.GetFunctionPointerForDelegate<BNPluginCommand.GlobalIsValidDelegate>(this.isValidCallback),
IntPtr.Zero
);
}
public abstract void Execute();
public virtual bool IsValid() { return true; }
private void InvokeCommand(IntPtr context) { this.Execute(); }
private bool InvokeIsValid(IntPtr context) { return this.IsValid(); }
}
}