-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
51 lines (47 loc) · 2.07 KB
/
main.js
File metadata and controls
51 lines (47 loc) · 2.07 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
const fs = require('fs');
const parser = require('@babel/parser');
const generate = require('@babel/generator').default;
const reorderSwitchCases = require('./transformers/reorderSwitchCase');
const removeDeadCode = require('./transformers/removeDeadCode');
const {
deobfuscateFirstType,
deobfuscateSecondType,
cleanStrings
} = require('./transformers/deobfuscateStrings');
function decodeHex(content) {
const pattern = /'(\\x[0-9a-fA-F]+)+'/g;
let matches = content.match(pattern) || [];
let decodedStrings = matches.map(match => {
let hexValues = match.slice(1, -1).replace(/\\x/g, '').match(/.{1,2}/g);
return hexValues.map(hex => String.fromCharCode(parseInt(hex, 16))).join('');
});
for (let i = 0; i < matches.length; i++) {
content = content.replace(matches[i], "`" + decodedStrings[i] + "`");
}
return content;
}
function deobfuscateCode(inputFile, outputFile) {
console.log("-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Datadome Captcha Deobfuscator -=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
const code = fs.readFileSync(inputFile, 'utf-8');
const ast = parser.parse(code, {
sourceType: 'module',
plugins: ['jsx']
});
console.log(`=-=-=-=-=-=-=-=-=-=-> Deobfuscating ${inputFile}...`);
console.log(`=-=-=-=-=-=-> Deobfuscated ${deobfuscateFirstType(ast)} matches from the first type of encryption`);
console.log(`=-=-=-=-=-=-> Deobfuscated ${deobfuscateSecondType(ast)} matches from the second type of encryption`);
reorderSwitchCases(ast);
console.log(`=-=-=-=-=-=-> Reordered case switch`);
removeDeadCode(ast);
console.log(`=-=-=-=-=-=-> Removed dead code`);
cleanStrings(ast);
console.log(`=-=-=-=-=-=-> Cleaned strings`);
fs.writeFileSync(outputFile, decodeHex(generate(ast).code));
console.log(`=-=-=-=-=-=-> Saved to ${outputFile}`);
console.log(`=-=-=-=-=-=-=-=-=-=-> Done!`);
console.log("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
}
deobfuscateCode(
process.argv[2] || 'script.js',
process.argv[3] || 'output.js'
)