mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 19:43:02 +00:00
feat(kgm): kgm v5 (aka. kgg) support
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user