-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
119 lines (95 loc) · 2.21 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"github.com/urfave/cli/v2"
)
var app = &cli.App{
Name: "geneva",
Usage: "Genetic Evasion for windows",
UseShortOptionHandling: true,
Commands: make([]*cli.Command, 0, 4),
}
type Command struct {
Name string `json:"name"`
CmdStr string `json:"command"`
Args []string `json:"args"`
}
type savedCommands struct {
Items []Command `json:"saved commands"`
}
func init() {
fromFile := func(c *cli.Context) error {
fmt.Println(app.Name)
fmt.Println(c.String("command"))
ex, err := os.Executable()
if err != nil {
fmt.Println(err)
return err
}
exPath := filepath.Dir(ex)
var savedComs savedCommands
data, err := os.ReadFile(filepath.Join(exPath, "saved_commands.json"))
if err != nil {
fmt.Println(err)
return err
}
err = json.Unmarshal(data, &savedComs)
if err != nil {
// print out if error is not nil
fmt.Println(err)
}
index := -1
desiredCom := c.String("command")
for i, s := range savedComs.Items {
fmt.Println(i)
fmt.Println(s.Name)
if s.Name == desiredCom {
index = i
}
}
if index < 0 {
fmt.Printf("Stored command named %s is not found", desiredCom)
return nil
}
chosenCommand := savedComs.Items[index]
// fmt.Println(commands)
realArgs := append([]string{os.Args[0], chosenCommand.CmdStr}, chosenCommand.Args...)
fmt.Println(realArgs)
_ = app.Run(realArgs)
return nil
}
app.Commands = append(app.Commands, &cli.Command{
Name: "list-adapters",
Usage: "Lists the available adapters",
Action: listAdaptersWrapper,
Flags: []cli.Flag{},
})
app.Commands = append(app.Commands, &cli.Command{
Name: "saved-command",
Usage: "Runs commands from config file",
Action: fromFile,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "command",
Aliases: []string{"c"},
Value: "default",
Required: true,
},
},
})
}
func main() {
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
for _, c := range app.Commands {
sort.Sort(cli.FlagsByName(c.Flags))
}
err := app.Run(os.Args)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
}