diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/plugins/example/example_addition.go b/PluginSystem/plugins/example/example_addition.go new file mode 100755 index 0000000..46da30b --- /dev/null +++ b/PluginSystem/plugins/example/example_addition.go @@ -0,0 +1,44 @@ +package example + +import ( + "fmt" + "strconv" + "encoding/json" + + "PLuginExample/plugins" +) + +type ExampleInts struct { + IntA int `json:"intA"` + IntB int `json:"intB"` +} + +func add(firstNo int, secondNo int)string { + result := strconv.Itoa( firstNo + secondNo ) + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!add" + commands.Callback = func(args ...interface{})(string) { + + var ints ExampleInts + + jsonToUse := []byte(args[0].(string)) + err := json.Unmarshal(jsonToUse, &ints) + if err != nil { + fmt.Println(err.Error()) + } + + result := add(ints.IntA, ints.IntB) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Addition" + p.About = "Example plugin to add two numbers together" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/plugins/example/example_addition.go b/PluginSystem/plugins/example/example_addition.go new file mode 100755 index 0000000..46da30b --- /dev/null +++ b/PluginSystem/plugins/example/example_addition.go @@ -0,0 +1,44 @@ +package example + +import ( + "fmt" + "strconv" + "encoding/json" + + "PLuginExample/plugins" +) + +type ExampleInts struct { + IntA int `json:"intA"` + IntB int `json:"intB"` +} + +func add(firstNo int, secondNo int)string { + result := strconv.Itoa( firstNo + secondNo ) + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!add" + commands.Callback = func(args ...interface{})(string) { + + var ints ExampleInts + + jsonToUse := []byte(args[0].(string)) + err := json.Unmarshal(jsonToUse, &ints) + if err != nil { + fmt.Println(err.Error()) + } + + result := add(ints.IntA, ints.IntB) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Addition" + p.About = "Example plugin to add two numbers together" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/example/example_echo.go b/PluginSystem/plugins/example/example_echo.go new file mode 100755 index 0000000..2c430fb --- /dev/null +++ b/PluginSystem/plugins/example/example_echo.go @@ -0,0 +1,27 @@ +package example + +import ( + //"fmt" + "PluginExample/plugins" +) + +func echo(msg string)string { + result := "returning: " + msg + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!echo" + commands.Callback = func(args ...interface{})(string) { + result := echo(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Echo" + p.About = "Example plugin to repeat what is sent to it" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/plugins/example/example_addition.go b/PluginSystem/plugins/example/example_addition.go new file mode 100755 index 0000000..46da30b --- /dev/null +++ b/PluginSystem/plugins/example/example_addition.go @@ -0,0 +1,44 @@ +package example + +import ( + "fmt" + "strconv" + "encoding/json" + + "PLuginExample/plugins" +) + +type ExampleInts struct { + IntA int `json:"intA"` + IntB int `json:"intB"` +} + +func add(firstNo int, secondNo int)string { + result := strconv.Itoa( firstNo + secondNo ) + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!add" + commands.Callback = func(args ...interface{})(string) { + + var ints ExampleInts + + jsonToUse := []byte(args[0].(string)) + err := json.Unmarshal(jsonToUse, &ints) + if err != nil { + fmt.Println(err.Error()) + } + + result := add(ints.IntA, ints.IntB) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Addition" + p.About = "Example plugin to add two numbers together" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/example/example_echo.go b/PluginSystem/plugins/example/example_echo.go new file mode 100755 index 0000000..2c430fb --- /dev/null +++ b/PluginSystem/plugins/example/example_echo.go @@ -0,0 +1,27 @@ +package example + +import ( + //"fmt" + "PluginExample/plugins" +) + +func echo(msg string)string { + result := "returning: " + msg + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!echo" + commands.Callback = func(args ...interface{})(string) { + result := echo(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Echo" + p.About = "Example plugin to repeat what is sent to it" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/misc/help.go b/PluginSystem/plugins/misc/help.go new file mode 100755 index 0000000..9def8b0 --- /dev/null +++ b/PluginSystem/plugins/misc/help.go @@ -0,0 +1,37 @@ +package misc + +import ( + //"fmt" + "PluginExample/plugins" +) + +func misc_help(msg string)string { + var result string + for _, element := range plugins.Plugins { + + result += "cmd:" + element.Commands.Name + ", " + result += "name:" + element.Name + "\n" + result += "about:" + element.About + "\n\n" + //element.Commands[0].Callback() + + //result += "cmd:", key, "=>", "info:", element + } + + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!help" + commands.Callback = func(args ...interface{})(string) { + result := misc_help(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Help" + p.About = "Display all plugins informaion" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/plugins/example/example_addition.go b/PluginSystem/plugins/example/example_addition.go new file mode 100755 index 0000000..46da30b --- /dev/null +++ b/PluginSystem/plugins/example/example_addition.go @@ -0,0 +1,44 @@ +package example + +import ( + "fmt" + "strconv" + "encoding/json" + + "PLuginExample/plugins" +) + +type ExampleInts struct { + IntA int `json:"intA"` + IntB int `json:"intB"` +} + +func add(firstNo int, secondNo int)string { + result := strconv.Itoa( firstNo + secondNo ) + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!add" + commands.Callback = func(args ...interface{})(string) { + + var ints ExampleInts + + jsonToUse := []byte(args[0].(string)) + err := json.Unmarshal(jsonToUse, &ints) + if err != nil { + fmt.Println(err.Error()) + } + + result := add(ints.IntA, ints.IntB) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Addition" + p.About = "Example plugin to add two numbers together" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/example/example_echo.go b/PluginSystem/plugins/example/example_echo.go new file mode 100755 index 0000000..2c430fb --- /dev/null +++ b/PluginSystem/plugins/example/example_echo.go @@ -0,0 +1,27 @@ +package example + +import ( + //"fmt" + "PluginExample/plugins" +) + +func echo(msg string)string { + result := "returning: " + msg + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!echo" + commands.Callback = func(args ...interface{})(string) { + result := echo(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Echo" + p.About = "Example plugin to repeat what is sent to it" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/misc/help.go b/PluginSystem/plugins/misc/help.go new file mode 100755 index 0000000..9def8b0 --- /dev/null +++ b/PluginSystem/plugins/misc/help.go @@ -0,0 +1,37 @@ +package misc + +import ( + //"fmt" + "PluginExample/plugins" +) + +func misc_help(msg string)string { + var result string + for _, element := range plugins.Plugins { + + result += "cmd:" + element.Commands.Name + ", " + result += "name:" + element.Name + "\n" + result += "about:" + element.About + "\n\n" + //element.Commands[0].Callback() + + //result += "cmd:", key, "=>", "info:", element + } + + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!help" + commands.Callback = func(args ...interface{})(string) { + result := misc_help(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Help" + p.About = "Display all plugins informaion" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/pluginsHelper.go b/PluginSystem/plugins/pluginsHelper.go new file mode 100755 index 0000000..f860040 --- /dev/null +++ b/PluginSystem/plugins/pluginsHelper.go @@ -0,0 +1,37 @@ +package plugins + +//import "fmt" + +type PluginInfo struct { + Name string + About string + Commands Command +} + +type Command struct { + Name string + Callback func(args ...interface{})(string) +} + +var Plugins []PluginInfo + +func (p *PluginInfo) AddPluginInfo() { + Plugins = append(Plugins, *p) +} + +func (p *PluginInfo) Handle() { + +} + +func RunPlugin(cmd string, arg string)string{ + var result string + for _, element := range Plugins { + // fmt.Println("cmd:", key, "=>", "info:", element) // DEBUG + if element.Commands.Name == cmd { + result = element.Commands.Callback(arg) + return result + } + result = "command not found" + } + return result +} diff --git a/PluginSystem/README.md b/PluginSystem/README.md new file mode 100644 index 0000000..bc3aa44 --- /dev/null +++ b/PluginSystem/README.md @@ -0,0 +1,25 @@ +Plugin Example +=============== +A simple plugin system so people can create simple plugin.go files to drop in a specific folder and they will be recognized and added to the app for use within the app. + +*example use:* + +``` +$> ./Vic4 +result of !help: +cmd:!help, name:Help +about:Display all plugins informaion + +cmd:!add, name:Example Addition +about:Example plugin to add two numbers together + +cmd:!echo, name:Example Echo +about:Example plugin to repeat what is sent to it + +result of !echo: returning: this argument returned +result of !add (1+2): 3 +``` + +Thanks +=============== +A MASSIVE thanks to @MantisSTS for writing the majority of this! diff --git a/PluginSystem/main.go b/PluginSystem/main.go new file mode 100755 index 0000000..c60cd8f --- /dev/null +++ b/PluginSystem/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "PluginSystem/plugins" + _ "PluginSystem/plugins/misc" + _ "PluginSystem/plugins/example" +) + +func main() { + + result := plugins.RunPlugin("!help", "") + fmt.Println("result of !help:") + fmt.Print(result) + + cmd := "!echo" + arg := "this argument returned" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !echo:", result) + + + cmd = "!add" + arg = "{\"intA\":1, \"intB\":2}" + result = plugins.RunPlugin(cmd, arg) + fmt.Println("result of !add (1+2):", result) + +} diff --git a/PluginSystem/plugins/example/example_addition.go b/PluginSystem/plugins/example/example_addition.go new file mode 100755 index 0000000..46da30b --- /dev/null +++ b/PluginSystem/plugins/example/example_addition.go @@ -0,0 +1,44 @@ +package example + +import ( + "fmt" + "strconv" + "encoding/json" + + "PLuginExample/plugins" +) + +type ExampleInts struct { + IntA int `json:"intA"` + IntB int `json:"intB"` +} + +func add(firstNo int, secondNo int)string { + result := strconv.Itoa( firstNo + secondNo ) + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!add" + commands.Callback = func(args ...interface{})(string) { + + var ints ExampleInts + + jsonToUse := []byte(args[0].(string)) + err := json.Unmarshal(jsonToUse, &ints) + if err != nil { + fmt.Println(err.Error()) + } + + result := add(ints.IntA, ints.IntB) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Addition" + p.About = "Example plugin to add two numbers together" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/example/example_echo.go b/PluginSystem/plugins/example/example_echo.go new file mode 100755 index 0000000..2c430fb --- /dev/null +++ b/PluginSystem/plugins/example/example_echo.go @@ -0,0 +1,27 @@ +package example + +import ( + //"fmt" + "PluginExample/plugins" +) + +func echo(msg string)string { + result := "returning: " + msg + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!echo" + commands.Callback = func(args ...interface{})(string) { + result := echo(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Example Echo" + p.About = "Example plugin to repeat what is sent to it" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/misc/help.go b/PluginSystem/plugins/misc/help.go new file mode 100755 index 0000000..9def8b0 --- /dev/null +++ b/PluginSystem/plugins/misc/help.go @@ -0,0 +1,37 @@ +package misc + +import ( + //"fmt" + "PluginExample/plugins" +) + +func misc_help(msg string)string { + var result string + for _, element := range plugins.Plugins { + + result += "cmd:" + element.Commands.Name + ", " + result += "name:" + element.Name + "\n" + result += "about:" + element.About + "\n\n" + //element.Commands[0].Callback() + + //result += "cmd:", key, "=>", "info:", element + } + + return result +} + +func init() { + + var commands plugins.Command + commands.Name = "!help" + commands.Callback = func(args ...interface{})(string) { + result := misc_help(args[0].(string)) + return result + } + + var p plugins.PluginInfo + p.Name = "Help" + p.About = "Display all plugins informaion" + p.Commands = commands + p.AddPluginInfo() +} diff --git a/PluginSystem/plugins/pluginsHelper.go b/PluginSystem/plugins/pluginsHelper.go new file mode 100755 index 0000000..f860040 --- /dev/null +++ b/PluginSystem/plugins/pluginsHelper.go @@ -0,0 +1,37 @@ +package plugins + +//import "fmt" + +type PluginInfo struct { + Name string + About string + Commands Command +} + +type Command struct { + Name string + Callback func(args ...interface{})(string) +} + +var Plugins []PluginInfo + +func (p *PluginInfo) AddPluginInfo() { + Plugins = append(Plugins, *p) +} + +func (p *PluginInfo) Handle() { + +} + +func RunPlugin(cmd string, arg string)string{ + var result string + for _, element := range Plugins { + // fmt.Println("cmd:", key, "=>", "info:", element) // DEBUG + if element.Commands.Name == cmd { + result = element.Commands.Callback(arg) + return result + } + result = "command not found" + } + return result +} diff --git a/README.md b/README.md index 2e1fd1f..fec8df5 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ view, modify and create windows shortcut files (.lnk) +**PLuginExample** + +A small PoC showing how to add a pluginsystem to your application + **RunningAs** -Alert box containing current user process running as \ No newline at end of file +Alert box containing current user process running as