Help us shape the future of Go! Take the 2026 Go Developer Survey

plugin

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LuaInternal = iota
	LuaFlag
	LuaArg
	LuaReverse
)
View Source
const (
	LuaScript = "lua"
	GoPlugin  = "go"
	EmbedType = "embed"
)
View Source
const CMDSeq = ":"

Variables

View Source
var (
	ReservedARGS    = "args"
	ReservedCMDLINE = "cmdline"
	ReservedCMD     = "cmd"
	ReservedWords   = []string{ReservedCMDLINE, ReservedARGS, ReservedCMD}

	ProtoPackage = []string{"implantpb", "clientpb", "modulepb"}
)
View Source
var ErrLuaVMDead = fmt.Errorf("lua vm is dead")

Functions

func GenerateSchemasFromCommands added in v0.3.0

func GenerateSchemasFromCommands(commands []*cobra.Command) (map[string]*CommandSchema, error)

GenerateSchemasFromCommands generates schemas from a list of cobra commands This is the unified API for schema generation from []*cobra.Command

func NewLuaVM

func NewLuaVM() *lua.LState

func NewYaegiInterpreter

func NewYaegiInterpreter() *interp.Interpreter

func SetFlagGroup added in v0.3.0

func SetFlagGroup(flag *pflag.Flag, group string) error

SetFlagGroup sets the field group Usage: ui_group(flag, "Basic Settings")

func SetFlagOrder added in v0.3.0

func SetFlagOrder(flag *pflag.Flag, order int) error

SetFlagOrder sets the field order Usage: ui_order(flag, 1)

func SetFlagPlaceholder added in v0.3.0

func SetFlagPlaceholder(flag *pflag.Flag, placeholder string) error

SetFlagPlaceholder sets the placeholder text Usage: ui_placeholder(flag, "Enter command")

func SetFlagRange added in v0.3.0

func SetFlagRange(flag *pflag.Flag, min, max float64) error

SetFlagRange sets the numeric range (min, max) Usage: ui_range(flag, 1, 100)

func SetFlagRequired added in v0.3.0

func SetFlagRequired(flag *pflag.Flag, required bool) error

SetFlagRequired sets whether the field is required Usage: ui_required(flag, true)

func SetFlagUI added in v0.3.0

func SetFlagUI(flag *pflag.Flag, options map[string]string) error

SetFlagUI sets multiple UI hints at once Usage: ui_set(flag, {widget="textarea", group="Basic", placeholder="Enter text"})

func SetFlagWidget added in v0.3.0

func SetFlagWidget(flag *pflag.Flag, widget string) error

SetFlagWidget sets the widget type Usage: ui_widget(flag, "textarea")

Types

type Command

type Command struct {
	Name    string
	Long    string
	Example string
	Command *cobra.Command
	Subs    Commands
	Parent  *Command
}

func (*Command) GenerateSchema added in v0.3.0

func (cmd *Command) GenerateSchema() (*CommandSchema, error)

GenerateSchema generates JSON Schema for a command

type CommandMetadata added in v0.3.0

type CommandMetadata struct {
	Name        string            `json:"name"`
	PluginName  string            `json:"plugin,omitempty"`
	Source      string            `json:"source,omitempty"` // golang/alias/extension/mal
	TTP         string            `json:"ttp,omitempty"`
	Opsec       int               `json:"opsec,omitempty"`
	Example     string            `json:"example,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

CommandMetadata represents metadata for a command

type CommandSchema added in v0.3.0

type CommandSchema struct {
	Type        string                     `json:"type"`
	Title       string                     `json:"title,omitempty"`
	Description string                     `json:"description,omitempty"`
	Properties  map[string]*PropertySchema `json:"properties"`
	Required    []string                   `json:"required,omitempty"`
	XMetadata   *CommandMetadata           `json:"x-metadata,omitempty"`
}

CommandSchema represents the JSON Schema for a command (including UI information)

func (*CommandSchema) ToJSON added in v0.3.0

func (schema *CommandSchema) ToJSON() (string, error)

ToJSON exports CommandSchema as JSON string

type Commands

type Commands map[string]*Command

func (Commands) Commands added in v0.1.2

func (cs Commands) Commands() []*cobra.Command

func (Commands) Find

func (cs Commands) Find(name string) *Command

func (Commands) SetCommand

func (cs Commands) SetCommand(name string, cmd *cobra.Command)

type DefaultPlugin

type DefaultPlugin struct {
	*MalManiFest
	Enable  bool
	Content []byte
	Path    string
	CMDs    Commands
	Events  map[client.EventCondition]client.OnEventFunc
}

func LoadGlobalLuaPlugin

func LoadGlobalLuaPlugin() []*DefaultPlugin

func NewPlugin

func NewPlugin(manifest *MalManiFest) (*DefaultPlugin, error)

func (*DefaultPlugin) Commands

func (plug *DefaultPlugin) Commands() Commands

func (*DefaultPlugin) GetEvents

func (plug *DefaultPlugin) GetEvents() map[client.EventCondition]client.OnEventFunc

func (*DefaultPlugin) Manifest

func (plug *DefaultPlugin) Manifest() *MalManiFest

type EmbedPlugin

type EmbedPlugin struct {
	*LuaPlugin
	// 嵌入式插件特有的信息
	Level    MalLevel
	FS       embed.FS
	RootPath string // 在embed.FS中的根路径,如"community"、"professional"等
}

EmbedPlugin 嵌入式Lua插件,直接实现Plugin接口

func NewEmbedPlugin

func NewEmbedPlugin(malPath, malName string, level MalLevel) (*EmbedPlugin, error)

NewEmbedPlugin 创建嵌入式插件

func (*EmbedPlugin) EmbedURI added in v0.3.0

func (plug *EmbedPlugin) EmbedURI(resourcePath string) string

EmbedURI 构建当前嵌入式插件的规范资源URI

func (*EmbedPlugin) FileExists

func (plug *EmbedPlugin) FileExists(filename string) bool

FileExists 检查文件是否存在

func (*EmbedPlugin) GetFileContent

func (plug *EmbedPlugin) GetFileContent(filename string) ([]byte, bool)

GetFileContent 获取文件内容 - 直接从embed.FS读取

func (*EmbedPlugin) GetLevel

func (plug *EmbedPlugin) GetLevel() MalLevel

GetLevel 获取插件级别

func (*EmbedPlugin) ReadDir

func (plug *EmbedPlugin) ReadDir(dirname string) ([]fs.DirEntry, error)

ReadDir 读取目录内容

func (*EmbedPlugin) Run

func (plug *EmbedPlugin) Run() error

type GoMalPlugin

type GoMalPlugin struct {
	*DefaultPlugin
	Interpreter *interp.Interpreter
}

func NewGoMalPlugin

func NewGoMalPlugin(manifest *MalManiFest) (*GoMalPlugin, error)

func (*GoMalPlugin) Destroy

func (plug *GoMalPlugin) Destroy() error

func (*GoMalPlugin) Run

func (plug *GoMalPlugin) Run() error

type LuaParam

type LuaParam struct {
	Name string
	Type int
}

type LuaPlugin

type LuaPlugin struct {
	*DefaultPlugin
	// contains filtered or unexported fields
}

func NewLuaMalPlugin

func NewLuaMalPlugin(manifest *MalManiFest) (*LuaPlugin, error)

func (*LuaPlugin) Acquire

func (plug *LuaPlugin) Acquire() (*LuaVMWrapper, error)

func (*LuaPlugin) Destroy

func (plug *LuaPlugin) Destroy() error

func (*LuaPlugin) InitLuaContext

func (plug *LuaPlugin) InitLuaContext(vm *lua.LState) error

func (*LuaPlugin) RegisterLuaFunction added in v0.1.2

func (plug *LuaPlugin) RegisterLuaFunction()

func (*LuaPlugin) Release

func (plug *LuaPlugin) Release(wrapper *LuaVMWrapper)

func (*LuaPlugin) Run

func (plug *LuaPlugin) Run() error

type LuaVMPool

type LuaVMPool struct {
	// contains filtered or unexported fields
}

func NewLuaVMPool

func NewLuaVMPool(maxSize int, initScript string, plugName string) (*LuaVMPool, error)

func (*LuaVMPool) AcquireVM

func (p *LuaVMPool) AcquireVM() (*LuaVMWrapper, error)

func (*LuaVMPool) Destroy

func (p *LuaVMPool) Destroy()

func (*LuaVMPool) ReleaseVM

func (p *LuaVMPool) ReleaseVM(wrapper *LuaVMWrapper)

type LuaVMWrapper

type LuaVMWrapper struct {
	*lua.LState
	// contains filtered or unexported fields
}

func NewLuaVMWrapper

func NewLuaVMWrapper() *LuaVMWrapper

func (*LuaVMWrapper) Lock

func (w *LuaVMWrapper) Lock()

func (*LuaVMWrapper) Unlock

func (w *LuaVMWrapper) Unlock()

type MalLevel

type MalLevel int

MalLevel 表示mal插件的级别

const (
	CommunityLevel MalLevel = iota
	ProfessionalLevel
	CustomLevel
)

func (MalLevel) String

func (l MalLevel) String() string

type MalManager

type MalManager struct {
	// contains filtered or unexported fields
}

MalManager 统一的mal插件管理器,分别管理嵌入式和外部插件

func GetGlobalMalManager

func GetGlobalMalManager() *MalManager

GetGlobalMalManager 获取全局mal管理器(单例)

func (*MalManager) GetAllEmbeddedPlugins

func (mm *MalManager) GetAllEmbeddedPlugins() map[string]*EmbedPlugin

GetAllEmbeddedPlugins 获取所有嵌入式插件

func (*MalManager) GetAllExternalPlugins

func (mm *MalManager) GetAllExternalPlugins() map[string]Plugin

GetAllExternalPlugins 获取所有外部插件

func (*MalManager) GetEmbedPlugin

func (mm *MalManager) GetEmbedPlugin(name string) (*EmbedPlugin, bool)

GetEmbedPlugin 获取指定名称的嵌入式插件

func (*MalManager) GetEmbeddedCommandsByLevel added in v0.3.0

func (mm *MalManager) GetEmbeddedCommandsByLevel(level MalLevel) []*cobra.Command

func (*MalManager) GetEmbeddedPluginsByLevel added in v0.3.0

func (mm *MalManager) GetEmbeddedPluginsByLevel(level MalLevel) []*EmbedPlugin

func (*MalManager) GetExternalPlugin

func (mm *MalManager) GetExternalPlugin(name string) (Plugin, bool)

GetExternalPlugin 获取指定名称的外部插件

func (*MalManager) GetGlobalPlugin

func (mm *MalManager) GetGlobalPlugin(name string) (*DefaultPlugin, bool)

GetGlobalPlugin 获取指定名称的全局插件

func (*MalManager) GetGlobalPlugins

func (mm *MalManager) GetGlobalPlugins() []*DefaultPlugin

GetGlobalPlugins 获取所有全局插件

func (*MalManager) GetLoadedMals

func (mm *MalManager) GetLoadedMals() []string

GetLoadedMals 获取所有已加载的插件列表

func (*MalManager) GetLuaVMPool added in v0.3.0

func (mm *MalManager) GetLuaVMPool() *LuaVMPool

GetLuaVMPool 获取共享的 Lua VM Pool

func (*MalManager) GetPlugin

func (mm *MalManager) GetPlugin(name string) (Plugin, bool)

GetPlugin 获取指定名称的插件(先查找外部,再查找嵌入式)

func (*MalManager) GetPluginManifests

func (mm *MalManager) GetPluginManifests() []*MalManiFest

GetPluginManifests 获取所有外部插件清单

func (*MalManager) LoadExternalMal

func (mm *MalManager) LoadExternalMal(manifest *MalManiFest) (Plugin, error)

LoadExternalMal 加载单个外部mal插件

func (*MalManager) ReloadExternalMal

func (mm *MalManager) ReloadExternalMal(malName string) error

ReloadExternalMal 重新加载指定的外部mal插件

func (*MalManager) RemoveExternalMal

func (mm *MalManager) RemoveExternalMal(malName string) error

RemoveExternalMal 移除指定的外部mal插件

type MalManiFest

type MalManiFest struct {
	Name         string   `json:"name" yaml:"name"`
	Type         string   `json:"type" yaml:"type"` // lua, tcl
	Author       string   `json:"author" yaml:"author"`
	Version      string   `json:"version" yaml:"version"`
	EntryFile    string   `json:"entry" yaml:"entry"`
	Lib          bool     `json:"lib" yaml:"lib"`
	DependModule []string `json:"depend_module" yaml:"depend_modules"`
	DependArmory []string `json:"depend_armory" yaml:"depend_armory"`
}

func GetPluginManifest

func GetPluginManifest() []*MalManiFest

func LoadMalManiFest

func LoadMalManiFest(filename string) (*MalManiFest, error)

func ParseMalManifest

func ParseMalManifest(data []byte) (*MalManiFest, error)

type Plugin

type Plugin interface {
	Run() error
	Manifest() *MalManiFest
	Commands() Commands
	Destroy() error
	GetEvents() map[client.EventCondition]client.OnEventFunc
}

type PropertySchema added in v0.3.0

type PropertySchema struct {
	Type        string      `json:"type"`
	Title       string      `json:"title,omitempty"`
	Description string      `json:"description,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Enum        []string    `json:"enum,omitempty"`
	Pattern     string      `json:"pattern,omitempty"`
	MinLength   *int        `json:"minLength,omitempty"`
	MaxLength   *int        `json:"maxLength,omitempty"`
	Minimum     *float64    `json:"minimum,omitempty"`
	Maximum     *float64    `json:"maximum,omitempty"`

	// Additional properties for UI hints (populated from flag annotations)
	AdditionalProperties map[string]interface{} `json:"-"`
}

PropertySchema represents a property in the JSON Schema

func (*PropertySchema) MarshalJSON added in v0.3.0

func (ps *PropertySchema) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to include additional properties

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL