js-confuser-vm 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -89
- package/dist/compiler.js +583 -208
- package/dist/disassembler.js +58 -8
- package/dist/runtime.js +93 -74
- package/dist/template.js +81 -76
- package/dist/transforms/bytecode/concealConstants.js +2 -2
- package/dist/transforms/bytecode/controlFlowFlattening.js +143 -25
- package/dist/transforms/bytecode/dispatcher.js +3 -3
- package/dist/transforms/bytecode/resolveRegisters.js +19 -4
- package/dist/transforms/bytecode/selfModifying.js +88 -21
- package/dist/transforms/bytecode/specializedOpcodes.js +6 -3
- package/dist/transforms/bytecode/stringConcealing.js +253 -75
- package/dist/utils/ast-utils.js +61 -0
- package/dist/utils/op-utils.js +1 -0
- package/package.json +7 -1
- package/.gitmodules +0 -4
- package/.prettierignore +0 -1
- package/CHANGELOG.md +0 -358
- package/babel-plugin-inline-runtime.cjs +0 -34
- package/babel.config.json +0 -23
- package/bench.ts +0 -146
- package/disassemble.ts +0 -12
- package/index.ts +0 -43
- package/jest-strip-types.js +0 -10
- package/jest.config.js +0 -64
- package/output.disassembled.js +0 -41
- package/src/build-runtime.ts +0 -113
- package/src/compiler.ts +0 -2703
- package/src/disassembler.ts +0 -329
- package/src/index.ts +0 -24
- package/src/minify.ts +0 -21
- package/src/options.ts +0 -24
- package/src/runtime.ts +0 -956
- package/src/template.ts +0 -265
- package/src/transforms/bytecode/aliasedOpcodes.ts +0 -151
- package/src/transforms/bytecode/concealConstants.ts +0 -52
- package/src/transforms/bytecode/controlFlowFlattening.ts +0 -566
- package/src/transforms/bytecode/dispatcher.ts +0 -292
- package/src/transforms/bytecode/macroOpcodes.ts +0 -193
- package/src/transforms/bytecode/resolveConstants.ts +0 -126
- package/src/transforms/bytecode/resolveLabels.ts +0 -112
- package/src/transforms/bytecode/resolveRegisters.ts +0 -226
- package/src/transforms/bytecode/selfModifying.ts +0 -121
- package/src/transforms/bytecode/specializedOpcodes.ts +0 -164
- package/src/transforms/bytecode/stringConcealing.ts +0 -130
- package/src/transforms/runtime/aliasedOpcodes.ts +0 -191
- package/src/transforms/runtime/classObfuscation.ts +0 -59
- package/src/transforms/runtime/macroOpcodes.ts +0 -138
- package/src/transforms/runtime/minify.ts +0 -1
- package/src/transforms/runtime/shuffleOpcodes.ts +0 -24
- package/src/transforms/runtime/specializedOpcodes.ts +0 -161
- package/src/types.ts +0 -134
- package/src/utils/ast-utils.ts +0 -19
- package/src/utils/op-utils.ts +0 -46
- package/src/utils/pass-utils.ts +0 -126
- package/src/utils/profile-utils.ts +0 -3
- package/src/utils/random-utils.ts +0 -31
- package/tsconfig.json +0 -12
package/jest.config.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const OPTIONS_MATRIX = [
|
|
2
|
-
{ displayName: "default", VM_OPTIONS: {} },
|
|
3
|
-
{ displayName: "randomizeOpcodes", VM_OPTIONS: { randomizeOpcodes: true } },
|
|
4
|
-
{ displayName: "shuffleOpcodes", VM_OPTIONS: { shuffleOpcodes: true } },
|
|
5
|
-
{ displayName: "encodeBytecode", VM_OPTIONS: { encodeBytecode: true } },
|
|
6
|
-
{ displayName: "selfModifying", VM_OPTIONS: { selfModifying: true } },
|
|
7
|
-
{ displayName: "timingChecks", VM_OPTIONS: { timingChecks: true } },
|
|
8
|
-
{ displayName: "macroOpcodes", VM_OPTIONS: { macroOpcodes: true } },
|
|
9
|
-
{
|
|
10
|
-
displayName: "specializedOpcodes",
|
|
11
|
-
VM_OPTIONS: { specializedOpcodes: true },
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
displayName: "aliasedOpcodes",
|
|
15
|
-
VM_OPTIONS: { aliasedOpcodes: true },
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
displayName: "concealConstants",
|
|
19
|
-
VM_OPTIONS: { concealConstants: true },
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
displayName: "dispatcher",
|
|
23
|
-
VM_OPTIONS: { dispatcher: true },
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
displayName: "controlFlowFlattening",
|
|
27
|
-
VM_OPTIONS: { controlFlowFlattening: true },
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
displayName: "stringConcealing",
|
|
31
|
-
VM_OPTIONS: { stringConcealing: true },
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
displayName: "classObfuscation",
|
|
35
|
-
VM_OPTIONS: { classObfuscation: true },
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
displayName: "all",
|
|
39
|
-
VM_OPTIONS: {
|
|
40
|
-
randomizeOpcodes: true,
|
|
41
|
-
shuffleOpcodes: true,
|
|
42
|
-
encodeBytecode: true,
|
|
43
|
-
selfModifying: true,
|
|
44
|
-
timingChecks: true,
|
|
45
|
-
macroOpcodes: true,
|
|
46
|
-
specializedOpcodes: true,
|
|
47
|
-
aliasedOpcodes: true,
|
|
48
|
-
concealConstants: true,
|
|
49
|
-
dispatcher: true,
|
|
50
|
-
stringConcealing: true,
|
|
51
|
-
classObfuscation: true,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
export default {
|
|
57
|
-
projects: OPTIONS_MATRIX.map(({ displayName, VM_OPTIONS }) => ({
|
|
58
|
-
displayName,
|
|
59
|
-
extensionsToTreatAsEsm: [".ts"],
|
|
60
|
-
moduleFileExtensions: ["ts", "js", "json"],
|
|
61
|
-
transform: { "\\.ts$": "./jest-strip-types.js" },
|
|
62
|
-
globals: { VM_OPTIONS },
|
|
63
|
-
})),
|
|
64
|
-
};
|
package/output.disassembled.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// fn_0_0:
|
|
2
|
-
r1 = 969
|
|
3
|
-
r2 = r1
|
|
4
|
-
// while_top_5:
|
|
5
|
-
r3 = 4439
|
|
6
|
-
r4 = r2 !== r3
|
|
7
|
-
if (!r4) goto: while_exit_6
|
|
8
|
-
r5 = 969
|
|
9
|
-
r6 = r2 === r5
|
|
10
|
-
if (!r6) goto: if_else_7
|
|
11
|
-
goto: cff_block_2
|
|
12
|
-
// if_else_7:
|
|
13
|
-
r7 = 1317
|
|
14
|
-
r8 = r2 === r7
|
|
15
|
-
if (!r8) goto: if_else_8
|
|
16
|
-
goto: cff_block_3
|
|
17
|
-
// if_else_8:
|
|
18
|
-
r9 = 58894
|
|
19
|
-
r10 = r2 === r9
|
|
20
|
-
if (!r10) goto: if_else_9
|
|
21
|
-
goto: if_else_1
|
|
22
|
-
// if_else_9:
|
|
23
|
-
goto: while_top_5
|
|
24
|
-
// while_exit_6:
|
|
25
|
-
// cff_block_3:
|
|
26
|
-
r11 = "Hello World"
|
|
27
|
-
r0 = r11
|
|
28
|
-
r2 = 58894
|
|
29
|
-
goto: while_top_5
|
|
30
|
-
// if_else_1:
|
|
31
|
-
r11 = undefined
|
|
32
|
-
return r11
|
|
33
|
-
// cff_block_2:
|
|
34
|
-
r0 = undefined
|
|
35
|
-
r11 = true
|
|
36
|
-
if (r11) goto: cff_skip_10
|
|
37
|
-
r2 = 58894
|
|
38
|
-
goto: while_top_5
|
|
39
|
-
// cff_skip_10:
|
|
40
|
-
r2 = 1317
|
|
41
|
-
goto: while_top_5
|
package/src/build-runtime.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { generate } from "@babel/generator";
|
|
2
|
-
import { parse } from "@babel/parser";
|
|
3
|
-
import type * as t from "@babel/types";
|
|
4
|
-
import type { Options } from "./options.ts";
|
|
5
|
-
import { applyMacroOpcodes } from "./transforms/runtime/macroOpcodes.ts";
|
|
6
|
-
import { applyShuffleOpcodes } from "./transforms/runtime/shuffleOpcodes.ts";
|
|
7
|
-
import { applyMinify } from "./transforms/runtime/minify.ts";
|
|
8
|
-
import { Compiler } from "./compiler.ts";
|
|
9
|
-
import { applySpecializedOpcodes } from "./transforms/runtime/specializedOpcodes.ts";
|
|
10
|
-
import { applyAliasedOpcodes } from "./transforms/runtime/aliasedOpcodes.ts";
|
|
11
|
-
import { applyClassObfuscation } from "./transforms/runtime/classObfuscation.ts";
|
|
12
|
-
import type * as b from "./types.ts";
|
|
13
|
-
import { getSwitchStatement } from "./utils/ast-utils.ts";
|
|
14
|
-
import { now } from "./utils/profile-utils.ts";
|
|
15
|
-
|
|
16
|
-
export async function buildRuntime(
|
|
17
|
-
runtime: string,
|
|
18
|
-
bytecode: b.Bytecode,
|
|
19
|
-
options: Options,
|
|
20
|
-
compiler: Compiler,
|
|
21
|
-
generateBytecodeComment: () => string,
|
|
22
|
-
) {
|
|
23
|
-
let ast: t.File;
|
|
24
|
-
try {
|
|
25
|
-
ast = parse(runtime, { sourceType: "unambiguous" });
|
|
26
|
-
} catch (error) {
|
|
27
|
-
throw new Error("VM-Runtime final parsing failed", { cause: error });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const switchStatement = getSwitchStatement(ast);
|
|
31
|
-
const getHandlerCount = () => {
|
|
32
|
-
return switchStatement.cases.length;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const timings: { [name: string]: number } = {};
|
|
36
|
-
function runAndTime(pass: typeof applySpecializedOpcodes, name: string) {
|
|
37
|
-
const startedAt = now();
|
|
38
|
-
|
|
39
|
-
compiler.log(`Running runtime pass ${name}...`);
|
|
40
|
-
|
|
41
|
-
pass(ast, compiler);
|
|
42
|
-
|
|
43
|
-
const endedAt = now();
|
|
44
|
-
const elapsedMs = endedAt - startedAt;
|
|
45
|
-
timings[name] = elapsedMs;
|
|
46
|
-
|
|
47
|
-
compiler.profileData.transforms[name] = {
|
|
48
|
-
fileSize: null, // TODO: Add option as doing 'generate(ast).code.length' is slow
|
|
49
|
-
transformTime: elapsedMs,
|
|
50
|
-
handlerCount: getHandlerCount(),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
compiler.log(
|
|
54
|
-
`Runtime pass ${name} completed in ${Math.floor(elapsedMs)}ms`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Specialized opcode cases must be applied BEFORE shuffleOpcodes
|
|
59
|
-
if (options.specializedOpcodes) {
|
|
60
|
-
runAndTime(applySpecializedOpcodes, "applySpecializedOpcodes");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Macro opcode cases must be applied BEFORE shuffleOpcodes
|
|
64
|
-
if (options.macroOpcodes && Object.keys(compiler.MACRO_OPS).length > 0) {
|
|
65
|
-
runAndTime(applyMacroOpcodes, "applyMacroOpcodes");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Aliased opcode cases must be applied BEFORE shuffleOpcodes
|
|
69
|
-
if (options.aliasedOpcodes) {
|
|
70
|
-
runAndTime(applyAliasedOpcodes, "applyAliasedOpcodes");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Shuffle opcode handle order
|
|
74
|
-
if (options.shuffleOpcodes) {
|
|
75
|
-
runAndTime(applyShuffleOpcodes, "applyShuffleOpcodes");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Shuffle top-level var declarations and prototype method definitions
|
|
79
|
-
if (options.classObfuscation) {
|
|
80
|
-
runAndTime(applyClassObfuscation, "applyClassObfuscation");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
compiler.profileData.handlerCount = getHandlerCount();
|
|
84
|
-
|
|
85
|
-
let generated: string;
|
|
86
|
-
try {
|
|
87
|
-
generated = generate(ast).code;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
throw new Error("VM-Runtime final generation failed", { cause: error });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Add comment here for more accurate opcode names
|
|
93
|
-
generated = generateBytecodeComment() + "\n" + generated;
|
|
94
|
-
|
|
95
|
-
// Minify code?
|
|
96
|
-
if (options.minify) {
|
|
97
|
-
try {
|
|
98
|
-
let startedAt = now();
|
|
99
|
-
compiler.log("Running minify...");
|
|
100
|
-
generated = await applyMinify(generated);
|
|
101
|
-
let elapsedMs = now() - startedAt;
|
|
102
|
-
compiler.log(`Minify completed in ${Math.floor(elapsedMs)}ms`);
|
|
103
|
-
|
|
104
|
-
compiler.profileData.transforms["minify"] = {
|
|
105
|
-
transformTime: elapsedMs,
|
|
106
|
-
};
|
|
107
|
-
} catch (error) {
|
|
108
|
-
throw new Error("VM-Runtime final minification failed", { cause: error });
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return generated;
|
|
113
|
-
}
|