-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (36 loc) · 1.36 KB
/
index.ts
File metadata and controls
43 lines (36 loc) · 1.36 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
import * as acorn from "acorn";
import * as astring from 'astring'
import fs from "node:fs";
import path from "node:path";
import { FixMovedDeclarations } from "./transforms/movedDecls";
import { FixEncodedStrings } from "./transforms/stringEncoding";
import { FixHexaDecimalNums } from "./transforms/hexaDecimalNums";
import { FixSeperatedVarDeclarations } from "./transforms/seperateVarDeclarations";
import { FixOpaquePredicates } from "./transforms/opaquePredicates";
import { FixMaskedVariables } from "./transforms/variableMasking";
import { FixShuffledArrays } from "./transforms/arrayShuffle";
import { CompleteArithmeticExprs } from "./transforms/calculator";
if (!fs.existsSync(path.join(process.cwd(), "input.js"))) {
console.error("input.js not found in the current working directory.");
process.exit(1);
};
const ast = acorn.parse(fs.readFileSync(path.join(process.cwd(), "input.js"), "utf-8"), {
ecmaVersion: "latest",
sourceType: "script",
});
// in order!
const Transfomrs = [
FixMovedDeclarations,
FixEncodedStrings,
FixHexaDecimalNums,
FixSeperatedVarDeclarations,
FixOpaquePredicates,
FixMaskedVariables,
FixShuffledArrays,
CompleteArithmeticExprs
]
for (const Transform of Transfomrs) {
new Transform(ast);
}
const output = astring.generate(ast);
fs.writeFileSync(path.join(process.cwd(), "output.js"), output);