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 CHANGED
@@ -1,4 +1,4 @@
1
- ## `0.0.4` Generated Opcodes
1
+ ## `0.0.5` Generated Opcodes
2
2
 
3
3
  - Added new option `specializedOpcodes` which creates specialized opcodes for commonly used opcode+operand pairs.
4
4
 
@@ -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
+ }