mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 03:33:02 +00:00
fix: Handle musicex tag correctly
This commit is contained in:
@@ -137,10 +137,10 @@ func (d *Decoder) searchKey() (err error) {
|
|||||||
d.decodedKey, err = deriveKey([]byte(key))
|
d.decodedKey, err = deriveKey([]byte(key))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
d.audioLen = fileSize
|
d.audioLen = fileSize
|
||||||
return nil
|
} else {
|
||||||
|
d.decodedKey = nil
|
||||||
|
d.logger.Warn("could not derive key, skip", zap.Error(err))
|
||||||
}
|
}
|
||||||
d.decodedKey = nil
|
|
||||||
d.logger.Warn("could not derive key, skip", zap.Error(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suffixBuf := make([]byte, 4)
|
suffixBuf := make([]byte, 4)
|
||||||
@@ -153,7 +153,7 @@ func (d *Decoder) searchKey() (err error) {
|
|||||||
return d.readRawMetaQTag()
|
return d.readRawMetaQTag()
|
||||||
case "STag":
|
case "STag":
|
||||||
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
|
return errors.New("qmc: file with 'STag' suffix doesn't contains media key")
|
||||||
// MusicEx\0
|
// speculative guess for "musicex\0"
|
||||||
case "cex\x00":
|
case "cex\x00":
|
||||||
footer, err := NewMusicExTag(d.raw)
|
footer, err := NewMusicExTag(d.raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -161,17 +161,26 @@ func (d *Decoder) searchKey() (err error) {
|
|||||||
}
|
}
|
||||||
d.audioLen = fileSize - int(footer.TagSize)
|
d.audioLen = fileSize - int(footer.TagSize)
|
||||||
if key, ok := d.params.CryptoParams.QmcKeys.Get(footer.MediaFileName); ok {
|
if key, ok := d.params.CryptoParams.QmcKeys.Get(footer.MediaFileName); ok {
|
||||||
|
d.logger.Debug("searchKey: using key from MediaFileName", zap.String("MediaFileName", footer.MediaFileName), zap.String("key", key))
|
||||||
d.decodedKey, err = deriveKey([]byte(key))
|
d.decodedKey, err = deriveKey([]byte(key))
|
||||||
|
} else if d.decodedKey == nil {
|
||||||
|
return errors.New("searchKey: no key found for musicex tag")
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
default:
|
default:
|
||||||
size := binary.LittleEndian.Uint32(suffixBuf)
|
// if we already have a key from legacy mmkv, use it
|
||||||
|
if d.decodedKey != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to use suffix as key length
|
||||||
|
size := binary.LittleEndian.Uint32(suffixBuf)
|
||||||
if size <= 0xFFFF && size != 0 { // assume size is key len
|
if size <= 0xFFFF && size != 0 { // assume size is key len
|
||||||
return d.readRawKey(int64(size))
|
return d.readRawKey(int64(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to use default static cipher
|
// try to use default static cipher,
|
||||||
|
// or the key read from the legacy mmkv
|
||||||
d.audioLen = fileSize
|
d.audioLen = fileSize
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,24 +42,25 @@ func NewMusicExTag(f io.ReadSeeker) (*MusicExTagV1, error) {
|
|||||||
tag := &MusicExTagV1{
|
tag := &MusicExTagV1{
|
||||||
TagSize: binary.LittleEndian.Uint32(buffer[0x00:0x04]),
|
TagSize: binary.LittleEndian.Uint32(buffer[0x00:0x04]),
|
||||||
TagVersion: binary.LittleEndian.Uint32(buffer[0x04:0x08]),
|
TagVersion: binary.LittleEndian.Uint32(buffer[0x04:0x08]),
|
||||||
TagMagic: buffer[0x04:0x0C],
|
TagMagic: buffer[0x08:],
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(tag.TagMagic, []byte("musicex\x00")) {
|
if !bytes.Equal(tag.TagMagic, []byte("musicex\x00")) {
|
||||||
return nil, errors.New("MusicEx magic mismatch")
|
return nil, errors.New("MusicEx magic mismatch")
|
||||||
}
|
}
|
||||||
if tag.TagVersion != 1 {
|
if tag.TagVersion != 1 {
|
||||||
return nil, errors.New(fmt.Sprintf("unsupported musicex tag version. expecting 1, got %d", tag.TagVersion))
|
return nil, fmt.Errorf("unsupported musicex tag version. expecting 1, got %d", tag.TagVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag.TagSize < 0xC0 {
|
if tag.TagSize < 0xC0 {
|
||||||
return nil, errors.New(fmt.Sprintf("unsupported musicex tag size. expecting at least 0xC0, got 0x%02x", tag.TagSize))
|
return nil, fmt.Errorf("unsupported musicex tag size. expecting at least 0xC0, got 0x%02x", tag.TagSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = make([]byte, tag.TagSize)
|
buffer = make([]byte, tag.TagSize)
|
||||||
|
f.Seek(-int64(tag.TagSize), io.SeekEnd)
|
||||||
bytesRead, err = f.Read(buffer)
|
bytesRead, err = f.Read(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("MusicExV1: Read error %w", err)
|
||||||
}
|
}
|
||||||
if uint32(bytesRead) != tag.TagSize {
|
if uint32(bytesRead) != tag.TagSize {
|
||||||
return nil, fmt.Errorf("MusicExV1: read %d bytes (expected %d)", bytesRead, tag.TagSize)
|
return nil, fmt.Errorf("MusicExV1: read %d bytes (expected %d)", bytesRead, tag.TagSize)
|
||||||
|
|||||||
Reference in New Issue
Block a user