mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 14:56:58 +00:00
Merge remote-tracking branch 'origin/main' into feat/qingting-fm
This commit is contained in:
commit
4498ab6592
18 files changed
+188
-82
No files matched your search
+5
-35
@@ -1,4 +1,3 @@
|
||||
import type { StagingKWMv2Key } from '~/features/settings/keyFormats';
|
||||
import { bytesToUTF8String } from '~/decrypt-worker/util/utf8Encoder';
|
||||
import { formatHex } from './formatHex';
|
||||
|
||||
@@ -69,7 +68,11 @@ export class MMKVParser {
|
||||
return bytesToUTF8String(data).normalize();
|
||||
}
|
||||
|
||||
public readOptionalString() {
|
||||
public readKey() {
|
||||
return this.readString();
|
||||
}
|
||||
|
||||
public readStringValue(): string | null {
|
||||
// Container [
|
||||
// len: int,
|
||||
// data: variant
|
||||
@@ -96,37 +99,4 @@ export class MMKVParser {
|
||||
const containerLen = this.readInt();
|
||||
this.offset += containerLen;
|
||||
}
|
||||
|
||||
public static toStringMap(view: DataView): Map<string, string> {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result = new Map<string, string>();
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const value = mmkv.readOptionalString();
|
||||
if (value) {
|
||||
result.set(key, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static parseKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const idMatch = key.match(/^sec_ekey#(\d+)-(.+)/);
|
||||
if (!idMatch) {
|
||||
mmkv.skipContainer();
|
||||
continue;
|
||||
}
|
||||
|
||||
const [_, rid, quality] = idMatch;
|
||||
const ekey = mmkv.readOptionalString();
|
||||
if (ekey) {
|
||||
result.push({ rid, quality, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,28 @@
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const makeViewFromBuffer = (buff: Buffer) =>
|
||||
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
|
||||
|
||||
test('parse qm mmkv file', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm.mmkv'));
|
||||
expect(Object.fromEntries(MMKVParser.toStringMap(view).entries())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"Lorem Ipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum congue volutpat metus non molestie. Quisque id est sapien. Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. Integer non urna justo.",
|
||||
"key": "value",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('parse qm mmkv file with optional str', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm_optional.mmkv'));
|
||||
expect(Object.fromEntries(MMKVParser.toStringMap(view).entries())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"key": "value",
|
||||
"key2": "value2",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('parse kuwo mmkv file', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo.mmkv'));
|
||||
expect(MMKVParser.parseKuwoEKey(view)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"ekey": "xyz123",
|
||||
"quality": "20201kmflac",
|
||||
"rid": "1234567",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('throw error on broken file', () => {
|
||||
const view = makeViewFromBuffer(
|
||||
Buffer.from([0x27, 0x00, 0x00, 0x00, 0x7f, 0x03, 0x6b, 0x65, 0x79, 0x06, 0x07, 0x62, 0x61, 0x64, 0xff, 0xff]),
|
||||
);
|
||||
|
||||
expect(() => Object.fromEntries(MMKVParser.toStringMap(view).entries())).toThrow(/offset mismatch/i);
|
||||
expect(() => {
|
||||
const parser = new MMKVParser(view);
|
||||
parser.readKey();
|
||||
parser.readStringValue();
|
||||
}).toThrow(/offset mismatch/i);
|
||||
});
|
||||
|
||||
test('able to handle empty value', () => {
|
||||
const view = makeViewFromBuffer(
|
||||
Buffer.from([0x0b, 0x00, 0x00, 0x00, 0x7f, 0x03, 0x6b, 0x65, 0x79, 0x00, 0x01, 0x31, 0x02, 0x01, 0x32, 0xff]),
|
||||
);
|
||||
|
||||
const parser = new MMKVParser(view);
|
||||
expect(parser.readKey()).toEqual('key');
|
||||
expect(parser.readStringValue()).toEqual(null);
|
||||
expect(parser.readKey()).toEqual('1');
|
||||
expect(parser.readStringValue()).toEqual('2');
|
||||
});
|
||||
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { parseAndroidKuwoEKey, parseIosKuwoEKey } from '../kuwo';
|
||||
|
||||
const makeViewFromBuffer = (buff: Buffer) =>
|
||||
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
|
||||
|
||||
test('parse kuwo android ekey mmkv file "cn.kuwo.player.mmkv.defaultconfig"', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo_android.mmkv'));
|
||||
expect(parseAndroidKuwoEKey(view)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"ekey": "xyz123",
|
||||
"quality": "20201kmflac",
|
||||
"rid": "1234567",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('parse kuwo ios ekey mmkv file "kw_ekey"', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo_ios.mmkv'));
|
||||
expect(parseIosKuwoEKey(view)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"ekey": "xyz123",
|
||||
"quality": "20201",
|
||||
"rid": "1234567",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { parseAndroidQmEKey } from '../qm';
|
||||
|
||||
const makeViewFromBuffer = (buff: Buffer) =>
|
||||
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
|
||||
|
||||
test('parse qm mmkv file', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm.mmkv'));
|
||||
expect(Object.fromEntries(parseAndroidQmEKey(view).entries())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"Lorem Ipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum congue volutpat metus non molestie. Quisque id est sapien. Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. Integer non urna justo.",
|
||||
"key": "value",
|
||||
}
|
||||
`);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { StagingKWMv2Key } from '~/features/settings/keyFormats';
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
|
||||
export function parseAndroidKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const idMatch = key.match(/^sec_ekey#(\d+)-(\w+)$/);
|
||||
if (!idMatch) {
|
||||
mmkv.skipContainer();
|
||||
continue;
|
||||
}
|
||||
|
||||
const [_, rid, quality] = idMatch;
|
||||
const ekey = mmkv.readStringValue();
|
||||
if (ekey) {
|
||||
result.push({ rid, quality, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function parseIosKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readKey();
|
||||
const idMatch = key.match(/^(\d+)_(\d+)$/);
|
||||
if (!idMatch) {
|
||||
mmkv.skipContainer();
|
||||
continue;
|
||||
}
|
||||
const [_, rid, quality] = idMatch;
|
||||
const ekey = mmkv.readStringValue();
|
||||
if (ekey) {
|
||||
result.push({ rid, quality, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
|
||||
export function parseAndroidQmEKey(view: DataView): Map<string, string> {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result = new Map<string, string>();
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const value = mmkv.readStringValue();
|
||||
if (value) {
|
||||
result.set(key, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user