2020-07-17 09:05:25 +08:00
|
|
|
package qqwry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-07-17 09:41:09 +08:00
|
|
|
"compress/zlib"
|
|
|
|
"encoding/binary"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2020-07-17 09:05:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func getKey() (uint32, error) {
|
2020-07-17 09:41:09 +08:00
|
|
|
resp, err := http.Get("https://qqwry.mirror.noc.one/copywrite.rar")
|
2020-07-17 09:05:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if body, err := ioutil.ReadAll(resp.Body); err != nil {
|
|
|
|
return 0, err
|
|
|
|
} else {
|
|
|
|
return binary.LittleEndian.Uint32(body[5*4:]), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 09:50:06 +08:00
|
|
|
// get db content from mirror
|
2020-07-17 09:05:25 +08:00
|
|
|
func GetOnline() ([]byte, error) {
|
2020-07-17 09:41:09 +08:00
|
|
|
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
|
2020-07-17 09:05:25 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if body, err := ioutil.ReadAll(resp.Body); err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
if key, err := getKey(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
for i := 0; i < 0x200; i++ {
|
|
|
|
key = key * 0x805
|
|
|
|
key++
|
|
|
|
key = key & 0xff
|
|
|
|
|
|
|
|
body[i] = byte(uint32(body[i]) ^ key)
|
|
|
|
}
|
|
|
|
|
|
|
|
reader, err := zlib.NewReader(bytes.NewReader(body))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.ReadAll(reader)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|