-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCash.test.ts
145 lines (132 loc) · 2.96 KB
/
Cash.test.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
import JsConfuser from "../../src/index";
var CASH_JS = readFileSync(join(__dirname, "./Cash.src.js"), "utf-8");
const handleError = (error, output) => {
var helperCode = `var document = {
documentElement: {},
createElement: () => {
return { style: {} };
},
};
var window = {
document,
Array,
Object,
Symbol,
Number,
parseInt,
JSON,
setTimeout,
encodeURIComponent,
RegExp,
String,
$: false,
};
window.window = window;
global.window = window;
for (var key in window) {
global[key] = window[key];
}`;
console.error(error);
// writeFileSync("dev.output.js", helperCode + "\n" + output, { encoding: "utf-8", });
expect("An error occurred").toStrictEqual(null);
};
test("Variant #1: Cash.js on High Preset (Strict Mode)", async () => {
var { code: output } = await JsConfuser.obfuscate(CASH_JS, {
target: "node",
preset: "high",
pack: true,
});
// Make the required document variables for initialization
var document = {
documentElement: {},
createElement: () => {
return { style: {} };
},
} as any as Document;
var window = {
document,
Array,
Object,
Symbol,
Number,
parseInt,
JSON,
setTimeout,
encodeURIComponent,
RegExp,
String,
$: false,
} as any;
window.window = window;
global.window = window;
for (var key in window) {
global[key] = window[key];
}
try {
// Pack option allows the code to be executed in a strict mode
eval(output);
} catch (e) {
handleError(e, output);
}
expect(window).toHaveProperty("cash");
});
test("Variant #2: Cash.js on High Preset + Integrity + Self Defending + RGF + Tamper Protection", async () => {
// Make the required document variables for initialization
var document = {
documentElement: {},
createElement: () => {
return { style: {} };
},
} as any as Document;
var window = {
document,
Array,
Object,
Symbol,
Number,
parseInt,
JSON,
setTimeout,
encodeURIComponent,
RegExp,
String,
$: false,
} as any;
window.window = window;
global.window = window;
for (var key in window) {
global[key] = window[key];
}
const CountermeasuresCode = `
function countermeasures() {
throw new Error("countermeasures() was called");
}
`;
var { code: output } = await JsConfuser.obfuscate(
CountermeasuresCode + CASH_JS,
{
target: "node",
preset: "high",
pack: true,
rgf: {
value: true,
limit: 10,
},
lock: {
integrity: true,
selfDefending: true,
tamperProtection: true,
countermeasures: "countermeasures",
},
}
);
try {
// Pack option allows the code to be executed in a strict mode
eval(output);
} catch (e) {
handleError(e, output);
}
expect(window).toHaveProperty("cash");
});