From 1c5310ffae078aaa0cc052e827edb3fe1b397959 Mon Sep 17 00:00:00 2001 From: awalol Date: Wed, 14 Feb 2024 16:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algo/qmc/key_mmkv.go | 9 ++------- algo/qmc/qmc.go | 7 +++---- .../{qmc_footer.go => qmc_footer_musicex.go} | 10 ++++++---- cmd/um/main.go | 20 +++++++++---------- go.mod | 3 +-- go.sum | 4 ++-- 6 files changed, 24 insertions(+), 29 deletions(-) rename algo/qmc/{qmc_footer.go => qmc_footer_musicex.go} (94%) diff --git a/algo/qmc/key_mmkv.go b/algo/qmc/key_mmkv.go index 88b1ef6..24b51cb 100644 --- a/algo/qmc/key_mmkv.go +++ b/algo/qmc/key_mmkv.go @@ -1,18 +1,17 @@ package qmc import ( - "encoding/base64" "errors" "fmt" "os" "path/filepath" "runtime" - "git.unlock-music.dev/awalol/go-mmkv" "github.com/samber/lo" "go.uber.org/zap" "golang.org/x/exp/slices" "golang.org/x/text/unicode/norm" + "unlock-music.dev/mmkv" ) var streamKeyVault mmkv.Vault @@ -107,11 +106,7 @@ func readKeyFromMMKVCustom(mid string) ([]byte, error) { if err != nil { return nil, fmt.Errorf("get eKey error: %w", err) } - n, err := base64.StdEncoding.Decode(eKey, eKey) - if err != nil { - return nil, fmt.Errorf("base64 error: %w", err) - } - return deriveKeyV1(eKey[:n]) + return deriveKey(eKey) } func getRelativeMMKVDir(file string) (string, error) { diff --git a/algo/qmc/qmc.go b/algo/qmc/qmc.go index 3bbf798..310e642 100644 --- a/algo/qmc/qmc.go +++ b/algo/qmc/qmc.go @@ -40,8 +40,6 @@ type Decoder struct { // provider logger *zap.Logger - - footer qqMusicTagMusicEx } // Read implements io.Reader, offer the decrypted audio data. @@ -147,12 +145,13 @@ func (d *Decoder) searchKey() (err error) { case "STag": return errors.New("qmc: file with 'STag' suffix doesn't contains media key") case "cex\x00": - audioLen, err := d.footer.Read(d.raw) + footer := qqMusicTagMusicEx{} + audioLen, err := footer.Read(d.raw) if err != nil { return err } d.audioLen = int(audioLen) - d.decodedKey, err = readKeyFromMMKVCustom(d.footer.mediafile) + d.decodedKey, err = readKeyFromMMKVCustom(footer.mediafile) if err != nil { return err } diff --git a/algo/qmc/qmc_footer.go b/algo/qmc/qmc_footer_musicex.go similarity index 94% rename from algo/qmc/qmc_footer.go rename to algo/qmc/qmc_footer_musicex.go index 1714175..444c2aa 100644 --- a/algo/qmc/qmc_footer.go +++ b/algo/qmc/qmc_footer_musicex.go @@ -43,15 +43,17 @@ func (tag *qqMusicTagMusicEx) Read(raw io.ReadSeeker) (int64, error) { for i := 0; i < 30; i++ { u := binary.LittleEndian.Uint16(buf[12+i*2 : 12+(i+1)*2]) - if u != 0 { - tag.mid += string(u) + if u == 0 { + break } + tag.mid += string(u) } for i := 0; i < 50; i++ { u := binary.LittleEndian.Uint16(buf[72+i*2 : 72+(i+1)*2]) - if u != 0 { - tag.mediafile += string(u) + if u == 0 { + break } + tag.mediafile += string(u) } tag.unknown_3 = binary.LittleEndian.Uint32(buf[173:177]) diff --git a/cmd/um/main.go b/cmd/um/main.go index 9c5c329..4b74ce7 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -50,7 +50,7 @@ func main() { &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.StringFlag{Name: "vault-file", Aliases: []string{"db"}, Usage: "数据库文件位置 (请确保crc文件在同目录下)", Required: false}, - &cli.StringFlag{Name: "vault-key", Aliases: []string{"key"}, Usage: "数据库密钥", Required: false}, + &cli.StringFlag{Name: "vault-key", Aliases: []string{"key"}, Usage: "数据库密钥 (length 32)", Required: false}, &cli.BoolFlag{Name: "remove-source", Aliases: []string{"rs"}, Usage: "remove source file", Required: false, Value: false}, &cli.BoolFlag{Name: "skip-noop", Aliases: []string{"n"}, Usage: "skip noop decoder", Required: false, Value: true}, &cli.BoolFlag{Name: "update-metadata", Usage: "update metadata & album art from network", Required: false, Value: false}, @@ -83,15 +83,6 @@ func printSupportedExtensions() { } func appMain(c *cli.Context) (err error) { - vaultPath := c.String("vault-file") - vaultKey := c.String("vault-key") - if vaultPath != "" && vaultKey != "" { - err := qmc.OpenMMKV(vaultPath, vaultKey, logger) - if err != nil { - return err - } - } - if c.Bool("supported-ext") { printSupportedExtensions() return nil @@ -140,6 +131,15 @@ func appMain(c *cli.Context) (err error) { return errors.New("output should be a writable directory") } + vaultPath := c.String("vault-file") + vaultKey := c.String("vault-key") + if vaultPath != "" && vaultKey != "" { + err := qmc.OpenMMKV(vaultPath, vaultKey, logger) + if err != nil { + return err + } + } + proc := &processor{ outputDir: output, skipNoopDecoder: c.Bool("skip-noop"), diff --git a/go.mod b/go.mod index 778d846..9854614 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module unlock-music.dev/cli go 1.19 require ( - git.unlock-music.dev/awalol/go-mmkv v0.1.0 github.com/fsnotify/fsnotify v1.6.0 github.com/go-flac/flacpicture v0.2.0 github.com/go-flac/flacvorbis v0.1.0 @@ -14,7 +13,7 @@ require ( golang.org/x/crypto v0.3.0 golang.org/x/exp v0.0.0-20240119083558-1b970713d09a golang.org/x/text v0.5.0 -//unlock-music.dev/mmkv v0.0.0-20221204231432-41a75bd29939 + unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3 ) require ( diff --git a/go.sum b/go.sum index a6d8443..52c7d2c 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -git.unlock-music.dev/awalol/go-mmkv v0.1.0 h1:Ev4buS12RNOUYd99wtE0P7CUIForghsBt0zRpaCnaSU= -git.unlock-music.dev/awalol/go-mmkv v0.1.0/go.mod h1:aM3nwVQyWkCH424GWxwU5w9JeRLUWNz7HgPxw0lWWOY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -65,3 +63,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3 h1:soJr2wq4gDr+oCz81OCLJX/YjMsx9cwQGAEzvmw2yEs= +unlock-music.dev/mmkv v0.0.0-20240213204546-08c723fb2ed3/go.mod h1:1+Hdsrk8gl1i4/oxOnAhx6y51DAcUfi2CDni6Qhk8Kw=