1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-23 05:39:03 +08:00
nali/pkg/qqwry/update.go
2020-07-18 10:48:41 +08:00

60 lines
1.0 KiB
Go

package qqwry
import (
"bytes"
"compress/zlib"
"encoding/binary"
"io/ioutil"
"net/http"
)
func Download() (data []byte, err error) {
resp, err := http.Get("https://qqwry.mirror.noc.one/qqwry.rar")
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
key, err := getCopyWriteKey()
if err != nil {
return nil, err
}
return unRar(body, key)
}
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))
if err != nil {
return nil, err
}
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
}
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
}
}