-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathdsHelper.js
More file actions
52 lines (45 loc) · 1.97 KB
/
dsHelper.js
File metadata and controls
52 lines (45 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { getOriginalJs } from '../../libs_drpy/drpyCustom.js';
/**
* Decode DS source code (encrypted JS) to plaintext
* @param {string} content - Encrypted content
* @returns {Promise<string>} - Decoded content
*/
export async function decodeDsSource(content) {
try {
// First try the standard drpy method
let result = await getOriginalJs(content);
// Check if result is still seemingly encrypted (starts with comment or looks like base64)
// A simple check: if it contains "var rule" or "export default", it's likely decoded.
// If it starts with "/*" and has no "var rule", it might still be encrypted.
if (result.includes('var rule') || result.includes('export default')) {
return result;
}
// Fallback: Manual decoding if getOriginalJs returned original or failed to decode
// 1. Remove comments
let cleanContent = content.replace(/\/\*[\s\S]*?\*\//, '').trim();
// 2. Try Base64 decode
try {
// Check if it looks like base64 (no spaces, alphanumeric + +/=)
if (/^[A-Za-z0-9+/=]+$/.test(cleanContent)) {
const decoded = Buffer.from(cleanContent, 'base64').toString('utf-8');
if (decoded.includes('var rule') || decoded.includes('function')) {
return decoded;
}
}
} catch (e) {
// Ignore base64 error
}
return result;
} catch (error) {
console.error('Error decoding DS source:', error);
// Fallback in catch block as well
try {
let cleanContent = content.replace(/\/\*[\s\S]*?\*\//, '').trim();
const decoded = Buffer.from(cleanContent, 'base64').toString('utf-8');
if (decoded.includes('var rule')) {
return decoded;
}
} catch (e) {}
return content; // Return original if all fails
}
}