-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfunctions.go
223 lines (212 loc) · 4.94 KB
/
functions.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package skype
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/spf13/viper"
"log"
"math"
"os"
"path/filepath"
"strconv"
"strings"
)
/**
+ SKYPEWEB_LOCKANDKEY_SECRET
*/
func getMac256Hash(secs string) string {
clearText := secs + SKYPEWEB_LOCKANDKEY_APPID
zeroNum := (8 - len(clearText)%8)
for i := 0; i < zeroNum; i++ {
clearText += "0"
}
//开始 加密 getMac256Hash
cchClearText := len(clearText) / 4
pClearText := make([]int, cchClearText)
for i := 0; i < cchClearText; i++ {
mib := 0
for pos := 0; pos < 4; pos++ {
len1 := 4*i + pos
b := int([]rune(clearText[len1 : len1+1])[0])
mi := int(math.Pow(256, float64(pos)))
mib += mi * b
}
pClearText[i] = mib
}
sha256Hash := []int{
0, 0, 0, 0,
}
//
screact_key_str := secs + SKYPEWEB_LOCKANDKEY_SECRET
h := sha256.New()
h.Write([]byte(screact_key_str))
sum := h.Sum(nil)
hash_str := strings.ToUpper(string(hex.EncodeToString(sum)))
sha256len := len(sha256Hash)
for s := 0; s < sha256len; s++ {
sha256Hash[s] = 0
for pos := 0; pos < 4; pos++ {
dpos := 8*s + pos*2
mi1 := int(math.Pow(256, float64(pos)))
inthash := hash_str[dpos : dpos+2]
inthash1, _ := strconv.ParseInt(inthash, 16, 64)
sha256Hash[s] += int(inthash1) * mi1
}
}
qwMAC, qwSum := cs64(pClearText, sha256Hash)
macParts := []int{
qwMAC,
qwSum,
qwMAC,
qwSum,
}
scans := []int{0, 0, 0, 0}
for i, sha := range sha256Hash {
scans[i] = int64Xor(sha, macParts[i])
}
//scan := int64Xor(sha256Hash, macParts)
hexString := ""
for _, scan := range scans {
hexString += int32ToHexString(scan)
}
return hexString
}
func int32ToHexString(n int) (hexString string) {
hexChars := "0123456789abcdef"
for i := 0; i < 4; i++ {
num1 := (n >> (i*8 + 4)) & 15
num2 := (n >> (i * 8)) & 15
hexString += hexChars[num1 : num1+1]
hexString += hexChars[num2 : num2+1]
}
return
}
func int64Xor(a int, b int) (sc int) {
sA := fmt.Sprintf("%b", a)
sB := fmt.Sprintf("%b", b)
sC := ""
sD := ""
diff := math.Abs(float64(len(sA) - len(sB)))
for d := 0; d < int(diff); d++ {
sD += "0"
}
if len(sA) < len(sB) {
sD += sA
sA = sD
} else if len(sB) < len(sA) {
sD += sB
sB = sD
}
for a := 0; a < len(sA); a++ {
if sA[a] == sB[a] {
sC += "0"
} else {
sC += "1"
}
}
to2, _ := strconv.ParseInt(sC, 2, 64)
xor, _ := strconv.Atoi(fmt.Sprintf("%d", to2))
return xor
}
func cs64(pdwData, pInHash []int) (qwMAC int, qwSum int) {
MODULUS := 2147483647
CS64_a := pInHash[0] & MODULUS
CS64_b := pInHash[1] & MODULUS
CS64_c := pInHash[2] & MODULUS
CS64_d := pInHash[3] & MODULUS
CS64_e := 242854337
pos := 0
qwDatum := 0
qwMAC = 0
qwSum = 0
pdwLen := len(pdwData) / 2
for i := 0; i < pdwLen; i++ {
qwDatum = int(pdwData[pos])
pos += 1
qwDatum *= CS64_e
qwDatum = qwDatum % MODULUS
qwMAC += qwDatum
qwMAC *= CS64_a
qwMAC += CS64_b
qwMAC = qwMAC % MODULUS
qwSum += qwMAC
qwMAC += int(pdwData[pos])
pos += 1
qwMAC *= CS64_c
qwMAC += CS64_d
qwMAC = qwMAC % MODULUS
qwSum += qwMAC
}
qwMAC += CS64_b
qwMAC = qwMAC % MODULUS
qwSum += CS64_d
qwSum = qwSum % MODULUS
return qwMAC, qwSum
}
func GetConfigYaml() {
viper.SetConfigName("config")
viper.AddConfigPath("examples")
if err := viper.ReadInConfig(); err != nil {
log.Println(err)
}
}
func GetConfigYamlForBuildExample() {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
dir = getParentDirectory(dir)
viper.SetConfigName("config")
viper.AddConfigPath(dir)
fmt.Println(viper.ReadInConfig())
if err := viper.ReadInConfig(); err != nil {
log.Println(err)
}
}
func substr(s string, pos, length int) string {
runes := []rune(s)
l := pos + length
if l > len(runes) {
l = len(runes)
}
return string(runes[pos:l])
}
func getParentDirectory(dir string) string {
return substr(dir, 0, strings.LastIndex(dir, "/"))
}
func UriObject(content, fileType, docId, url, thumb, title, desc string, durationMs int, values map[string]string) string {
titleTag := "" // "<Title/>"
descTag := "" //"<Description/>"
thumbAttr := ""
valTags := ""
Durations := ""
docIdTag := ""
if len(title) > 0 {
titleTag = fmt.Sprintf(`<Title>Title: %s</Title>`, title)
}
if len(desc) >0 {
descTag = fmt.Sprintf(`<Description>Description: %s</Description>`, desc)
}
if len(thumb) > 0 {
thumbAttr = fmt.Sprintf(`url_thumbnail="%s"`, thumb)
}
if len(docId) > 0 {
docIdTag = fmt.Sprintf(`doc_id="%s"`, docId)
}
if len(values) > 0 {
for k,v := range values {
valTags += fmt.Sprintf(`<%s v="%s"></%s>`, k, v, k)
}
}
if durationMs > 0 {
Durations = fmt.Sprintf(`duration_ms="%s"`, strconv.Itoa(durationMs))
}
objStr := fmt.Sprintf(`<URIObject type="%s" uri="%s" %s %s %s>%s%s%s%s</URIObject>`, fileType, url, Durations, thumbAttr, docIdTag, titleTag, descTag, valTags, content)
return objStr
}
func ReplaceSymbol(str string) string {
str = strings.ReplaceAll(str, "&", "&")
str = strings.ReplaceAll(str, "<", "<")
str = strings.ReplaceAll(str, ">", ">")
return str
}