1
0
forked from um/cli

Fix: algorithm bugs in qmc

Optimize: algorithm in `kgm`
This commit is contained in:
Emmm Monster 2021-08-03 04:17:10 +08:00
parent 60c15894c0
commit 28d84e4dc2
No known key found for this signature in database
GPG Key ID: C98279C83FB50DB9
3 changed files with 6 additions and 10 deletions

View File

@ -75,12 +75,8 @@ func (d *Decoder) Decode() error {
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++ {

View File

@ -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{
@ -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))
}

View File

@ -39,7 +39,7 @@ func NewKey256FromMask44(mask44 []byte) (*Key256Mask, error) {
return q, nil
}
func (q *Key256Mask) getMatrix44() (mask44 []byte, err error) {
func (q *Key256Mask) GetMatrix44() ([]byte, error) {
if len(q.matrix) != 128 {
return nil, ErrMaskLength128
}
@ -53,7 +53,7 @@ func (q *Key256Mask) getMatrix44() (mask44 []byte, err error) {
return nil, ErrMaskDecode
}
}
q.matrix[idx44] = q.matrix[it256[0]]
matrix44[idx44] = q.matrix[it256[0]]
idx44++
}
}