js-confuser-vm 0.0.3 → 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 +125 -28
- package/LICENSE +21 -21
- package/README.MD +370 -196
- package/babel-plugin-inline-runtime.cjs +34 -34
- package/babel.config.json +23 -23
- package/dist/build-runtime.js +53 -0
- package/dist/compiler.js +107 -117
- package/dist/runtime.js +78 -84
- package/dist/transforms/bytecode/macroOpcodes.js +152 -0
- package/dist/transforms/{resolveContants.js → bytecode/resolveContants.js} +16 -6
- package/dist/transforms/bytecode/resolveLabels.js +80 -0
- package/dist/transforms/{selfModifying.js → bytecode/selfModifying.js} +33 -33
- 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/{random.js → transforms/utils/random-utils.js} +3 -3
- package/dist/types.js +4 -2
- package/index.ts +34 -22
- package/jest-strip-types.js +10 -10
- package/jest.config.js +35 -28
- package/package.json +49 -48
- package/src/build-runtime.ts +57 -0
- package/src/compiler.ts +2069 -2066
- package/src/index.ts +14 -14
- package/src/minify.ts +21 -21
- package/src/options.ts +14 -12
- package/src/runtime.ts +771 -779
- package/src/transforms/bytecode/macroOpcodes.ts +177 -0
- package/src/transforms/bytecode/resolveContants.ts +62 -0
- package/src/transforms/bytecode/resolveLabels.ts +107 -0
- package/src/transforms/{selfModifying.ts → bytecode/selfModifying.ts} +37 -40
- package/src/transforms/bytecode/specializedOpcodes.ts +118 -0
- package/src/transforms/runtime/macroOpcodes.ts +111 -0
- package/src/transforms/runtime/minify.ts +1 -0
- package/src/transforms/runtime/shuffleOpcodes.ts +24 -0
- package/src/transforms/runtime/specializedOpcodes.ts +146 -0
- package/src/transforms/utils/op-utils.ts +26 -0
- package/src/{random.ts → transforms/utils/random-utils.ts} +31 -31
- package/src/types.ts +33 -24
- package/src/utilts.ts +3 -3
- package/tsconfig.json +12 -12
- package/dist/runtimeObf.js +0 -56
- package/dist/transforms/controlFlowFlattening.js +0 -22
- package/dist/transforms/resolveLabels.js +0 -59
- package/src/runtimeObf.ts +0 -62
- package/src/transforms/controlFlowFlattening.ts +0 -30
- package/src/transforms/resolveContants.ts +0 -42
- package/src/transforms/resolveLabels.ts +0 -83
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,125 @@
|
|
|
1
|
-
## `
|
|
2
|
-
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
## `0.0.5` 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.
|