1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-24 06:09:01 +08:00
nali/pkg/qqwry/update.go

60 lines
1.0 KiB
Go
Raw Normal View History

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
)
2020-07-18 10:48:41 +08:00
func Download() (data []byte, err error) {
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
2020-07-17 09:05:25 +08:00
if err != nil {
2020-07-18 10:48:41 +08:00
return nil, err
2020-07-17 09:05:25 +08:00
}
defer resp.Body.Close()
2020-07-18 10:48:41 +08:00
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
2020-07-17 09:05:25 +08:00
}
2020-07-18 10:48:41 +08:00
key, err := getCopyWriteKey()
if err != nil {
return nil, err
}
return unRar(body, key)
2020-07-17 09:05:25 +08:00
}
2020-07-18 10:48:41 +08:00
func unRar(data []byte, key uint32) ([]byte, error) {
for i := 0; i < 0x200; i++ {
key = key * 0x805
key++
key = key & 0xff
data[i] = byte(uint32(data[i]) ^ key)
}
reader, err := zlib.NewReader(bytes.NewReader(data))
2020-07-17 09:05:25 +08:00
if err != nil {
return nil, err
}
2020-07-18 10:48:41 +08:00
return ioutil.ReadAll(reader)
}
func getCopyWriteKey() (uint32, error) {
resp, err := http.Get("https://qqwry.mirror.noc.one/copywrite.rar")
if err != nil {
return 0, err
}
2020-07-17 09:05:25 +08:00
defer resp.Body.Close()
if body, err := ioutil.ReadAll(resp.Body); err != nil {
2020-07-18 10:48:41 +08:00
return 0, err
2020-07-17 09:05:25 +08:00
} else {
2020-07-18 10:48:41 +08:00
return binary.LittleEndian.Uint32(body[5*4:]), nil
2020-07-17 09:05:25 +08:00
}
}