mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 03:33:02 +00:00
feat(ximalaya): initial support
This commit is contained in:
34
algo/ximalaya/x2m_crypto.go
Normal file
34
algo/ximalaya/x2m_crypto.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package ximalaya
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
const x2mHeaderSize = 1024
|
||||
|
||||
var x2mKey = [...]byte{'x', 'm', 'l', 'y'}
|
||||
var x2mScrambleTable = [x2mHeaderSize]uint16{}
|
||||
|
||||
//go:embed x2m_scramble_table.bin
|
||||
var x2mScrambleTableBytes []byte
|
||||
|
||||
func init() {
|
||||
if len(x2mScrambleTableBytes) != 2*x2mHeaderSize {
|
||||
panic("invalid x3m scramble table")
|
||||
}
|
||||
for i := range x3mScrambleTable {
|
||||
x3mScrambleTable[i] = binary.LittleEndian.Uint16(x2mScrambleTableBytes[i*2:])
|
||||
}
|
||||
}
|
||||
|
||||
// decryptX2MHeader decrypts the header of ximalaya .x2m file.
|
||||
// make sure input src is 1024(x2mHeaderSize) bytes long.
|
||||
func decryptX2MHeader(src []byte) []byte {
|
||||
dst := make([]byte, len(src))
|
||||
for dstIdx := range src {
|
||||
srcIdx := x2mScrambleTable[dstIdx]
|
||||
dst[dstIdx] = src[srcIdx] ^ x2mKey[dstIdx%len(x2mKey)]
|
||||
}
|
||||
return dst
|
||||
}
|
||||
Reference in New Issue
Block a user