feat: mmkv 加密数据库解析

This commit is contained in:
awalol
2024-02-05 08:41:40 +08:00
parent 7b12f61a97
commit 877f37f01e
5 changed files with 89 additions and 10 deletions

View File

@ -16,6 +16,9 @@ import (
"unlock-music.dev/cli/internal/sniff"
)
var VaultPath = ""
var VaultKey = ""
type Decoder struct {
raw io.ReadSeeker // raw is the original file reader
params *common.DecoderParams
@ -140,11 +143,32 @@ func (d *Decoder) searchKey() (err error) {
return err
}
switch string(suffixBuf) {
switch string(bytes.ReplaceAll(suffixBuf, []byte{0x00}, []byte{})) {
case "QTag":
return d.readRawMetaQTag()
case "STag":
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
case "cex":
d.decodedKey, err = readKeyFromMMKVCustom(d)
if err == nil {
suffix := []byte{0x63, 0x65, 0x78, 0x00} // cex
for i := 0; i <= 3; i++ {
// 末尾的信息数据每192字节出现一次故只要循环判断末尾不为musicex时即为歌曲数据
musicexLen, err := d.raw.Seek(int64(-(192*i)-4), io.SeekEnd)
if err != nil {
return fmt.Errorf("get musicexLen error: %w", err)
}
buf, err := io.ReadAll(io.LimitReader(d.raw, 4))
if err != nil {
return fmt.Errorf("get musicex error: %w", err)
}
if !bytes.Equal(buf, suffix) {
d.audioLen = int(musicexLen) + 4
return nil
}
}
}
return err
default:
size := binary.LittleEndian.Uint32(suffixBuf)