js-confuser-vm 0.1.0 → 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 +281 -147
- package/dist/build-runtime.js +41 -15
- package/dist/compiler.js +714 -265
- package/dist/disassembler.js +367 -0
- package/dist/index.js +7 -2
- package/dist/runtime.js +160 -119
- package/dist/template.js +163 -42
- package/dist/transforms/bytecode/aliasedOpcodes.js +4 -1
- package/dist/transforms/bytecode/concealConstants.js +2 -2
- package/dist/transforms/bytecode/controlFlowFlattening.js +569 -0
- package/dist/transforms/bytecode/dispatcher.js +15 -111
- package/dist/transforms/bytecode/macroOpcodes.js +2 -2
- package/{src/transforms/bytecode/resolveContants.ts → dist/transforms/bytecode/resolveConstants.js} +30 -56
- package/dist/transforms/bytecode/resolveRegisters.js +23 -4
- package/dist/transforms/bytecode/selfModifying.js +88 -21
- package/dist/transforms/bytecode/semanticOpcodes.js +162 -0
- package/dist/transforms/bytecode/specializedOpcodes.js +23 -12
- package/dist/transforms/bytecode/stringConcealing.js +288 -0
- package/dist/transforms/runtime/classObfuscation.js +43 -0
- package/dist/transforms/runtime/handlerTable.js +91 -0
- package/dist/transforms/runtime/semanticOpcodes.js +35 -0
- package/dist/transforms/runtime/specializedOpcodes.js +11 -5
- package/dist/types.js +1 -1
- package/dist/utils/ast-utils.js +75 -0
- package/dist/utils/op-utils.js +1 -2
- package/dist/utils/pass-utils.js +100 -0
- package/dist/utils/profile-utils.js +3 -0
- package/package.json +8 -1
- package/.gitmodules +0 -4
- package/.prettierignore +0 -1
- package/CHANGELOG.md +0 -335
- package/babel-plugin-inline-runtime.cjs +0 -34
- package/babel.config.json +0 -23
- package/index.ts +0 -38
- package/jest-strip-types.js +0 -10
- package/jest.config.js +0 -52
- package/src/build-runtime.ts +0 -78
- package/src/compiler.ts +0 -2593
- package/src/index.ts +0 -14
- package/src/minify.ts +0 -21
- package/src/options.ts +0 -18
- package/src/runtime.ts +0 -923
- package/src/template.ts +0 -141
- package/src/transforms/bytecode/aliasedOpcodes.ts +0 -148
- package/src/transforms/bytecode/concealConstants.ts +0 -52
- package/src/transforms/bytecode/dispatcher.ts +0 -398
- package/src/transforms/bytecode/macroOpcodes.ts +0 -193
- package/src/transforms/bytecode/microOpcodes.ts +0 -291
- package/src/transforms/bytecode/resolveLabels.ts +0 -112
- package/src/transforms/bytecode/resolveRegisters.ts +0 -221
- package/src/transforms/bytecode/selfModifying.ts +0 -121
- package/src/transforms/bytecode/specializedOpcodes.ts +0 -153
- package/src/transforms/runtime/aliasedOpcodes.ts +0 -191
- package/src/transforms/runtime/internalVariables.ts +0 -270
- package/src/transforms/runtime/macroOpcodes.ts +0 -138
- package/src/transforms/runtime/microOpcodes.ts +0 -93
- package/src/transforms/runtime/minify.ts +0 -1
- package/src/transforms/runtime/shuffleOpcodes.ts +0 -24
- package/src/transforms/runtime/specializedOpcodes.ts +0 -156
- package/src/types.ts +0 -93
- package/src/utils/op-utils.ts +0 -48
- package/src/utils/random-utils.ts +0 -31
- package/tsconfig.json +0 -12
package/dist/build-runtime.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { generate } from "@babel/generator";
|
|
2
2
|
import { parse } from "@babel/parser";
|
|
3
3
|
import { applyMacroOpcodes } from "./transforms/runtime/macroOpcodes.js";
|
|
4
|
-
import { applyMicroOpcodes } from "./transforms/runtime/microOpcodes.js";
|
|
5
|
-
import { applyInteralVariablesToRuntime } from "./transforms/runtime/internalVariables.js";
|
|
6
4
|
import { applyShuffleOpcodes } from "./transforms/runtime/shuffleOpcodes.js";
|
|
7
5
|
import { applyMinify } from "./transforms/runtime/minify.js";
|
|
8
6
|
import { applySpecializedOpcodes } from "./transforms/runtime/specializedOpcodes.js";
|
|
9
7
|
import { applyAliasedOpcodes } from "./transforms/runtime/aliasedOpcodes.js";
|
|
10
|
-
|
|
8
|
+
import { applyClassObfuscation } from "./transforms/runtime/classObfuscation.js";
|
|
9
|
+
import { getSwitchStatement } from "./utils/ast-utils.js";
|
|
10
|
+
import { now } from "./utils/profile-utils.js";
|
|
11
|
+
export async function buildRuntime(runtime, bytecode, options, compiler, generateBytecodeComment) {
|
|
11
12
|
let ast;
|
|
12
13
|
try {
|
|
13
14
|
ast = parse(runtime, {
|
|
@@ -18,34 +19,52 @@ export async function obfuscateRuntime(runtime, bytecode, options, compiler, gen
|
|
|
18
19
|
cause: error
|
|
19
20
|
});
|
|
20
21
|
}
|
|
22
|
+
const switchStatement = getSwitchStatement(ast);
|
|
23
|
+
const getHandlerCount = () => {
|
|
24
|
+
return switchStatement.cases.length;
|
|
25
|
+
};
|
|
26
|
+
const timings = {};
|
|
27
|
+
function runAndTime(pass, name) {
|
|
28
|
+
const startedAt = now();
|
|
29
|
+
compiler.log(`Running runtime pass ${name}...`);
|
|
30
|
+
pass(ast, compiler);
|
|
31
|
+
const endedAt = now();
|
|
32
|
+
const elapsedMs = endedAt - startedAt;
|
|
33
|
+
timings[name] = elapsedMs;
|
|
34
|
+
compiler.profileData.transforms[name] = {
|
|
35
|
+
fileSize: null,
|
|
36
|
+
// TODO: Add option as doing 'generate(ast).code.length' is slow
|
|
37
|
+
transformTime: elapsedMs,
|
|
38
|
+
handlerCount: getHandlerCount()
|
|
39
|
+
};
|
|
40
|
+
compiler.log(`Runtime pass ${name} completed in ${Math.floor(elapsedMs)}ms`);
|
|
41
|
+
}
|
|
21
42
|
|
|
22
43
|
// Specialized opcode cases must be applied BEFORE shuffleOpcodes
|
|
23
44
|
if (options.specializedOpcodes) {
|
|
24
|
-
applySpecializedOpcodes
|
|
25
|
-
}
|
|
26
|
-
if (options.microOpcodes) {
|
|
27
|
-
applyInteralVariablesToRuntime(ast, compiler);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Micro opcode cases must be applied BEFORE shuffleOpcodes
|
|
31
|
-
if (options.microOpcodes && Object.keys(compiler.MICRO_OPS).length > 0) {
|
|
32
|
-
applyMicroOpcodes(ast, compiler);
|
|
45
|
+
runAndTime(applySpecializedOpcodes, "applySpecializedOpcodes");
|
|
33
46
|
}
|
|
34
47
|
|
|
35
48
|
// Macro opcode cases must be applied BEFORE shuffleOpcodes
|
|
36
49
|
if (options.macroOpcodes && Object.keys(compiler.MACRO_OPS).length > 0) {
|
|
37
|
-
applyMacroOpcodes
|
|
50
|
+
runAndTime(applyMacroOpcodes, "applyMacroOpcodes");
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
// Aliased opcode cases must be applied BEFORE shuffleOpcodes
|
|
41
54
|
if (options.aliasedOpcodes) {
|
|
42
|
-
applyAliasedOpcodes
|
|
55
|
+
runAndTime(applyAliasedOpcodes, "applyAliasedOpcodes");
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
// Shuffle opcode handle order
|
|
46
59
|
if (options.shuffleOpcodes) {
|
|
47
|
-
applyShuffleOpcodes
|
|
60
|
+
runAndTime(applyShuffleOpcodes, "applyShuffleOpcodes");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Shuffle top-level var declarations and prototype method definitions
|
|
64
|
+
if (options.classObfuscation) {
|
|
65
|
+
runAndTime(applyClassObfuscation, "applyClassObfuscation");
|
|
48
66
|
}
|
|
67
|
+
compiler.profileData.handlerCount = getHandlerCount();
|
|
49
68
|
let generated;
|
|
50
69
|
try {
|
|
51
70
|
generated = generate(ast).code;
|
|
@@ -61,7 +80,14 @@ export async function obfuscateRuntime(runtime, bytecode, options, compiler, gen
|
|
|
61
80
|
// Minify code?
|
|
62
81
|
if (options.minify) {
|
|
63
82
|
try {
|
|
83
|
+
let startedAt = now();
|
|
84
|
+
compiler.log("Running minify...");
|
|
64
85
|
generated = await applyMinify(generated);
|
|
86
|
+
let elapsedMs = now() - startedAt;
|
|
87
|
+
compiler.log(`Minify completed in ${Math.floor(elapsedMs)}ms`);
|
|
88
|
+
compiler.profileData.transforms["minify"] = {
|
|
89
|
+
transformTime: elapsedMs
|
|
90
|
+
};
|
|
65
91
|
} catch (error) {
|
|
66
92
|
throw new Error("VM-Runtime final minification failed", {
|
|
67
93
|
cause: error
|