-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.go
94 lines (86 loc) · 1.54 KB
/
update.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
package qqwry
import (
"bytes"
"compress/zlib"
"encoding/binary"
"io"
"log"
"net/http"
"os"
"strings"
)
var (
remoteKeyURL = "http://update.cz88.net/ip/copywrite.rar"
remoteDataURL = "http://update.cz88.net/ip/qqwry.rar"
localKeyURL = "copywrite.rar"
localDataURL = "qqwry.rar"
dbFileName = "qqwry.dat"
tpFileName = "qqwry.tmp"
)
func urlopen(url string) (*bytes.Buffer, error) {
var buff bytes.Buffer
if strings.HasPrefix(url, "http://") {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
io.Copy(&buff, resp.Body)
} else {
file, err := os.Open(url)
if err != nil {
return nil, err
}
io.Copy(&buff, file)
file.Close()
}
return &buff, nil
}
func decode(keyurl, dataurl string) error {
rk, err := urlopen(keyurl)
if err != nil {
return err
}
rd, err := urlopen(dataurl)
if err != nil {
return err
}
var key int32
for i := 0; i < 6; i++ {
err = binary.Read(rk, binary.LittleEndian, &key)
if err != nil {
return nil
}
}
qqwry := rd.Bytes()
for i := 0; i < 0x200; i++ {
key *= 0x805
key += 1
key = key & 0xFF
qqwry[i] = qqwry[i] ^ byte(key)
}
file, err := os.Create(tpFileName)
if err != nil {
log.Println(err)
return err
}
rd = bytes.NewBuffer(qqwry)
zr, err := zlib.NewReader(rd)
if err != nil {
log.Println(err)
return err
}
io.Copy(file, zr)
zr.Close()
file.Close()
return nil
}
func Update(remote bool) {
var err error
if remote {
err = decode(remoteKeyURL, remoteDataURL)
} else {
err = decode(localKeyURL, localDataURL)
}
if err == nil {
}
}