-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_thread.go
80 lines (70 loc) · 1.47 KB
/
core_thread.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
package gomsf
import (
"fmt"
"time"
)
const (
coreThreadList = "core.thread_list"
coreThreadKill = "core.thread_kill"
coreSetg = "core.setg"
coreUnSetg = "core.unsetg"
)
type ThreadInfo struct {
Status string `msgpack:"status"`
Critical bool `msgpack:"critical"`
Name string `msgpack:"name"`
Started time.Time `msgpack:"started"`
}
//TODO Should remove options when failed?
func SetOption(cli MsfCli, token string, kvs ...string) error {
var (
err error
sts = []string{coreSetg, token, "", ""}
)
if len(kvs) == 0 || len(kvs)%2 != 0 {
return fmt.Errorf("kv list is not odd or nil!")
}
for i := 0; i < len(kvs); i += 2 {
sts[2] = kvs[i]
sts[3] = kvs[i+1]
err = cli.Send(sts, nil)
if err != nil {
return err
}
}
return nil
}
func UnSetOption(cli MsfCli, token string, keys ...string) error {
var (
err error
sts = []string{coreUnSetg, token, ""}
)
if len(keys) == 0 {
return fmt.Errorf("key list is nil!")
}
for i := 0; i < len(keys); i++ {
sts[2] = keys[i]
err = cli.Send(sts, nil)
if err != nil {
return err
}
}
return nil
}
func ThreadList(cli MsfCli, token string) ([]*ThreadInfo, error) {
var (
err error
sts = []string{coreThreadList, token}
infos []*ThreadInfo
)
err = cli.Send(sts, &infos)
return infos, err
}
func ThreadKill(cli MsfCli, token, id string) (*Generic, error) {
var (
sts = []string{coreThreadKill, token, id}
gen *Generic
)
err := cli.Send(sts, &gen)
return gen, err
}