js-confuser-vm 0.0.4 → 0.0.5
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/CHANGELOG.md +1 -1
- package/dist/build-runtime.js +53 -0
- package/dist/compiler.js +1761 -0
- package/dist/index.js +10 -0
- package/dist/minify.js +18 -0
- package/dist/options.js +1 -0
- package/dist/runtime.js +749 -0
- package/dist/transforms/bytecode/macroOpcodes.js +152 -0
- package/dist/transforms/bytecode/resolveContants.js +43 -0
- package/dist/transforms/bytecode/resolveLabels.js +80 -0
- package/dist/transforms/bytecode/selfModifying.js +107 -0
- package/dist/transforms/bytecode/specializedOpcodes.js +103 -0
- package/dist/transforms/runtime/macroOpcodes.js +88 -0
- package/dist/transforms/runtime/minify.js +1 -0
- package/dist/transforms/runtime/shuffleOpcodes.js +20 -0
- package/dist/transforms/runtime/specializedOpcodes.js +102 -0
- package/dist/transforms/utils/op-utils.js +25 -0
- package/dist/transforms/utils/random-utils.js +27 -0
- package/dist/types.js +15 -0
- package/dist/utilts.js +3 -0
- package/package.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { generate } from "@babel/generator";
|
|
2
|
+
import { parse } from "@babel/parser";
|
|
3
|
+
import { applyMacroOpcodes } from "./transforms/runtime/macroOpcodes.js";
|
|
4
|
+
import { applyShuffleOpcodes } from "./transforms/runtime/shuffleOpcodes.js";
|
|
5
|
+
import { applyMinify } from "./transforms/runtime/minify.js";
|
|
6
|
+
import { applySpecializedOpcodes } from "./transforms/runtime/specializedOpcodes.js";
|
|
7
|
+
export async function obfuscateRuntime(runtime, bytecode, options, compiler) {
|
|
8
|
+
let ast;
|
|
9
|
+
try {
|
|
10
|
+
ast = parse(runtime, {
|
|
11
|
+
sourceType: "unambiguous"
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
throw new Error("VM-Runtime final parsing failed", {
|
|
15
|
+
cause: error
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Macro opcode cases must be applied BEFORE shuffleOpcodes
|
|
20
|
+
if (options.specializedOpcodes) {
|
|
21
|
+
applySpecializedOpcodes(ast, bytecode, compiler);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Macro opcode cases must be applied BEFORE shuffleOpcodes
|
|
25
|
+
if (options.macroOpcodes && Object.keys(compiler.MACRO_OPS).length > 0) {
|
|
26
|
+
applyMacroOpcodes(ast, compiler);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Shuffle opcode handle order
|
|
30
|
+
if (options.shuffleOpcodes) {
|
|
31
|
+
applyShuffleOpcodes(ast);
|
|
32
|
+
}
|
|
33
|
+
let generated;
|
|
34
|
+
try {
|
|
35
|
+
generated = generate(ast).code;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error("VM-Runtime final generation failed", {
|
|
38
|
+
cause: error
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Minify code?
|
|
43
|
+
if (options.minify) {
|
|
44
|
+
try {
|
|
45
|
+
generated = await applyMinify(generated);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("VM-Runtime final minification failed", {
|
|
48
|
+
cause: error
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return generated;
|
|
53
|
+
}
|