feat(QMCv2): Add mapCipher & mflac/mgg key discovery

This commit is contained in:
MengYX
2021-12-13 22:54:08 +08:00
parent 1552a667f6
commit 38648d57e6
17 changed files with 295 additions and 134 deletions

39
algo/qmc/cipher_map.go Normal file
View File

@ -0,0 +1,39 @@
package qmc
import "errors"
type mapCipher struct {
key []byte
box []byte
size int
}
func NewMapCipher(key []byte) (*mapCipher, error) {
if len(key) == 0 {
return nil, errors.New("qmc/cipher_map: invalid key size")
}
c := &mapCipher{key: key, size: len(key)}
c.box = make([]byte, c.size)
return c, nil
}
func (c *mapCipher) getMask(offset int) byte {
if offset > 0x7FFF {
offset %= 0x7FFF
}
idx := (offset*offset + 71214) % c.size
return c.rotate(c.key[idx], byte(idx)&0x7)
}
func (c *mapCipher) rotate(value byte, bits byte) byte {
rotate := (bits + 4) % 8
left := value << rotate
right := value >> rotate
return left | right
}
func (c *mapCipher) Decrypt(buf []byte, offset int) {
for i := 0; i < len(buf); i++ {
buf[i] ^= c.getMask(offset + i)
}
}