js-confuser-vm 0.0.2 → 0.0.4

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/LICENSE +21 -21
  3. package/README.MD +370 -190
  4. package/babel-plugin-inline-runtime.cjs +34 -0
  5. package/babel.config.json +23 -24
  6. package/index.ts +34 -28
  7. package/jest-strip-types.js +10 -10
  8. package/jest.config.js +35 -18
  9. package/package.json +50 -48
  10. package/src/build-runtime.ts +57 -0
  11. package/src/compiler.ts +2069 -1677
  12. package/src/index.ts +14 -13
  13. package/src/minify.ts +21 -21
  14. package/src/options.ts +14 -10
  15. package/src/runtime.ts +771 -645
  16. package/src/transforms/bytecode/macroOpcodes.ts +177 -0
  17. package/src/transforms/bytecode/resolveContants.ts +62 -0
  18. package/src/transforms/bytecode/resolveLabels.ts +107 -0
  19. package/src/transforms/bytecode/selfModifying.ts +121 -0
  20. package/src/transforms/bytecode/specializedOpcodes.ts +118 -0
  21. package/src/transforms/runtime/macroOpcodes.ts +111 -0
  22. package/src/transforms/runtime/minify.ts +1 -0
  23. package/src/transforms/runtime/shuffleOpcodes.ts +24 -0
  24. package/src/transforms/runtime/specializedOpcodes.ts +146 -0
  25. package/src/transforms/utils/op-utils.ts +26 -0
  26. package/src/{random.ts → transforms/utils/random-utils.ts} +31 -31
  27. package/src/types.ts +33 -0
  28. package/src/utilts.ts +3 -3
  29. package/tsconfig.json +12 -12
  30. package/dist/compiler.js +0 -1505
  31. package/dist/index.js +0 -9
  32. package/dist/minify.js +0 -18
  33. package/dist/minify_empty_externs.js +0 -4
  34. package/dist/options.js +0 -1
  35. package/dist/random.js +0 -27
  36. package/dist/runtime.js +0 -620
  37. package/dist/runtimeObf.js +0 -36
  38. package/dist/utilts.js +0 -3
  39. package/src/runtimeObf.ts +0 -48
package/CHANGELOG.md ADDED
@@ -0,0 +1,125 @@
1
+ ## `0.0.4` Generated Opcodes
2
+
3
+ - Added new option `specializedOpcodes` which creates specialized opcodes for commonly used opcode+operand pairs.
4
+
5
+ ```js
6
+ // Input Code
7
+ console.log("Hello world!");
8
+
9
+ // Before
10
+ // [3, 0], LOAD_GLOBAL "console" 1:0-1:7
11
+ // [0, 1], LOAD_CONST "log" 1:0-1:27
12
+ // [5], GET_PROP 1:0-1:27
13
+ // [0, 2], LOAD_CONST "Hello world!" 1:12-1:26
14
+ // [12, 1], CALL_METHOD (1 args) 1:0-1:27
15
+ // [14], POP 1:0-1:28
16
+
17
+ // What the opcode "LOAD_GLOBAL" looks like:
18
+ case OP.LOAD_CONST:
19
+ this._push(this.constants[this._operand()]);
20
+ break;
21
+
22
+ // After
23
+ // [64], LOAD_GLOBAL_0 1:0-1:7
24
+ // [65], LOAD_CONST_1 1:0-1:27
25
+ // [5], GET_PROP 1:0-1:27
26
+ // [66], LOAD_CONST_2 1:12-1:26
27
+ // [67], CALL_METHOD_1 1:0-1:27
28
+ // [14], POP 1:0-1:28
29
+
30
+ // What the opcode "LOAD_GLOBAL_0" (64) looks like:
31
+ case 64:
32
+ // LOAD_GLOBAL_0 (specialized)
33
+ this._push(this.globals[this.constants[0]]);
34
+ break;
35
+ ```
36
+
37
+ - Added new option `macroOpcodes` which combines multiple opcodes commonly used from your bytecode
38
+
39
+ ```js
40
+ // Input Code
41
+ console.log("Hello world!");
42
+ console.log("Hello world!");
43
+
44
+ // Before
45
+ // [3, 0], LOAD_GLOBAL "console" 1:0-1:7
46
+ // [0, 1], LOAD_CONST "log" 1:0-1:27
47
+ // [5], GET_PROP 1:0-1:27
48
+ // [0, 2], LOAD_CONST "Hello world!" 1:12-1:26
49
+ // [12, 1], CALL_METHOD (1 args) 1:0-1:27
50
+ // [14], POP 1:0-1:28
51
+ // [3, 0], LOAD_GLOBAL "console" 2:0-2:7
52
+ // [0, 1], LOAD_CONST "log" 2:0-2:27
53
+ // [5], GET_PROP 2:0-2:27
54
+ // [0, 2], LOAD_CONST "Hello world!" 2:12-2:26
55
+ // [12, 1], CALL_METHOD (1 args) 2:0-2:27
56
+ // [14], POP 2:0-2:28
57
+
58
+ // After
59
+ // [64, 0, 1, 2], LOAD_GLOBAL,LOAD_CONST,GET_PROP,LOAD_CONST [0, 1, 2]
60
+ // [12, 1], CALL_METHOD (1 args) 1:0-1:27
61
+ // [14], POP 1:0-1:28
62
+ // [64, 0, 1, 2], LOAD_GLOBAL,LOAD_CONST,GET_PROP,LOAD_CONST [0, 1, 2]
63
+ // [12, 1], CALL_METHOD (1 args) 2:0-2:27
64
+ // [14], POP 2:0-2:28
65
+
66
+ // What the opcode "LOAD_GLOBAL,LOAD_CONST,GET_PROP,LOAD_CONST" (64) looks like:
67
+ case 64:
68
+ {
69
+ // LOAD_GLOBAL
70
+ this._push(this.globals[this.constants[this._operand()]]);
71
+ // LOAD_CONST
72
+ this._push(this.constants[this._operand()]);
73
+ // GET_PROP
74
+ // Stack: [..., obj, key] -> [..., obj, obj[key]]
75
+ // obj is PEEKED (not popped) - CALL_METHOD needs it as receiver
76
+ var key = this._pop();
77
+ var obj = this.peek();
78
+ this._push(obj[key]);
79
+ // LOAD_CONST
80
+ this._push(this.constants[this._operand()]);
81
+ break;
82
+ }
83
+ ```
84
+
85
+ - Flattened the bytecode. Now, instructions can read as many operands as needed, and it's unclear to distinguish between opcodes and operands:
86
+
87
+ ```js
88
+ // Before (Operands clearly visible)
89
+ var BYTECODE = [[3, 0], [0, 1], [5, undefined], [0, 2], [12, 1], [14, undefined], [3, 0], [0, 1], [5, undefined], [0, 2], [12, 1], [14, undefined], [13, undefined]];
90
+
91
+ // After (Flattened with multi-operand instruction support)
92
+ var BYTECODE = [3, 0, 0, 1, 5, 0, 2, 12, 1, 14, 3, 0, 0, 1, 5, 0, 2, 12, 1, 14, 13];
93
+ ```
94
+
95
+ - Changed the bytecode to use ushorts (16-bit ints) allowing a max value of 65,535 for opcodes and operands.
96
+
97
+
98
+ ## `0.0.3` First update
99
+
100
+ - Created [Website Playground](https://development--confuser.netlify.app/vm)
101
+
102
+ - Added partial support for `try..catch` - The `finally` operator is not supported yet
103
+ - More ES5 coverage: getter/setters, debugger statement
104
+ - Improved compilation process:
105
+ - Parsing:
106
+ JS -> AST
107
+ Done by [@babel/parser](https://www.npmjs.com/package/@babel/parser)
108
+ - Compilation:
109
+ AST -> IR bytecode.
110
+ This bytecode contains pseudo instructions and symbolic values for things like jump labels and constants
111
+ - Transform passes (Assembler):
112
+ Transform passes obfuscate and finally prepare the pseudo bytecode to be runnable. Here, all jump labels get converted into absolute PCs
113
+ - Serializer:
114
+ The bytecode is printed into the array form or encoded string if you have `encodeBytecode` enabled
115
+ - Generating:
116
+ This includes two sub-stages:
117
+ - 1) Creating (another parsing->transforming->generating) the VM Runtime with the given options (randomized op codes, shuffled handlers)
118
+ - 2) Placing the final bytecode into this VM Runtime
119
+
120
+ - Typescript is now transpiled for NPM
121
+
122
+
123
+
124
+ ## `0.0.2` First release
125
+
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Michael Brasington
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Brasington
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.