mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-25 14:56:58 +00:00
feat(kgm): kgm v5 (aka. kgg) support
This commit is contained in:
1 parent
acb7a634b1
commit
c71078f5da
24 files changed
+553
-39
No files matched your search
@@ -1,11 +1,17 @@
|
||||
import { getFileName } from './pathHelper';
|
||||
import { SQLDatabase, SQLStatic, loadSQL } from './sqlite';
|
||||
import { KuGou } from '@unlock-music/crypto';
|
||||
|
||||
export interface QMAndroidKeyEntry {
|
||||
name: string;
|
||||
ekey: string;
|
||||
}
|
||||
|
||||
export type KugouKeyEntry = {
|
||||
audioHash: string;
|
||||
ekey: string;
|
||||
};
|
||||
|
||||
export class DatabaseKeyExtractor {
|
||||
private static _instance: DatabaseKeyExtractor;
|
||||
|
||||
@@ -52,4 +58,34 @@ export class DatabaseKeyExtractor {
|
||||
db?.close();
|
||||
}
|
||||
}
|
||||
|
||||
extractKugouKeyFromEncryptedDb(buffer: ArrayBuffer): null | KugouKeyEntry[] {
|
||||
const dbBuffer = new Uint8Array(buffer);
|
||||
let db: SQLDatabase | null = null;
|
||||
|
||||
try {
|
||||
KuGou.decryptDatabase(dbBuffer);
|
||||
db = new this.SQL.Database(dbBuffer);
|
||||
|
||||
let sql: undefined | string;
|
||||
if (this.hasTable(db, 'ShareFileItems')) {
|
||||
sql = `select EncryptionKeyId, EncryptionKey from ShareFileItems where EncryptionKey != '' group by EncryptionKeyId`;
|
||||
}
|
||||
if (!sql) return null;
|
||||
|
||||
const result = db.exec(sql);
|
||||
if (result.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const keys = result[0].values;
|
||||
return keys.map(([audioHash, ekey]) => ({
|
||||
// strip dir name
|
||||
audioHash: String(audioHash).normalize(),
|
||||
ekey: String(ekey).normalize(),
|
||||
}));
|
||||
} finally {
|
||||
db?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { StagingKugouKey } from '~/features/settings/keyFormats';
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
|
||||
export function parseAndroidKugouMMKV(view: DataView): Omit<StagingKugouKey, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKugouKey, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const audioHash = mmkv.readString();
|
||||
const ekey = mmkv.readStringValue();
|
||||
|
||||
if (audioHash.length === 0x20 && ekey) {
|
||||
result.push({ audioHash, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user