| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import pako from 'pako';
- // 反混淆:URL安全 Base64 -> 标准 Base64
- function deobfuscate(obfStr: string) {
- let base64 = obfStr.replace(/-/g, '+').replace(/_/g, '/');
- while (base64.length % 4) base64 += '=';
- return base64;
- }
- // Base64 转 Uint8Array
- function b642ab(base64: string) {
- const binary = atob(base64);
- const len = binary.length;
- const bytes = new Uint8Array(len);
- for (let i = 0; i < len; i++) {
- bytes[i] = binary.charCodeAt(i);
- }
- return bytes.buffer;
- }
- // 主函数:反混淆 + 解压成字符串
- function deobfuscateAndDecompress(obfStr: string): Uint8Array {
- const b64 = deobfuscate(obfStr);
- const compressedBuf = b642ab(b64);
- const decompressed = pako.inflate(new Uint8Array(compressedBuf));
- return decompressed;
- }
- export async function decrypt(url: string): Promise<Uint8Array | undefined> {
- const res = await fetch(url).catch((err) => {
- console.error('Error during fetch:', err)
- return undefined
- })
- if (!res) return undefined
- const buffer = await res.text().catch((err) => {
- console.error('Error during get text:', err)
- return undefined
- })
- if (!buffer) return undefined
- return deobfuscateAndDecompress(buffer)
- }
|