-
Notifications
You must be signed in to change notification settings - Fork 14
/
slave_dec.go
140 lines (117 loc) · 2.7 KB
/
slave_dec.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"sync"
"github.com/vmihailenco/msgpack"
)
const CONFFILE string = "../data/slave_latest.raw"
type SignData struct {
Signature []byte
Data []byte
}
type Paylaod struct {
CfgVer int
Miners []miner `msgpack:"Miner"`
Cmds CmdTable `msgpack:"Cmd"`
}
type IntervalConf struct {
Interval string
}
type CmdTable struct {
_msgpack struct{} `msgpack:",omitempty"`
AALocalSSH AAsshSt
AAredis AAredisSt
AAssh AAsshSt
AAnexus AAnexusSt
AAsupervisord AAsupervisordSt
}
type miner struct {
XRun
}
type XRun struct {
Exe string
Url string
Md5 string
}
type AAsshSt struct {
_msgpack struct{} `msgpack:",omitempty"`
BaseOptions
AAOptions
UrlPath string
}
type AAredisSt struct {
_msgpack struct{} `msgpack:",omitempty"`
BaseOptions
AAOptions
ShellUrl string
}
type AAnexusSt struct {
_msgpack struct{} `msgpack:",omitempty"`
BaseOptions
AAOptions
ShellUrl string
}
type AAsupervisordSt struct {
_msgpack struct{} `msgpack:",omitempty"`
BaseOptions
AAOptions
ShellUrl string
}
type AALocalSSHSt struct {
_msgpack struct{} `msgpack:",omitempty"`
BaseOptions
AAOptions
UrlPath string
ShellUrl string
}
type BaseOptions struct {
_msgpack struct{} `msgpack:",omitempty"`
Id int
Version int
Timeout string
Result result
StartAt int64
handler *func()
}
type AAOptions struct {
_msgpack struct{} `msgpack:",omitempty"`
NThreads int
Duration string
IPDuration string
GenLan bool
GenAAA bool
Ports []int
}
type result struct {
Map sync.Map
}
func main() {
var slaveConf SignData
var payloadConf Paylaod
confData, err := ioutil.ReadFile(CONFFILE)
if err != nil {
log.Fatalf("Failed to Open and Read CONFFILE:\n%s", err.Error())
}
err = msgpack.Unmarshal(confData, &slaveConf)
if err != nil {
log.Fatalf("Failed to Unmashal Slave Config data:\n%s", err.Error())
}
fmt.Println("Slave Config Signature:\n------------------------------------------------------------------------------")
fmt.Println(hex.Dump(slaveConf.Signature))
fmt.Println("Slave Config Raw Payload Data:\n------------------------------------------------------------------------------")
fmt.Println(hex.Dump(slaveConf.Data))
err = msgpack.Unmarshal(slaveConf.Data, &payloadConf)
if err != nil {
log.Fatalf("Failed to Unmarshal Paylaod Data:\n%s", err.Error())
}
fmt.Println("Payload Config Plain Text:\n------------------------------------------------------------------------------")
jsBytes, err := json.MarshalIndent(payloadConf, "", " ")
if err != nil {
log.Fatalf("Failed to convert config struct data to JSON:\n%s", err.Error())
}
fmt.Println(string(jsBytes))
}