Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
62f7991a64 | |||
9390b45207 | |||
deaa58e91f | |||
7755d47f7a | |||
7cc7aa19fd | |||
1025010395 | |||
8cc7f66640 | |||
38648d57e6 | |||
629c0c36f0 | |||
1552a667f6 | |||
f14c0cd9c2 | |||
63d4e6e1d2 | |||
be6d3e5a44 | |||
ae4b46bf57 | |||
3f3980de38 | |||
6fd5bd5863 | |||
0a13671df2 | |||
28d84e4dc2 | |||
60c15894c0 | |||
15e340eac4 | |||
c836ac7cb5 |
32
.github/workflows/build.yml
vendored
32
.github/workflows/build.yml
vendored
@ -1,7 +1,6 @@
|
||||
name: Build
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
@ -17,17 +16,23 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ windows-latest, ubuntu-latest, macos-latest ]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
- target: "linux/amd64"
|
||||
GOOS: "linux"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ""
|
||||
- os: macos-latest
|
||||
BIN_SUFFIX: ""
|
||||
- os: windows-latest
|
||||
- target: "windows/amd64"
|
||||
GOOS: "windows"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ".exe"
|
||||
- target: "darwin/amd64"
|
||||
GOOS: "darwin"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ""
|
||||
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v2
|
||||
@ -37,7 +42,7 @@ jobs:
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.16
|
||||
go-version: ^1.17
|
||||
|
||||
- name: Setup vars
|
||||
id: vars
|
||||
@ -45,13 +50,18 @@ jobs:
|
||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
||||
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
GOOS: ${{ matrix.GOOS }}
|
||||
GOARCH: ${{ matrix.GOARCH }}
|
||||
CGO_ENABLED: 0
|
||||
run: go build -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
||||
run: go build -v -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
||||
|
||||
- name: Publish artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: um-${{ runner.os }}${{ matrix.BIN_SUFFIX }}
|
||||
path: ./um-${{ runner.os }}${{ matrix.BIN_SUFFIX }}
|
||||
name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
|
||||
path: ./um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}
|
||||
|
84
.github/workflows/release.yml
vendored
Normal file
84
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
name: Create Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
create_release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get current time
|
||||
id: date
|
||||
run: echo "::set-output name=date::$(date +'%Y/%m/%d')"
|
||||
|
||||
- name: Create release
|
||||
id: release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: "Build ${{ steps.date.outputs.date }}"
|
||||
draft: true
|
||||
outputs:
|
||||
upload_url: "${{ steps.release.outputs.upload_url }}"
|
||||
build:
|
||||
needs:
|
||||
- create_release
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- target: "linux/amd64"
|
||||
GOOS: "linux"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ""
|
||||
- target: "windows/amd64"
|
||||
GOOS: "windows"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ".exe"
|
||||
- target: "windows/386"
|
||||
GOOS: "windows"
|
||||
GOARCH: "386"
|
||||
BIN_SUFFIX: ".exe"
|
||||
- target: "darwin/amd64"
|
||||
GOOS: "darwin"
|
||||
GOARCH: "amd64"
|
||||
BIN_SUFFIX: ""
|
||||
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup vars
|
||||
id: vars
|
||||
run: |
|
||||
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
||||
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
||||
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.17
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
GOOS: ${{ matrix.GOOS }}
|
||||
GOARCH: ${{ matrix.GOARCH }}
|
||||
CGO_ENABLED: 0
|
||||
run: go build -trimpath -v -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -o um ./cmd/um
|
||||
|
||||
- name: Upload release assets
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ needs.create_release.outputs.upload_url }}
|
||||
asset_path: um
|
||||
asset_name: um-${{ matrix.GOOS }}-${{ matrix.GOARCH }}${{ matrix.BIN_SUFFIX }}
|
||||
asset_content_type: application/octet-stream
|
||||
|
@ -13,7 +13,7 @@ Original: Web Edition https://github.com/ix64/unlock-music
|
||||
|
||||
## Hou to Build
|
||||
|
||||
- Requirements: **Golang 1.16**
|
||||
- Requirements: **Golang 1.17**
|
||||
|
||||
1. Clone this repo `git clone https://github.com/unlock-music/cli && cd cli`
|
||||
2. Build the executable `go build ./cmd/um`
|
||||
|
@ -1,12 +1,30 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NewDecoderFunc func([]byte) Decoder
|
||||
|
||||
var decoderRegistry = make(map[string][]NewDecoderFunc)
|
||||
type decoderItem struct {
|
||||
noop bool
|
||||
decoder NewDecoderFunc
|
||||
}
|
||||
|
||||
func RegisterDecoder(ext string, dispatchFunc NewDecoderFunc) {
|
||||
decoderRegistry[ext] = append(decoderRegistry[ext], dispatchFunc)
|
||||
var DecoderRegistry = make(map[string][]decoderItem)
|
||||
|
||||
func RegisterDecoder(ext string, noop bool, dispatchFunc NewDecoderFunc) {
|
||||
DecoderRegistry[ext] = append(DecoderRegistry[ext],
|
||||
decoderItem{noop: noop, decoder: dispatchFunc})
|
||||
}
|
||||
func GetDecoder(ext string) []NewDecoderFunc {
|
||||
return decoderRegistry[ext]
|
||||
func GetDecoder(filename string, skipNoop bool) (rs []NewDecoderFunc) {
|
||||
ext := strings.ToLower(strings.TrimLeft(filepath.Ext(filename), "."))
|
||||
for _, dec := range DecoderRegistry[ext] {
|
||||
if skipNoop && dec.noop {
|
||||
continue
|
||||
}
|
||||
rs = append(rs, dec.decoder)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1,17 +1,27 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type RawDecoder struct {
|
||||
file []byte
|
||||
audioExt string
|
||||
}
|
||||
|
||||
//goland:noinspection GoUnusedExportedFunction
|
||||
func NewRawDecoder(file []byte) Decoder {
|
||||
return &RawDecoder{file: file}
|
||||
}
|
||||
|
||||
func (d RawDecoder) Validate() error {
|
||||
return nil
|
||||
func (d *RawDecoder) Validate() error {
|
||||
for ext, sniffer := range snifferRegistry {
|
||||
if sniffer(d.file) {
|
||||
d.audioExt = strings.ToLower(ext)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("audio doesn't recognized")
|
||||
}
|
||||
|
||||
func (d RawDecoder) Decode() error {
|
||||
@ -27,21 +37,19 @@ func (d RawDecoder) GetAudioData() []byte {
|
||||
}
|
||||
|
||||
func (d RawDecoder) GetAudioExt() string {
|
||||
return "." + d.audioExt
|
||||
return d.audioExt
|
||||
}
|
||||
|
||||
func (d RawDecoder) GetMeta() Meta {
|
||||
return nil
|
||||
}
|
||||
func DecoderFuncWithExt(ext string) NewDecoderFunc {
|
||||
return func(file []byte) Decoder {
|
||||
return &RawDecoder{file: file, audioExt: ext}
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
/*RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
|
||||
RegisterDecoder("flac", DecoderFuncWithExt("flac"))
|
||||
RegisterDecoder("wav", DecoderFuncWithExt("wav"))
|
||||
RegisterDecoder("ogg", DecoderFuncWithExt("ogg"))
|
||||
RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))*/
|
||||
RegisterDecoder("mp3", true, NewRawDecoder)
|
||||
RegisterDecoder("flac", true, NewRawDecoder)
|
||||
RegisterDecoder("ogg", true, NewRawDecoder)
|
||||
RegisterDecoder("m4a", true, NewRawDecoder)
|
||||
RegisterDecoder("wav", true, NewRawDecoder)
|
||||
RegisterDecoder("wma", true, NewRawDecoder)
|
||||
RegisterDecoder("aac", true, NewRawDecoder)
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ import "bytes"
|
||||
type Sniffer func(header []byte) bool
|
||||
|
||||
var snifferRegistry = map[string]Sniffer{
|
||||
".m4a": SnifferM4A,
|
||||
".ogg": SnifferOGG,
|
||||
".mp3": SnifferMP3,
|
||||
".flac": SnifferFLAC,
|
||||
".ogg": SnifferOGG,
|
||||
".m4a": SnifferM4A,
|
||||
".wav": SnifferWAV,
|
||||
".wma": SnifferWMA,
|
||||
".mp3": SnifferMP3,
|
||||
".aac": SnifferAAC,
|
||||
".dff": SnifferDFF,
|
||||
}
|
||||
|
||||
func SniffAll(header []byte) (string, bool) {
|
||||
@ -42,3 +44,12 @@ func SnifferWAV(header []byte) bool {
|
||||
func SnifferWMA(header []byte) bool {
|
||||
return bytes.HasPrefix(header, []byte("\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00\xaa\x00\x62\xce\x6c"))
|
||||
}
|
||||
func SnifferAAC(header []byte) bool {
|
||||
return bytes.HasPrefix(header, []byte{0xFF, 0xF1})
|
||||
}
|
||||
|
||||
// SnifferDFF sniff a DSDIFF format
|
||||
// reference to: https://www.sonicstudio.com/pdf/dsd/DSDIFF_1.5_Spec.pdf
|
||||
func SnifferDFF(header []byte) bool {
|
||||
return bytes.HasPrefix(header, []byte("FRM8"))
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (d Decoder) GetAudioData() []byte {
|
||||
}
|
||||
|
||||
func (d Decoder) GetAudioExt() string {
|
||||
return ""
|
||||
return "" // use sniffer
|
||||
}
|
||||
|
||||
func (d Decoder) GetMeta() common.Meta {
|
||||
@ -58,9 +58,8 @@ func (d *Decoder) Validate() error {
|
||||
|
||||
d.key = d.file[0x1c:0x2c]
|
||||
d.key = append(d.key, 0x00)
|
||||
_ = d.file[0x2c:0x3c] //key2
|
||||
_ = d.file[0x2c:0x3c] //todo: key2
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (d *Decoder) Decode() error {
|
||||
@ -69,18 +68,15 @@ func (d *Decoder) Decode() error {
|
||||
lenData := len(dataEncrypted)
|
||||
initMask()
|
||||
if fullMaskLen < lenData {
|
||||
logging.Log().Warn("文件过大,处理后的音频不完整,请向我们报告此文件的信息")
|
||||
logging.Log().Warn("The file is too large and the processed audio is incomplete, " +
|
||||
"please report to us about this file at https://github.com/unlock-music/cli/issues")
|
||||
lenData = fullMaskLen
|
||||
}
|
||||
d.audio = make([]byte, lenData)
|
||||
|
||||
for i := 0; i < lenData; i++ {
|
||||
med8 := d.key[i%17] ^ dataEncrypted[i]
|
||||
med8 ^= (med8 & 0xf) << 4
|
||||
|
||||
msk8 := maskV2PreDef[i%272] ^ maskV2[i>>4]
|
||||
msk8 ^= (msk8 & 0xf) << 4
|
||||
d.audio[i] = med8 ^ msk8
|
||||
med8 := dataEncrypted[i] ^ d.key[i%17] ^ maskV2PreDef[i%(16*17)] ^ maskV2[i>>4]
|
||||
d.audio[i] = med8 ^ (med8&0xf)<<4
|
||||
}
|
||||
if d.isVpr {
|
||||
for i := 0; i < lenData; i++ {
|
||||
@ -91,8 +87,8 @@ func (d *Decoder) Decode() error {
|
||||
}
|
||||
func init() {
|
||||
// Kugou
|
||||
common.RegisterDecoder("kgm", NewDecoder)
|
||||
common.RegisterDecoder("kgma", NewDecoder)
|
||||
common.RegisterDecoder("kgm", false, NewDecoder)
|
||||
common.RegisterDecoder("kgma", false, NewDecoder)
|
||||
// Viper
|
||||
common.RegisterDecoder("vpr", NewDecoder)
|
||||
common.RegisterDecoder("vpr", false, NewDecoder)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/ulikunitz/xz"
|
||||
"github.com/unlock-music/cli/internal/logging"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
)
|
||||
|
||||
var maskDiffVpr = []byte{
|
||||
@ -41,7 +41,7 @@ var maskV2 []byte
|
||||
var fullMaskLen int
|
||||
var initMaskOK = false
|
||||
|
||||
//todo: 根据需求解压Mask大小
|
||||
//todo: decompress mask on demand
|
||||
func initMask() {
|
||||
if initMaskOK {
|
||||
return
|
||||
@ -50,7 +50,7 @@ func initMask() {
|
||||
if err != nil {
|
||||
logging.Log().Fatal("load kgm mask failed", zap.Error(err))
|
||||
}
|
||||
maskV2, err = ioutil.ReadAll(maskReader)
|
||||
maskV2, err = io.ReadAll(maskReader)
|
||||
if err != nil {
|
||||
logging.Log().Fatal("load kgm mask failed", zap.Error(err))
|
||||
}
|
||||
|
@ -124,5 +124,6 @@ func padOrTruncate(raw string, length int) string {
|
||||
|
||||
func init() {
|
||||
// Kuwo Mp3/Flac
|
||||
common.RegisterDecoder("kwm", NewDecoder)
|
||||
common.RegisterDecoder("kwm", false, NewDecoder)
|
||||
common.RegisterDecoder("kwm", false, common.NewRawDecoder)
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ func (d *Decoder) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//todo: 读取前进行检查长度,防止越界
|
||||
func (d *Decoder) readKeyData() error {
|
||||
if d.offsetKey == 0 || d.offsetKey+4 > d.fileLen {
|
||||
return errors.New("invalid cover file offset")
|
||||
@ -247,5 +246,5 @@ func (d Decoder) GetMeta() common.Meta {
|
||||
|
||||
func init() {
|
||||
// Netease Mp3/Flac
|
||||
common.RegisterDecoder("ncm", NewDecoder)
|
||||
common.RegisterDecoder("ncm", false, NewDecoder)
|
||||
}
|
||||
|
5
algo/qmc/cipher.go
Normal file
5
algo/qmc/cipher.go
Normal file
@ -0,0 +1,5 @@
|
||||
package qmc
|
||||
|
||||
type streamCipher interface {
|
||||
Decrypt(buf []byte, offset int)
|
||||
}
|
39
algo/qmc/cipher_map.go
Normal file
39
algo/qmc/cipher_map.go
Normal file
@ -0,0 +1,39 @@
|
||||
package qmc
|
||||
|
||||
import "errors"
|
||||
|
||||
type mapCipher struct {
|
||||
key []byte
|
||||
box []byte
|
||||
size int
|
||||
}
|
||||
|
||||
func NewMapCipher(key []byte) (*mapCipher, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, errors.New("qmc/cipher_map: invalid key size")
|
||||
}
|
||||
c := &mapCipher{key: key, size: len(key)}
|
||||
c.box = make([]byte, c.size)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *mapCipher) getMask(offset int) byte {
|
||||
if offset > 0x7FFF {
|
||||
offset %= 0x7FFF
|
||||
}
|
||||
idx := (offset*offset + 71214) % c.size
|
||||
return c.rotate(c.key[idx], byte(idx)&0x7)
|
||||
}
|
||||
|
||||
func (c *mapCipher) rotate(value byte, bits byte) byte {
|
||||
rotate := (bits + 4) % 8
|
||||
left := value << rotate
|
||||
right := value >> rotate
|
||||
return left | right
|
||||
}
|
||||
|
||||
func (c *mapCipher) Decrypt(buf []byte, offset int) {
|
||||
for i := 0; i < len(buf); i++ {
|
||||
buf[i] ^= c.getMask(offset + i)
|
||||
}
|
||||
}
|
53
algo/qmc/cipher_map_test.go
Normal file
53
algo/qmc/cipher_map_test.go
Normal file
@ -0,0 +1,53 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func loadTestDataMapCipher(name string) ([]byte, []byte, []byte, error) {
|
||||
key, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key.bin", name))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
raw, err := os.ReadFile(fmt.Sprintf("./testdata/%s_raw.bin", name))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
target, err := os.ReadFile(fmt.Sprintf("./testdata/%s_target.bin", name))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return key, raw, target, nil
|
||||
}
|
||||
func Test_mapCipher_Decrypt(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
wantErr bool
|
||||
}{
|
||||
{"mflac_map", false},
|
||||
{"mgg_map", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
key, raw, target, err := loadTestDataMapCipher(tt.name)
|
||||
if err != nil {
|
||||
t.Fatalf("load testing data failed: %s", err)
|
||||
}
|
||||
c, err := NewMapCipher(key)
|
||||
if err != nil {
|
||||
t.Errorf("init mapCipher failed: %s", err)
|
||||
return
|
||||
}
|
||||
c.Decrypt(raw, 0)
|
||||
if !reflect.DeepEqual(raw, target) {
|
||||
t.Error("overall")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
133
algo/qmc/cipher_rc4.go
Normal file
133
algo/qmc/cipher_rc4.go
Normal file
@ -0,0 +1,133 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// A rc4Cipher is an instance of RC4 using a particular key.
|
||||
type rc4Cipher struct {
|
||||
box []byte
|
||||
key []byte
|
||||
hash uint32
|
||||
boxTmp []byte
|
||||
}
|
||||
|
||||
// NewRC4Cipher creates and returns a new rc4Cipher. The key argument should be the
|
||||
// RC4 key, at least 1 byte and at most 256 bytes.
|
||||
func NewRC4Cipher(key []byte) (*rc4Cipher, error) {
|
||||
n := len(key)
|
||||
if n == 0 {
|
||||
return nil, errors.New("qmc/cipher_rc4: invalid key size")
|
||||
}
|
||||
|
||||
var c = rc4Cipher{key: key}
|
||||
c.box = make([]byte, n)
|
||||
c.boxTmp = make([]byte, n)
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
c.box[i] = byte(i)
|
||||
}
|
||||
|
||||
var j = 0
|
||||
for i := 0; i < n; i++ {
|
||||
j = (j + int(c.box[i]) + int(key[i%n])) % n
|
||||
c.box[i], c.box[j] = c.box[j], c.box[i]
|
||||
}
|
||||
c.getHashBase()
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *rc4Cipher) getHashBase() {
|
||||
c.hash = 1
|
||||
for i := 0; i < len(c.key); i++ {
|
||||
v := uint32(c.key[i])
|
||||
if v == 0 {
|
||||
continue
|
||||
}
|
||||
nextHash := c.hash * v
|
||||
if nextHash == 0 || nextHash <= c.hash {
|
||||
break
|
||||
}
|
||||
c.hash = nextHash
|
||||
}
|
||||
}
|
||||
|
||||
const rc4SegmentSize = 5120
|
||||
|
||||
func (c *rc4Cipher) Decrypt(src []byte, offset int) {
|
||||
toProcess := len(src)
|
||||
processed := 0
|
||||
markProcess := func(p int) (finished bool) {
|
||||
offset += p
|
||||
toProcess -= p
|
||||
processed += p
|
||||
return toProcess == 0
|
||||
}
|
||||
|
||||
if offset < 128 {
|
||||
blockSize := toProcess
|
||||
if blockSize > 128-offset {
|
||||
blockSize = 128 - offset
|
||||
}
|
||||
c.encFirstSegment(src[:blockSize], offset)
|
||||
if markProcess(blockSize) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if offset%rc4SegmentSize != 0 {
|
||||
blockSize := toProcess
|
||||
if blockSize > rc4SegmentSize-offset%rc4SegmentSize {
|
||||
blockSize = rc4SegmentSize - offset%rc4SegmentSize
|
||||
}
|
||||
k := src[processed : processed+blockSize]
|
||||
c.encASegment(k, offset)
|
||||
if markProcess(blockSize) {
|
||||
return
|
||||
}
|
||||
}
|
||||
for toProcess > rc4SegmentSize {
|
||||
c.encASegment(src[processed:processed+rc4SegmentSize], offset)
|
||||
markProcess(rc4SegmentSize)
|
||||
}
|
||||
|
||||
if toProcess > 0 {
|
||||
c.encASegment(src[processed:], offset)
|
||||
}
|
||||
}
|
||||
func (c *rc4Cipher) encFirstSegment(buf []byte, offset int) {
|
||||
n := len(c.box)
|
||||
for i := 0; i < len(buf); i++ {
|
||||
idx1 := offset + i
|
||||
segmentID := int(c.key[idx1%n])
|
||||
idx2 := int(float64(c.hash) / float64((idx1+1)*segmentID) * 100.0)
|
||||
buf[i] ^= c.key[idx2%n]
|
||||
}
|
||||
}
|
||||
|
||||
func (c *rc4Cipher) encASegment(buf []byte, offset int) {
|
||||
n := len(c.box)
|
||||
copy(c.boxTmp, c.box)
|
||||
|
||||
segmentID := (offset / rc4SegmentSize) & 0x1FF
|
||||
|
||||
if n <= segmentID {
|
||||
return
|
||||
}
|
||||
|
||||
idx2 := int64(float64(c.hash) /
|
||||
float64((offset/rc4SegmentSize+1)*int(c.key[segmentID])) *
|
||||
100.0)
|
||||
skipLen := int((idx2 & 0x1FF) + int64(offset%rc4SegmentSize))
|
||||
|
||||
j, k := 0, 0
|
||||
|
||||
for i := -skipLen; i < len(buf); i++ {
|
||||
j = (j + 1) % n
|
||||
k = (int(c.boxTmp[j]) + k) % n
|
||||
c.boxTmp[j], c.boxTmp[k] = c.boxTmp[k], c.boxTmp[j]
|
||||
if i >= 0 {
|
||||
buf[i] ^= c.boxTmp[int(c.boxTmp[j])+int(c.boxTmp[k])%n]
|
||||
}
|
||||
}
|
||||
}
|
90
algo/qmc/cipher_rc4_test.go
Normal file
90
algo/qmc/cipher_rc4_test.go
Normal file
@ -0,0 +1,90 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func loadTestRC4CipherData() ([]byte, []byte, []byte, error) {
|
||||
key, err := os.ReadFile("./testdata/mflac0_rc4_key.bin")
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
raw, err := os.ReadFile("./testdata/mflac0_rc4_raw.bin")
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
target, err := os.ReadFile("./testdata/mflac0_rc4_target.bin")
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return key, raw, target, nil
|
||||
}
|
||||
func Test_rc4Cipher_Decrypt(t *testing.T) {
|
||||
key, raw, target, err := loadTestRC4CipherData()
|
||||
if err != nil {
|
||||
t.Fatalf("load testing data failed: %s", err)
|
||||
}
|
||||
t.Run("overall", func(t *testing.T) {
|
||||
c, err := NewRC4Cipher(key)
|
||||
if err != nil {
|
||||
t.Errorf("init rc4Cipher failed: %s", err)
|
||||
return
|
||||
}
|
||||
c.Decrypt(raw, 0)
|
||||
if !reflect.DeepEqual(raw, target) {
|
||||
t.Error("overall")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_rc4Cipher_encFirstSegment(t *testing.T) {
|
||||
key, raw, target, err := loadTestRC4CipherData()
|
||||
if err != nil {
|
||||
t.Fatalf("load testing data failed: %s", err)
|
||||
}
|
||||
t.Run("first-block(0~128)", func(t *testing.T) {
|
||||
c, err := NewRC4Cipher(key)
|
||||
if err != nil {
|
||||
t.Errorf("init rc4Cipher failed: %s", err)
|
||||
return
|
||||
}
|
||||
c.Decrypt(raw[:128], 0)
|
||||
if !reflect.DeepEqual(raw[:128], target[:128]) {
|
||||
t.Error("first-block(0~128)")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_rc4Cipher_encASegment(t *testing.T) {
|
||||
key, raw, target, err := loadTestRC4CipherData()
|
||||
if err != nil {
|
||||
t.Fatalf("load testing data failed: %s", err)
|
||||
}
|
||||
|
||||
t.Run("align-block(128~5120)", func(t *testing.T) {
|
||||
c, err := NewRC4Cipher(key)
|
||||
if err != nil {
|
||||
t.Errorf("init rc4Cipher failed: %s", err)
|
||||
return
|
||||
}
|
||||
c.Decrypt(raw[128:5120], 128)
|
||||
if !reflect.DeepEqual(raw[128:5120], target[128:5120]) {
|
||||
t.Error("align-block(128~5120)")
|
||||
}
|
||||
})
|
||||
t.Run("simple-block(5120~10240)", func(t *testing.T) {
|
||||
c, err := NewRC4Cipher(key)
|
||||
if err != nil {
|
||||
t.Errorf("init rc4Cipher failed: %s", err)
|
||||
return
|
||||
}
|
||||
c.Decrypt(raw[5120:10240], 5120)
|
||||
if !reflect.DeepEqual(raw[5120:10240], target[5120:10240]) {
|
||||
t.Error("align-block(128~5120)")
|
||||
}
|
||||
})
|
||||
}
|
57
algo/qmc/cipher_static.go
Normal file
57
algo/qmc/cipher_static.go
Normal file
@ -0,0 +1,57 @@
|
||||
package qmc
|
||||
|
||||
func NewStaticCipher() *staticCipher {
|
||||
return &defaultStaticCipher
|
||||
}
|
||||
|
||||
var defaultStaticCipher = staticCipher{}
|
||||
|
||||
type staticCipher struct{}
|
||||
|
||||
func (c *staticCipher) Decrypt(buf []byte, offset int) {
|
||||
for i := 0; i < len(buf); i++ {
|
||||
buf[i] ^= c.getMask(offset + i)
|
||||
}
|
||||
}
|
||||
func (c *staticCipher) getMask(offset int) byte {
|
||||
if offset > 0x7FFF {
|
||||
offset %= 0x7FFF
|
||||
}
|
||||
idx := (offset*offset + 27) & 0xff
|
||||
return staticCipherBox[idx]
|
||||
}
|
||||
|
||||
var staticCipherBox = [...]byte{
|
||||
0x77, 0x48, 0x32, 0x73, 0xDE, 0xF2, 0xC0, 0xC8, //0x00
|
||||
0x95, 0xEC, 0x30, 0xB2, 0x51, 0xC3, 0xE1, 0xA0, //0x08
|
||||
0x9E, 0xE6, 0x9D, 0xCF, 0xFA, 0x7F, 0x14, 0xD1, //0x10
|
||||
0xCE, 0xB8, 0xDC, 0xC3, 0x4A, 0x67, 0x93, 0xD6, //0x18
|
||||
0x28, 0xC2, 0x91, 0x70, 0xCA, 0x8D, 0xA2, 0xA4, //0x20
|
||||
0xF0, 0x08, 0x61, 0x90, 0x7E, 0x6F, 0xA2, 0xE0, //0x28
|
||||
0xEB, 0xAE, 0x3E, 0xB6, 0x67, 0xC7, 0x92, 0xF4, //0x30
|
||||
0x91, 0xB5, 0xF6, 0x6C, 0x5E, 0x84, 0x40, 0xF7, //0x38
|
||||
0xF3, 0x1B, 0x02, 0x7F, 0xD5, 0xAB, 0x41, 0x89, //0x40
|
||||
0x28, 0xF4, 0x25, 0xCC, 0x52, 0x11, 0xAD, 0x43, //0x48
|
||||
0x68, 0xA6, 0x41, 0x8B, 0x84, 0xB5, 0xFF, 0x2C, //0x50
|
||||
0x92, 0x4A, 0x26, 0xD8, 0x47, 0x6A, 0x7C, 0x95, //0x58
|
||||
0x61, 0xCC, 0xE6, 0xCB, 0xBB, 0x3F, 0x47, 0x58, //0x60
|
||||
0x89, 0x75, 0xC3, 0x75, 0xA1, 0xD9, 0xAF, 0xCC, //0x68
|
||||
0x08, 0x73, 0x17, 0xDC, 0xAA, 0x9A, 0xA2, 0x16, //0x70
|
||||
0x41, 0xD8, 0xA2, 0x06, 0xC6, 0x8B, 0xFC, 0x66, //0x78
|
||||
0x34, 0x9F, 0xCF, 0x18, 0x23, 0xA0, 0x0A, 0x74, //0x80
|
||||
0xE7, 0x2B, 0x27, 0x70, 0x92, 0xE9, 0xAF, 0x37, //0x88
|
||||
0xE6, 0x8C, 0xA7, 0xBC, 0x62, 0x65, 0x9C, 0xC2, //0x90
|
||||
0x08, 0xC9, 0x88, 0xB3, 0xF3, 0x43, 0xAC, 0x74, //0x98
|
||||
0x2C, 0x0F, 0xD4, 0xAF, 0xA1, 0xC3, 0x01, 0x64, //0xA0
|
||||
0x95, 0x4E, 0x48, 0x9F, 0xF4, 0x35, 0x78, 0x95, //0xA8
|
||||
0x7A, 0x39, 0xD6, 0x6A, 0xA0, 0x6D, 0x40, 0xE8, //0xB0
|
||||
0x4F, 0xA8, 0xEF, 0x11, 0x1D, 0xF3, 0x1B, 0x3F, //0xB8
|
||||
0x3F, 0x07, 0xDD, 0x6F, 0x5B, 0x19, 0x30, 0x19, //0xC0
|
||||
0xFB, 0xEF, 0x0E, 0x37, 0xF0, 0x0E, 0xCD, 0x16, //0xC8
|
||||
0x49, 0xFE, 0x53, 0x47, 0x13, 0x1A, 0xBD, 0xA4, //0xD0
|
||||
0xF1, 0x40, 0x19, 0x60, 0x0E, 0xED, 0x68, 0x09, //0xD8
|
||||
0x06, 0x5F, 0x4D, 0xCF, 0x3D, 0x1A, 0xFE, 0x20, //0xE0
|
||||
0x77, 0xE4, 0xD9, 0xDA, 0xF9, 0xA4, 0x2B, 0x76, //0xE8
|
||||
0x1C, 0x71, 0xDB, 0x00, 0xBC, 0xFD, 0x0C, 0x6C, //0xF0
|
||||
0xA5, 0x47, 0xF7, 0xF6, 0x00, 0x79, 0x4A, 0x11, //0xF8
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package qmc
|
||||
|
||||
var oggPublicHeader1 = []byte{
|
||||
0x4f, 0x67, 0x67, 0x53, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x1e, 0x01, 0x76, 0x6f, 0x72,
|
||||
0x62, 0x69, 0x73, 0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xee, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x01, 0x4f, 0x67, 0x67, 0x53, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff}
|
||||
|
||||
var oggPublicHeader2 = []byte{
|
||||
0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73, 0x2c, 0x00, 0x00, 0x00, 0x58, 0x69, 0x70, 0x68, 0x2e,
|
||||
0x4f, 0x72, 0x67, 0x20, 0x6c, 0x69, 0x62, 0x56, 0x6f, 0x72, 0x62, 0x69, 0x73, 0x20, 0x49, 0x20,
|
||||
0x32, 0x30, 0x31, 0x35, 0x30, 0x31, 0x30, 0x35, 0x20, 0x28, 0xe2, 0x9b, 0x84, 0xe2, 0x9b, 0x84,
|
||||
0xe2, 0x9b, 0x84, 0xe2, 0x9b, 0x84, 0x29, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x54,
|
||||
0x49, 0x54, 0x4c, 0x45, 0x3d}
|
||||
|
||||
var oggPublicConfidence1 = []uint{
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0,
|
||||
0, 0, 9, 9, 9, 9, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 6, 3, 3, 3, 3, 6, 6, 6, 6,
|
||||
3, 3, 3, 3, 6, 6, 6, 6, 6, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 9, 9, 9, 9,
|
||||
0, 0, 0, 0}
|
||||
|
||||
var oggPublicConfidence2 = []uint{
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 0, 1, 3, 3, 0, 1, 3, 3, 3,
|
||||
3, 3, 3, 3, 3}
|
||||
|
||||
var (
|
||||
defaultKey256Mask44 = []byte{
|
||||
0xde, 0x51, 0xfa, 0xc3, 0x4a, 0xd6, 0xca, 0x90,
|
||||
0x7e, 0x67, 0x5e, 0xf7, 0xd5, 0x52, 0x84, 0xd8,
|
||||
0x47, 0x95, 0xbb, 0xa1, 0xaa, 0xc6, 0x66, 0x23,
|
||||
0x92, 0x62, 0xf3, 0x74, 0xa1, 0x9f, 0xf4, 0xa0,
|
||||
0x1d, 0x3f, 0x5b, 0xf0, 0x13, 0x0e, 0x09, 0x3d,
|
||||
0xf9, 0xbc, 0x00, 0x11}
|
||||
)
|
||||
var key256MappingAll [][]int //[idx256][idx128]idx44
|
||||
var key256Mapping128to44 map[int]int
|
||||
|
||||
func init() {
|
||||
{ // init all mapping
|
||||
key256MappingAll = make([][]int, 256)
|
||||
for i := 0; i < 128; i++ {
|
||||
realIdx := (i*i + 27) % 256
|
||||
if key256MappingAll[realIdx] == nil {
|
||||
key256MappingAll[realIdx] = []int{i}
|
||||
} else {
|
||||
key256MappingAll[realIdx] = append(key256MappingAll[realIdx], i)
|
||||
}
|
||||
}
|
||||
}
|
||||
{ // init
|
||||
key256Mapping128to44 = make(map[int]int, 128)
|
||||
idx44 := 0
|
||||
for _, all128 := range key256MappingAll {
|
||||
if all128 != nil {
|
||||
for _, _i128 := range all128 {
|
||||
key256Mapping128to44[_i128] = idx44
|
||||
}
|
||||
idx44++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
115
algo/qmc/key_dec.go
Normal file
115
algo/qmc/key_dec.go
Normal file
@ -0,0 +1,115 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"golang.org/x/crypto/tea"
|
||||
)
|
||||
|
||||
func simpleMakeKey(salt byte, length int) []byte {
|
||||
keyBuf := make([]byte, length)
|
||||
for i := 0; i < length; i++ {
|
||||
tmp := math.Tan(float64(salt) + float64(i)*0.1)
|
||||
keyBuf[i] = byte(math.Abs(tmp) * 100.0)
|
||||
}
|
||||
return keyBuf
|
||||
}
|
||||
func DecryptKey(rawKey []byte) ([]byte, error) {
|
||||
rawKeyDec := make([]byte, base64.StdEncoding.DecodedLen(len(rawKey)))
|
||||
n, err := base64.StdEncoding.Decode(rawKeyDec, rawKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n < 16 {
|
||||
return nil, errors.New("key length is too short")
|
||||
}
|
||||
rawKeyDec = rawKeyDec[:n]
|
||||
|
||||
simpleKey := simpleMakeKey(106, 8)
|
||||
teaKey := make([]byte, 16)
|
||||
for i := 0; i < 8; i++ {
|
||||
teaKey[i<<1] = simpleKey[i]
|
||||
teaKey[i<<1+1] = rawKeyDec[i]
|
||||
}
|
||||
|
||||
rs, err := decryptTencentTea(rawKeyDec[8:], teaKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(rawKeyDec[:8], rs...), nil
|
||||
}
|
||||
func decryptTencentTea(inBuf []byte, key []byte) ([]byte, error) {
|
||||
const saltLen = 2
|
||||
const zeroLen = 7
|
||||
if len(inBuf)%8 != 0 {
|
||||
return nil, errors.New("inBuf size not a multiple of the block size")
|
||||
}
|
||||
if len(inBuf) < 16 {
|
||||
return nil, errors.New("inBuf size too small")
|
||||
}
|
||||
|
||||
blk, err := tea.NewCipherWithRounds(key, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destBuf := make([]byte, 8)
|
||||
blk.Decrypt(destBuf, inBuf)
|
||||
padLen := int(destBuf[0] & 0x7)
|
||||
outLen := len(inBuf) - 1 - padLen - saltLen - zeroLen
|
||||
if padLen+saltLen != 8 {
|
||||
return nil, errors.New("invalid pad len")
|
||||
}
|
||||
out := make([]byte, outLen)
|
||||
|
||||
ivPrev := make([]byte, 8)
|
||||
ivCur := inBuf[:8]
|
||||
|
||||
inBufPos := 8
|
||||
|
||||
destIdx := 1 + padLen
|
||||
cryptBlock := func() {
|
||||
ivPrev = ivCur
|
||||
ivCur = inBuf[inBufPos : inBufPos+8]
|
||||
|
||||
xor8Bytes(destBuf, destBuf, inBuf[inBufPos:inBufPos+8])
|
||||
blk.Decrypt(destBuf, destBuf)
|
||||
|
||||
inBufPos += 8
|
||||
destIdx = 0
|
||||
}
|
||||
for i := 1; i <= saltLen; {
|
||||
if destIdx < 8 {
|
||||
destIdx++
|
||||
i++
|
||||
} else if destIdx == 8 {
|
||||
cryptBlock()
|
||||
}
|
||||
}
|
||||
|
||||
outPos := 0
|
||||
for outPos < outLen {
|
||||
if destIdx < 8 {
|
||||
out[outPos] = destBuf[destIdx] ^ ivPrev[destIdx]
|
||||
destIdx++
|
||||
outPos++
|
||||
} else if destIdx == 8 {
|
||||
cryptBlock()
|
||||
}
|
||||
}
|
||||
|
||||
for i := 1; i <= zeroLen; i++ {
|
||||
if destBuf[destIdx] != ivPrev[destIdx] {
|
||||
return nil, errors.New("zero check failed")
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
func xor8Bytes(dst, a, b []byte) {
|
||||
for i := 0; i < 8; i++ {
|
||||
dst[i] = a[i] ^ b[i]
|
||||
}
|
||||
}
|
56
algo/qmc/key_dec_test.go
Normal file
56
algo/qmc/key_dec_test.go
Normal file
@ -0,0 +1,56 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSimpleMakeKey(t *testing.T) {
|
||||
expect := []byte{0x69, 0x56, 0x46, 0x38, 0x2b, 0x20, 0x15, 0x0b}
|
||||
t.Run("106,8", func(t *testing.T) {
|
||||
if got := simpleMakeKey(106, 8); !reflect.DeepEqual(got, expect) {
|
||||
t.Errorf("simpleMakeKey() = %v, want %v", got, expect)
|
||||
}
|
||||
})
|
||||
}
|
||||
func loadDecryptKeyData(name string) ([]byte, []byte, error) {
|
||||
keyRaw, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key_raw.bin", name))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
keyDec, err := os.ReadFile(fmt.Sprintf("./testdata/%s_key.bin", name))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return keyRaw, keyDec, nil
|
||||
}
|
||||
func TestDecryptKey(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
filename string
|
||||
wantErr bool
|
||||
}{
|
||||
{"mflac0_rc4(512)", "mflac0_rc4", false},
|
||||
{"mflac_map(256)", "mflac_map", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
raw, want, err := loadDecryptKeyData(tt.filename)
|
||||
if err != nil {
|
||||
t.Fatalf("load test data failed: %s", err)
|
||||
}
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := DecryptKey(raw)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("DecryptKey() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("DecryptKey() got = %v..., want %v...",
|
||||
string(got[:32]), string(want[:32]))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/unlock-music/cli/algo/common"
|
||||
"github.com/unlock-music/cli/internal/logging"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrFailToMatchMask = errors.New("can not match at least one key")
|
||||
ErrTestDataLength = errors.New("invalid length of test file")
|
||||
ErrMaskLength128 = errors.New("incorrect mask length 128")
|
||||
ErrMaskLength44 = errors.New("incorrect mask length 44")
|
||||
ErrMaskDecode = errors.New("decode mask-128 to mask-58 failed")
|
||||
ErrDetectFlacMask = errors.New("can not detect mflac mask")
|
||||
ErrDetectMggMask = errors.New("can not detect mgg mask")
|
||||
)
|
||||
|
||||
type Key256Mask struct {
|
||||
matrix []byte // Mask 128
|
||||
}
|
||||
|
||||
func NewKey256FromMask128(mask128 []byte) (*Key256Mask, error) {
|
||||
if len(mask128) != 128 {
|
||||
return nil, ErrMaskLength128
|
||||
}
|
||||
q := &Key256Mask{matrix: mask128}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func NewKey256FromMask44(mask44 []byte) (*Key256Mask, error) {
|
||||
mask128, err := convertKey256Mask44to128(mask44)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := &Key256Mask{matrix: mask128}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (q *Key256Mask) getMatrix44() (mask44 []byte, err error) {
|
||||
if len(q.matrix) != 128 {
|
||||
return nil, ErrMaskLength128
|
||||
}
|
||||
matrix44 := make([]byte, 44)
|
||||
idx44 := 0
|
||||
for _, it256 := range key256MappingAll {
|
||||
if it256 != nil {
|
||||
it256Len := len(it256)
|
||||
for i := 1; i < it256Len; i++ {
|
||||
if q.matrix[it256[0]] != q.matrix[it256[i]] {
|
||||
return nil, ErrMaskDecode
|
||||
}
|
||||
}
|
||||
q.matrix[idx44] = q.matrix[it256[0]]
|
||||
idx44++
|
||||
}
|
||||
}
|
||||
return matrix44, nil
|
||||
}
|
||||
|
||||
func (q *Key256Mask) Decrypt(data []byte) []byte {
|
||||
dst := make([]byte, len(data))
|
||||
index := -1
|
||||
maskIdx := -1
|
||||
for cur := 0; cur < len(data); cur++ {
|
||||
index++
|
||||
maskIdx++
|
||||
if index == 0x8000 || (index > 0x8000 && (index+1)%0x8000 == 0) {
|
||||
index++
|
||||
maskIdx++
|
||||
}
|
||||
if maskIdx >= 128 {
|
||||
maskIdx -= 128
|
||||
}
|
||||
dst[cur] = data[cur] ^ q.matrix[maskIdx]
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
func convertKey256Mask44to128(mask44 []byte) ([]byte, error) {
|
||||
if len(mask44) != 44 {
|
||||
return nil, ErrMaskLength44
|
||||
}
|
||||
mask128 := make([]byte, 128)
|
||||
idx44 := 0
|
||||
for _, it256 := range key256MappingAll {
|
||||
if it256 != nil {
|
||||
for _, idx128 := range it256 {
|
||||
mask128[idx128] = mask44[idx44]
|
||||
}
|
||||
idx44++
|
||||
}
|
||||
}
|
||||
return mask128, nil
|
||||
}
|
||||
|
||||
func getDefaultMask() *Key256Mask {
|
||||
y, _ := NewKey256FromMask44(defaultKey256Mask44)
|
||||
return y
|
||||
}
|
||||
|
||||
func detectMflac256Mask(input []byte) (*Key256Mask, error) {
|
||||
var q *Key256Mask
|
||||
var rtErr = ErrDetectFlacMask
|
||||
|
||||
lenData := len(input)
|
||||
lenTest := 0x8000
|
||||
if lenData < 0x8000 {
|
||||
lenTest = lenData
|
||||
}
|
||||
|
||||
for blockIdx := 0; blockIdx < lenTest; blockIdx += 128 {
|
||||
var err error
|
||||
q, err = NewKey256FromMask128(input[blockIdx : blockIdx+128])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if common.SnifferFLAC(q.Decrypt(input[:4])) {
|
||||
rtErr = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
return q, rtErr
|
||||
}
|
||||
|
||||
func detectMgg256Mask(input []byte) (*Key256Mask, error) {
|
||||
if len(input) < 0x100 {
|
||||
return nil, ErrTestDataLength
|
||||
}
|
||||
|
||||
matrixConf := make([]map[uint8]uint, 44) //meaning: [idx58][value]confidence
|
||||
for i := uint(0); i < 44; i++ {
|
||||
matrixConf[i] = make(map[uint8]uint)
|
||||
}
|
||||
|
||||
page2size := input[0x54] ^ input[0xC] ^ oggPublicHeader1[0xC]
|
||||
spHeader, spConf := generateOggFullHeader(int(page2size))
|
||||
lenTest := len(spHeader)
|
||||
|
||||
for idx128 := 0; idx128 < lenTest; idx128++ {
|
||||
confidence := spConf[idx128]
|
||||
if confidence > 0 {
|
||||
mask := input[idx128] ^ spHeader[idx128]
|
||||
|
||||
idx44 := key256Mapping128to44[idx128&0x7f] // equals: [idx128 % 128]
|
||||
if _, ok2 := matrixConf[idx44][mask]; ok2 {
|
||||
matrixConf[idx44][mask] += confidence
|
||||
} else {
|
||||
matrixConf[idx44][mask] = confidence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix := make([]uint8, 44)
|
||||
var err error
|
||||
for i := uint(0); i < 44; i++ {
|
||||
matrix[i], err = decideMgg256MaskItemConf(matrixConf[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
q, err := NewKey256FromMask44(matrix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if common.SnifferOGG(q.Decrypt(input[:4])) {
|
||||
return q, nil
|
||||
}
|
||||
return nil, ErrDetectMggMask
|
||||
}
|
||||
|
||||
func generateOggFullHeader(pageSize int) ([]byte, []uint) {
|
||||
spec := make([]byte, pageSize+1)
|
||||
|
||||
spec[0], spec[1], spec[pageSize] = uint8(pageSize), 0xFF, 0xFF
|
||||
for i := 2; i < pageSize; i++ {
|
||||
spec[i] = 0xFF
|
||||
}
|
||||
specConf := make([]uint, pageSize+1)
|
||||
specConf[0], specConf[1], specConf[pageSize] = 6, 0, 0
|
||||
for i := 2; i < pageSize; i++ {
|
||||
specConf[i] = 4
|
||||
}
|
||||
allConf := append(oggPublicConfidence1, specConf...)
|
||||
allConf = append(allConf, oggPublicConfidence2...)
|
||||
|
||||
allHeader := bytes.Join(
|
||||
[][]byte{oggPublicHeader1, spec, oggPublicHeader2},
|
||||
[]byte{},
|
||||
)
|
||||
return allHeader, allConf
|
||||
}
|
||||
|
||||
func decideMgg256MaskItemConf(confidence map[uint8]uint) (uint8, error) {
|
||||
lenConf := len(confidence)
|
||||
if lenConf == 0 {
|
||||
return 0xff, ErrFailToMatchMask
|
||||
} else if lenConf > 1 {
|
||||
logging.Log().Warn("there are 2 potential value for the mask", zap.Any("confidence", confidence))
|
||||
}
|
||||
result := uint8(0)
|
||||
conf := uint(0)
|
||||
for idx, item := range confidence {
|
||||
if item > conf {
|
||||
result = idx
|
||||
conf = item
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
307
algo/qmc/qmc.go
307
algo/qmc/qmc.go
@ -1,128 +1,263 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/unlock-music/cli/algo/common"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrQmcFileLength = errors.New("invalid qmc file length")
|
||||
ErrQmcKeyDecodeFailed = errors.New("base64 decode qmc key failed")
|
||||
ErrQmcKeyLength = errors.New("unexpected decoded qmc key length")
|
||||
)
|
||||
|
||||
type Decoder struct {
|
||||
file []byte
|
||||
maskDetector func(encodedData []byte) (*Key256Mask, error)
|
||||
mask *Key256Mask
|
||||
audioExt string
|
||||
key []byte
|
||||
audio []byte
|
||||
r io.ReadSeeker
|
||||
fileExt string
|
||||
|
||||
audioLen int
|
||||
decodedKey []byte
|
||||
cipher streamCipher
|
||||
offset int
|
||||
|
||||
rawMetaExtra1 int
|
||||
rawMetaExtra2 int
|
||||
}
|
||||
|
||||
func NewMflac256Decoder(data []byte) common.Decoder {
|
||||
return &Decoder{file: data, maskDetector: detectMflac256Mask, audioExt: "flac"}
|
||||
// Read implements io.Reader, offer the decrypted audio data.
|
||||
// Validate should call before Read to check if the file is valid.
|
||||
func (d *Decoder) Read(p []byte) (int, error) {
|
||||
n := len(p)
|
||||
if d.audioLen-d.offset <= 0 {
|
||||
return 0, io.EOF
|
||||
} else if d.audioLen-d.offset < n {
|
||||
n = d.audioLen - d.offset
|
||||
}
|
||||
m, err := d.r.Read(p[:n])
|
||||
if m == 0 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
d.cipher.Decrypt(p[:m], d.offset)
|
||||
d.offset += m
|
||||
return m, err
|
||||
}
|
||||
|
||||
func NewMgg256Decoder(data []byte) common.Decoder {
|
||||
return &Decoder{file: data, maskDetector: detectMgg256Mask, audioExt: "ogg"}
|
||||
func NewDecoder(r io.ReadSeeker) (*Decoder, error) {
|
||||
d := &Decoder{r: r}
|
||||
err := d.searchKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(d.decodedKey) > 300 {
|
||||
d.cipher, err = NewRC4Cipher(d.decodedKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if len(d.decodedKey) != 0 {
|
||||
d.cipher, err = NewMapCipher(d.decodedKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
d.cipher = NewStaticCipher()
|
||||
}
|
||||
|
||||
_, err = d.r.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (d *Decoder) Validate() error {
|
||||
if nil != d.mask {
|
||||
return nil
|
||||
}
|
||||
if nil != d.maskDetector {
|
||||
if err := d.validateKey(); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
d.mask, err = d.maskDetector(d.file)
|
||||
buf := make([]byte, 16)
|
||||
if _, err := io.ReadFull(d.r, buf); err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.New("no mask or mask detector found")
|
||||
}
|
||||
|
||||
func (d *Decoder) validateKey() error {
|
||||
lenData := len(d.file)
|
||||
if lenData < 4 {
|
||||
return ErrQmcFileLength
|
||||
}
|
||||
|
||||
keyLen := binary.LittleEndian.Uint32(d.file[lenData-4:])
|
||||
if lenData < int(keyLen+4) {
|
||||
return ErrQmcFileLength
|
||||
}
|
||||
var err error
|
||||
d.key, err = base64.StdEncoding.DecodeString(
|
||||
string(d.file[lenData-4-int(keyLen) : lenData-4]))
|
||||
_, err := d.r.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
return ErrQmcKeyDecodeFailed
|
||||
return err
|
||||
}
|
||||
|
||||
if len(d.key) != 272 {
|
||||
return ErrQmcKeyLength
|
||||
d.cipher.Decrypt(buf, 0)
|
||||
fileExt, ok := common.SniffAll(buf)
|
||||
if !ok {
|
||||
return errors.New("detect file type failed")
|
||||
}
|
||||
d.file = d.file[:lenData-4-int(keyLen)]
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (d *Decoder) Decode() error {
|
||||
d.audio = d.mask.Decrypt(d.file)
|
||||
d.fileExt = fileExt
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Decoder) GetCoverImage() []byte {
|
||||
func (d Decoder) GetFileExt() string {
|
||||
return d.fileExt
|
||||
}
|
||||
|
||||
func (d *Decoder) searchKey() error {
|
||||
fileSizeM4, err := d.r.Seek(-4, io.SeekEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf, err := io.ReadAll(io.LimitReader(d.r, 4))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(buf) == "QTag" {
|
||||
if err := d.readRawMetaQTag(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
size := binary.LittleEndian.Uint32(buf)
|
||||
if size < 0x300 && size != 0 {
|
||||
return d.readRawKey(int64(size))
|
||||
} else {
|
||||
// try to use default static cipher
|
||||
d.audioLen = int(fileSizeM4 + 4)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Decoder) GetAudioData() []byte {
|
||||
return d.audio
|
||||
}
|
||||
|
||||
func (d Decoder) GetAudioExt() string {
|
||||
if d.audioExt != "" {
|
||||
return "." + d.audioExt
|
||||
func (d *Decoder) readRawKey(rawKeyLen int64) error {
|
||||
audioLen, err := d.r.Seek(-(4 + rawKeyLen), io.SeekEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.audioLen = int(audioLen)
|
||||
|
||||
rawKeyData, err := io.ReadAll(io.LimitReader(d.r, rawKeyLen))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.decodedKey, err = DecryptKey(rawKeyData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (d Decoder) GetMeta() common.Meta {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
|
||||
return func(file []byte) common.Decoder {
|
||||
return &Decoder{file: file, audioExt: ext, mask: getDefaultMask()}
|
||||
func (d *Decoder) readRawMetaQTag() error {
|
||||
// get raw meta data len
|
||||
if _, err := d.r.Seek(-8, io.SeekEnd); err != nil {
|
||||
return err
|
||||
}
|
||||
buf, err := io.ReadAll(io.LimitReader(d.r, 4))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rawMetaLen := int64(binary.BigEndian.Uint32(buf))
|
||||
|
||||
// read raw meta data
|
||||
audioLen, err := d.r.Seek(-(8 + rawMetaLen), io.SeekEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.audioLen = int(audioLen)
|
||||
rawMetaData, err := io.ReadAll(io.LimitReader(d.r, rawMetaLen))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
items := strings.Split(string(rawMetaData), ",")
|
||||
if len(items) != 3 {
|
||||
return errors.New("invalid raw meta data")
|
||||
}
|
||||
|
||||
d.decodedKey, err = DecryptKey([]byte(items[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.rawMetaExtra1, err = strconv.Atoi(items[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.rawMetaExtra2, err = strconv.Atoi(items[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//goland:noinspection SpellCheckingInspection
|
||||
func init() {
|
||||
common.RegisterDecoder("qmc0", DecoderFuncWithExt("mp3")) //QQ Music Mp3
|
||||
common.RegisterDecoder("qmc3", DecoderFuncWithExt("mp3")) //QQ Music Mp3
|
||||
supportedExts := []string{
|
||||
"qmc0", "qmc3", //QQ Music MP3
|
||||
"qmc2", "qmc4", "qmc6", "qmc8", //QQ Music M4A
|
||||
"qmcflac", //QQ Music FLAC
|
||||
"qmcogg", //QQ Music OGG
|
||||
|
||||
common.RegisterDecoder("qmc2", DecoderFuncWithExt("m4a")) //QQ Music M4A
|
||||
common.RegisterDecoder("qmc4", DecoderFuncWithExt("m4a")) //QQ Music M4A
|
||||
common.RegisterDecoder("qmc6", DecoderFuncWithExt("m4a")) //QQ Music M4A
|
||||
common.RegisterDecoder("qmc8", DecoderFuncWithExt("m4a")) //QQ Music M4A
|
||||
"tkm", //QQ Music Accompaniment M4A
|
||||
"bkcmp3", //Moo Music Mp3
|
||||
"bkcflac", //Moo Music Flac
|
||||
|
||||
common.RegisterDecoder("qmcflac", DecoderFuncWithExt("flac")) //QQ Music Flac
|
||||
common.RegisterDecoder("qmcogg", DecoderFuncWithExt("ogg")) //QQ Music Ogg
|
||||
common.RegisterDecoder("tkm", DecoderFuncWithExt("m4a")) //QQ Music Accompaniment M4a
|
||||
"666c6163", //QQ Music Weiyun Flac
|
||||
"6d7033", //QQ Music Weiyun Mp3
|
||||
"6f6767", //QQ Music Weiyun Ogg
|
||||
"6d3461", //QQ Music Weiyun M4a
|
||||
"776176", //QQ Music Weiyun Wav
|
||||
|
||||
common.RegisterDecoder("bkcmp3", DecoderFuncWithExt("mp3")) //Moo Music Mp3
|
||||
common.RegisterDecoder("bkcflac", DecoderFuncWithExt("flac")) //Moo Music Flac
|
||||
|
||||
common.RegisterDecoder("666c6163", DecoderFuncWithExt("flac")) //QQ Music Weiyun Flac
|
||||
common.RegisterDecoder("6d7033", DecoderFuncWithExt("mp3")) //QQ Music Weiyun Mp3
|
||||
common.RegisterDecoder("6f6767", DecoderFuncWithExt("ogg")) //QQ Music Weiyun Ogg
|
||||
common.RegisterDecoder("6d3461", DecoderFuncWithExt("m4a")) //QQ Music Weiyun M4a
|
||||
common.RegisterDecoder("776176", DecoderFuncWithExt("wav")) //QQ Music Weiyun Wav
|
||||
|
||||
common.RegisterDecoder("mgg", NewMgg256Decoder) //QQ Music New Ogg
|
||||
common.RegisterDecoder("mflac", NewMflac256Decoder) //QQ Music New Flac
|
||||
"mgg", "mgg1", //QQ Music New Ogg
|
||||
"mflac", "mflac0", //QQ Music New Flac
|
||||
}
|
||||
for _, ext := range supportedExts {
|
||||
common.RegisterDecoder(ext, false, newCompactDecoder)
|
||||
}
|
||||
}
|
||||
|
||||
type compactDecoder struct {
|
||||
decoder *Decoder
|
||||
createErr error
|
||||
buf *bytes.Buffer
|
||||
}
|
||||
|
||||
func newCompactDecoder(p []byte) common.Decoder {
|
||||
r := bytes.NewReader(p)
|
||||
d, err := NewDecoder(r)
|
||||
c := compactDecoder{
|
||||
decoder: d,
|
||||
createErr: err,
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *compactDecoder) Validate() error {
|
||||
if c.createErr != nil {
|
||||
return c.createErr
|
||||
}
|
||||
return c.decoder.Validate()
|
||||
}
|
||||
|
||||
func (c *compactDecoder) Decode() error {
|
||||
if c.createErr != nil {
|
||||
return c.createErr
|
||||
}
|
||||
c.buf = bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(c.buf, c.decoder)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *compactDecoder) GetCoverImage() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *compactDecoder) GetAudioData() []byte {
|
||||
return c.buf.Bytes()
|
||||
}
|
||||
|
||||
func (c *compactDecoder) GetAudioExt() string {
|
||||
if c.createErr != nil {
|
||||
return ""
|
||||
}
|
||||
return c.decoder.GetFileExt()
|
||||
}
|
||||
|
||||
func (c *compactDecoder) GetMeta() common.Meta {
|
||||
return nil
|
||||
}
|
||||
|
98
algo/qmc/qmc_test.go
Normal file
98
algo/qmc/qmc_test.go
Normal file
@ -0,0 +1,98 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func loadTestDataQmcDecoder(filename string) ([]byte, []byte, error) {
|
||||
encBody, err := os.ReadFile(fmt.Sprintf("./testdata/%s_raw.bin", filename))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
encSuffix, err := os.ReadFile(fmt.Sprintf("./testdata/%s_suffix.bin", filename))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
target, err := os.ReadFile(fmt.Sprintf("./testdata/%s_target.bin", filename))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return bytes.Join([][]byte{encBody, encSuffix}, nil), target, nil
|
||||
|
||||
}
|
||||
func TestMflac0Decoder_Read(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
wantErr bool
|
||||
}{
|
||||
{"mflac0_rc4", false},
|
||||
{"mflac_map", false},
|
||||
{"mgg_map", false},
|
||||
{"qmc0_static", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
raw, target, err := loadTestDataQmcDecoder(tt.name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
d, err := NewDecoder(bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
buf := make([]byte, len(target))
|
||||
if _, err := io.ReadFull(d, buf); err != nil {
|
||||
t.Errorf("read bytes from decoder error = %v", err)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(buf, target) {
|
||||
t.Errorf("Decrypt() got = %v, want %v", buf[:32], target[:32])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMflac0Decoder_Validate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fileExt string
|
||||
wantErr bool
|
||||
}{
|
||||
{"mflac0_rc4", ".flac", false},
|
||||
{"mflac_map", ".flac", false},
|
||||
{"mgg_map", ".ogg", false},
|
||||
{"qmc0_static", ".mp3", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
raw, _, err := loadTestDataQmcDecoder(tt.name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d, err := NewDecoder(bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := d.Validate(); err != nil {
|
||||
t.Errorf("read bytes from decoder error = %v", err)
|
||||
return
|
||||
}
|
||||
if tt.fileExt != d.GetFileExt() {
|
||||
t.Errorf("Decrypt() got = %v, want %v", d.GetFileExt(), tt.fileExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
1
algo/qmc/testdata/mflac0_rc4_key.bin
vendored
Normal file
1
algo/qmc/testdata/mflac0_rc4_key.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
dRzX3p5ZYqAlp7lLSs9Zr0rw1iEZy23bB670x4ch2w97x14Zwpk1UXbKU4C2sOS7uZ0NB5QM7ve9GnSrr2JHxP74hVNONwVV77CdOOVb807317KvtI5Yd6h08d0c5W88rdV46C235YGDjUSZj5314YTzy0b6vgh4102P7E273r911Nl464XV83Hr00rkAHkk791iMGSJH95GztN28u2Nv5s9Xx38V69o4a8aIXxbx0g1EM0623OEtbtO9zsqCJfj6MhU7T8iVS6M3q19xhq6707E6r7wzPO6Yp4BwBmgg4F95Lfl0vyF7YO6699tb5LMnr7iFx29o98hoh3O3Rd8h9Juu8P1wG7vdnO5YtRlykhUluYQblNn7XwjBJ53HAyKVraWN5dG7pv7OMl1s0RykPh0p23qfYzAAMkZ1M422pEd07TA9OCKD1iybYxWH06xj6A8mzmcnYGT9P1a5Ytg2EF5LG3IknL2r3AUz99Y751au6Cr401mfAWK68WyEBe5
|
1
algo/qmc/testdata/mflac0_rc4_key_raw.bin
vendored
Normal file
1
algo/qmc/testdata/mflac0_rc4_key_raw.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
ZFJ6WDNwNVrjEJZB1o6QjkQV2ZbHSw/2Eb00q1+4z9SVWYyFWO1PcSQrJ5326ubLklmk2ab3AEyIKNUu8DFoAoAc9dpzpTmc+pdkBHjM/bW2jWx+dCyC8vMTHE+DHwaK14UEEGW47ZXMDi7PRCQ2Jpm/oXVdHTIlyrc+bRmKfMith0L2lFQ+nW8CCjV6ao5ydwkZhhNOmRdrCDcUXSJH9PveYwra9/wAmGKWSs9nemuMWKnbjp1PkcxNQexicirVTlLX7PVgRyFyzNyUXgu+R2S4WTmLwjd8UsOyW/dc2mEoYt+vY2lq1X4hFBtcQGOAZDeC+mxrN0EcW8tjS6P4TjOjiOKNMxIfMGSWkSKL3H7z5K7nR1AThW20H2bP/LcpsdaL0uZ/js1wFGpdIfFx9rnLC78itL0WwDleIqp9TBMX/NwakGgIPIbjBwfgyD8d8XKYuLEscIH0ZGdjsadB5XjybgdE3ppfeFEcQiqpnodlTaQRm3KDIF9ATClP0mTl8XlsSojsZ468xseS1Ib2iinx/0SkK3UtJDwp8DH3/+ELisgXd69Bf0pve7wbrQzzMUs9/Ogvvo6ULsIkQfApJ8cSegDYklzGXiLNH7hZYnXDLLSNejD7NvQouULSmGsBbGzhZ5If0NP/6AhSbpzqWLDlabTDgeWWnFeZpBnlK6SMxo+YFFk1Y0XLKsd69+jj
|
BIN
algo/qmc/testdata/mflac0_rc4_raw.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac0_rc4_raw.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mflac0_rc4_suffix.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac0_rc4_suffix.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mflac0_rc4_target.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac0_rc4_target.bin
vendored
Normal file
Binary file not shown.
1
algo/qmc/testdata/mflac_map_key.bin
vendored
Normal file
1
algo/qmc/testdata/mflac_map_key.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
yw7xWOyNQ8585Jwx3hjB49QLPKi38F89awnrQ0fq66NT9TDq1ppHNrFqhaDrU5AFk916D58I53h86304GqOFCCyFzBem68DqiXJ81bILEQwG3P3MOnoNzM820kNW9Lv9IJGNn9Xo497p82BLTm4hAX8JLBs0T2pilKvT429sK9jfg508GSk4d047Jxdz5Fou4aa33OkyFRBU3x430mgNBn04Lc9BzXUI2IGYXv3FGa9qE4Vb54kSjVv8ogbg47j3
|
1
algo/qmc/testdata/mflac_map_key_raw.bin
vendored
Normal file
1
algo/qmc/testdata/mflac_map_key_raw.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
eXc3eFdPeU6+3f7GVeF35bMpIEIQj5JWOWt7G+jsR68Hx3BUFBavkTQ8dpPdP0XBIwPe+OfdsnTGVQqPyg3GCtQSrkgA0mwSQdr4DPzKLkEZFX+Cf1V6ChyipOuC6KT37eAxWMdV1UHf9/OCvydr1dc6SWK1ijRUcP6IAHQhiB+mZLay7XXrSPo32WjdBkn9c9sa2SLtI48atj5kfZ4oOq6QGeld2JA3Z+3wwCe6uTHthKaEHY8ufDYodEe3qqrjYpzkdx55pCtxCQa1JiNqFmJigWm4m3CDzhuJ7YqnjbD+mXxLi7BP1+z4L6nccE2h+DGHVqpGjR9+4LBpe4WHB4DrAzVp2qQRRQJxeHd1v88=
|
BIN
algo/qmc/testdata/mflac_map_raw.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac_map_raw.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mflac_map_suffix.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac_map_suffix.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mflac_map_target.bin
vendored
Normal file
BIN
algo/qmc/testdata/mflac_map_target.bin
vendored
Normal file
Binary file not shown.
1
algo/qmc/testdata/mgg_map_key.bin
vendored
Normal file
1
algo/qmc/testdata/mgg_map_key.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
zGxNk54pKJ0hDkAo80wHE80ycSWQ7z4m4E846zVy2sqCn14F42Y5S7GqeR11WpOV75sDLbE5dFP992t88l0pHy1yAQ49YK6YX6c543drBYLo55Hc4Y0Fyic6LQPiGqu2bG31r8vaq9wS9v63kg0X5VbnOD6RhO4t0RRhk3ajrA7p0iIy027z0L70LZjtw6E18H0D41nz6ASTx71otdF9z1QNC0JmCl51xvnb39zPExEXyKkV47S6QsK5hFh884QJ
|
1
algo/qmc/testdata/mgg_map_key_raw.bin
vendored
Normal file
1
algo/qmc/testdata/mgg_map_key_raw.bin
vendored
Normal file
@ -0,0 +1 @@
|
||||
ekd4Tms1NHC53JEDO/AKVyF+I0bj0hHB7CZeoLDGSApaQB9Oo/pJTBGA/RO+nk5RXLXdHsffLiY4e8kt3LNo6qMl7S89vkiSFxx4Uoq4bGDJ7Jc+bYL6lLsa3M4sBvXS4XcPChrMDz+LmrJMGG6ua2fYyIz1d6TCRUBf1JJgCIkBbDAEeMVYc13qApitiz/apGAPmAnveCaDhfD5GxWsF+RfQ2OcnvrnIXe80Feh/0jx763DlsOBI3eIede6t5zYHokWkZmVEF1jMrnlvsgbQK2EzUWMblmLMsTKNILyZazEoKUyulqmyLO/c/KYE+USPOXPcbjlYFmLhSGHK7sQB5aBR153Yp+xh61ooh2NGAA=
|
BIN
algo/qmc/testdata/mgg_map_raw.bin
vendored
Normal file
BIN
algo/qmc/testdata/mgg_map_raw.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mgg_map_suffix.bin
vendored
Normal file
BIN
algo/qmc/testdata/mgg_map_suffix.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/mgg_map_target.bin
vendored
Normal file
BIN
algo/qmc/testdata/mgg_map_target.bin
vendored
Normal file
Binary file not shown.
BIN
algo/qmc/testdata/qmc0_static_raw.bin
vendored
Normal file
BIN
algo/qmc/testdata/qmc0_static_raw.bin
vendored
Normal file
Binary file not shown.
0
algo/qmc/testdata/qmc0_static_suffix.bin
vendored
Normal file
0
algo/qmc/testdata/qmc0_static_suffix.bin
vendored
Normal file
BIN
algo/qmc/testdata/qmc0_static_target.bin
vendored
Normal file
BIN
algo/qmc/testdata/qmc0_static_target.bin
vendored
Normal file
Binary file not shown.
@ -70,10 +70,10 @@ func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
|
||||
|
||||
func init() {
|
||||
// QQ Music IOS M4a
|
||||
common.RegisterDecoder("tm2", DecoderFuncWithExt("m4a"))
|
||||
common.RegisterDecoder("tm6", DecoderFuncWithExt("m4a"))
|
||||
common.RegisterDecoder("tm2", false, DecoderFuncWithExt("m4a"))
|
||||
common.RegisterDecoder("tm6", false, DecoderFuncWithExt("m4a"))
|
||||
// QQ Music IOS Mp3
|
||||
common.RegisterDecoder("tm0", common.DecoderFuncWithExt("mp3"))
|
||||
common.RegisterDecoder("tm3", common.DecoderFuncWithExt("mp3"))
|
||||
common.RegisterDecoder("tm0", false, common.NewRawDecoder)
|
||||
common.RegisterDecoder("tm3", false, common.NewRawDecoder)
|
||||
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ func DecoderFuncWithExt(ext string) common.NewDecoderFunc {
|
||||
|
||||
func init() {
|
||||
// Xiami Wav/M4a/Mp3/Flac
|
||||
common.RegisterDecoder("xm", NewDecoder)
|
||||
common.RegisterDecoder("xm", false, NewDecoder)
|
||||
// Xiami Typed Format
|
||||
common.RegisterDecoder("wav", DecoderFuncWithExt("wav"))
|
||||
common.RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
|
||||
common.RegisterDecoder("flac", DecoderFuncWithExt("flac"))
|
||||
common.RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))
|
||||
common.RegisterDecoder("wav", false, DecoderFuncWithExt("wav"))
|
||||
common.RegisterDecoder("mp3", false, DecoderFuncWithExt("mp3"))
|
||||
common.RegisterDecoder("flac", false, DecoderFuncWithExt("flac"))
|
||||
common.RegisterDecoder("m4a", false, DecoderFuncWithExt("m4a"))
|
||||
}
|
||||
|
@ -2,6 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/unlock-music/cli/algo/common"
|
||||
_ "github.com/unlock-music/cli/algo/kgm"
|
||||
_ "github.com/unlock-music/cli/algo/kwm"
|
||||
@ -10,41 +20,61 @@ import (
|
||||
_ "github.com/unlock-music/cli/algo/tm"
|
||||
_ "github.com/unlock-music/cli/algo/xm"
|
||||
"github.com/unlock-music/cli/internal/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var AppVersion = "0.0.4"
|
||||
var AppVersion = "v0.0.6"
|
||||
|
||||
func main() {
|
||||
app := cli.App{
|
||||
Name: "Unlock Music CLI",
|
||||
HelpName: "um",
|
||||
Usage: "Unlock your encrypted music file https://github.com/unlock-music/cli",
|
||||
Version: AppVersion,
|
||||
Version: fmt.Sprintf("%s (%s,%s/%s)", AppVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: false},
|
||||
&cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: false},
|
||||
&cli.BoolFlag{Name: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true},
|
||||
&cli.BoolFlag{Name: "supported-ext", Usage: "Show supported file extensions and exit", Required: false, Value: false},
|
||||
},
|
||||
|
||||
Action: appMain,
|
||||
Copyright: "Copyright (c) 2020 - 2021 Unlock Music https://github.com/unlock-music/cli/blob/master/LICENSE",
|
||||
HideHelpCommand: true,
|
||||
UsageText: "um [-o /path/to/output/dir] [-i] /path/to/input",
|
||||
UsageText: "um [-o /path/to/output/dir] [--extra-flags] [-i] /path/to/input",
|
||||
}
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
logging.Log().Fatal("run app failed", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func appMain(c *cli.Context) error {
|
||||
func printSupportedExtensions() {
|
||||
exts := []string{}
|
||||
for ext := range common.DecoderRegistry {
|
||||
exts = append(exts, ext)
|
||||
}
|
||||
sort.Strings(exts)
|
||||
for _, ext := range exts {
|
||||
fmt.Printf("%s: %d\n", ext, len(common.DecoderRegistry[ext]))
|
||||
}
|
||||
}
|
||||
func appMain(c *cli.Context) (err error) {
|
||||
if c.Bool("supported-ext") {
|
||||
printSupportedExtensions()
|
||||
return nil
|
||||
}
|
||||
input := c.String("input")
|
||||
if input == "" && c.Args().Present() {
|
||||
input = c.Args().Get(c.Args().Len() - 1)
|
||||
if input == "" {
|
||||
switch c.Args().Len() {
|
||||
case 0:
|
||||
input, err = os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case 1:
|
||||
input = c.Args().Get(0)
|
||||
default:
|
||||
return errors.New("please specify input file (or directory)")
|
||||
}
|
||||
}
|
||||
|
||||
output := c.String("output")
|
||||
@ -54,8 +84,13 @@ func appMain(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if input == output {
|
||||
return errors.New("input and output path are same")
|
||||
}
|
||||
}
|
||||
|
||||
skipNoop := c.Bool("skip-noop")
|
||||
|
||||
inputStat, err := os.Stat(input)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -74,10 +109,9 @@ func appMain(c *cli.Context) error {
|
||||
}
|
||||
|
||||
if inputStat.IsDir() {
|
||||
return dealDirectory(input, output)
|
||||
return dealDirectory(input, output, skipNoop)
|
||||
} else {
|
||||
ext := strings.TrimLeft(filepath.Ext(inputStat.Name()), ".")
|
||||
allDec := common.GetDecoder(ext)
|
||||
allDec := common.GetDecoder(inputStat.Name(), skipNoop)
|
||||
if len(allDec) == 0 {
|
||||
logging.Log().Fatal("skipping while no suitable decoder")
|
||||
}
|
||||
@ -85,7 +119,7 @@ func appMain(c *cli.Context) error {
|
||||
}
|
||||
|
||||
}
|
||||
func dealDirectory(inputDir string, outputDir string) error {
|
||||
func dealDirectory(inputDir string, outputDir string, skipNoop bool) error {
|
||||
items, err := os.ReadDir(inputDir)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -94,8 +128,7 @@ func dealDirectory(inputDir string, outputDir string) error {
|
||||
if item.IsDir() {
|
||||
continue
|
||||
}
|
||||
ext := strings.TrimLeft(filepath.Ext(item.Name()), ".")
|
||||
allDec := common.GetDecoder(ext)
|
||||
allDec := common.GetDecoder(item.Name(), skipNoop)
|
||||
if len(allDec) == 0 {
|
||||
logging.Log().Info("skipping while no suitable decoder", zap.String("file", item.Name()))
|
||||
continue
|
||||
|
15
go.mod
15
go.mod
@ -1,12 +1,17 @@
|
||||
module github.com/unlock-music/cli
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/ulikunitz/xz v0.5.10
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.16.0
|
||||
go.uber.org/zap v1.19.1
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
)
|
||||
|
62
go.sum
62
go.sum
@ -1,13 +1,12 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
@ -15,51 +14,60 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
|
||||
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
|
||||
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
Reference in New Issue
Block a user