js-confuser-vm 0.0.2 → 0.0.3
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 +28 -0
- package/README.MD +16 -10
- package/babel-plugin-inline-runtime.cjs +34 -0
- package/babel.config.json +2 -3
- package/dist/compiler.js +687 -421
- package/dist/index.js +2 -1
- package/dist/options.js +1 -1
- package/dist/runtime.js +598 -463
- package/dist/runtimeObf.js +26 -6
- package/dist/transforms/controlFlowFlattening.js +22 -0
- package/dist/transforms/resolveContants.js +33 -0
- package/dist/transforms/resolveLabels.js +59 -0
- package/dist/transforms/selfModifying.js +107 -0
- package/dist/types.js +13 -0
- package/index.ts +0 -6
- package/jest.config.js +10 -0
- package/package.json +1 -1
- package/src/compiler.ts +876 -487
- package/src/index.ts +2 -1
- package/src/options.ts +2 -0
- package/src/runtime.ts +589 -455
- package/src/runtimeObf.ts +22 -8
- package/src/transforms/controlFlowFlattening.ts +30 -0
- package/src/transforms/resolveContants.ts +42 -0
- package/src/transforms/resolveLabels.ts +83 -0
- package/src/transforms/selfModifying.ts +124 -0
- package/src/types.ts +24 -0
- package/dist/minify_empty_externs.js +0 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
## `1.0.3` First update
|
|
2
|
+
|
|
3
|
+
- Created [Website Playground](https://development--confuser.netlify.app/vm)
|
|
4
|
+
|
|
5
|
+
- Added partial support for `try..catch` - The `finally` operator is not supported yet
|
|
6
|
+
- More ES5 coverage: getter/setters, debugger statement
|
|
7
|
+
- Improved compilation process:
|
|
8
|
+
- Parsing:
|
|
9
|
+
JS -> AST
|
|
10
|
+
Done by [@babel/parser](https://www.npmjs.com/package/@babel/parser)
|
|
11
|
+
- Compilation:
|
|
12
|
+
AST -> IR bytecode.
|
|
13
|
+
This bytecode contains pseudo instructions and symbolic values for things like jump labels and constants
|
|
14
|
+
- Transform passes (Assembler):
|
|
15
|
+
Transform passes obfuscate and finally prepare the pseudo bytecode to be runnable. Here, all jump labels get converted into absolute PCs
|
|
16
|
+
- Serializer:
|
|
17
|
+
The bytecode is printed into the array form or encoded string if you have `encodeBytecode` enabled
|
|
18
|
+
- Generating:
|
|
19
|
+
This includes two sub-stages:
|
|
20
|
+
- 1) Creating (another parsing->transforming->generating) the VM Runtime with the given options (randomized op codes, shuffled handlers)
|
|
21
|
+
- 2) Placing the final bytecode into this VM Runtime
|
|
22
|
+
|
|
23
|
+
- Typescript is now transpiled for NPM
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## `1.0.2` First release
|
|
28
|
+
|
package/README.MD
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# JS Confuser VM
|
|
2
2
|
|
|
3
|
-
[](https://npmjs.com/package/js-confuser-vm) [](https://github.com/MichaelXF/js-confuser-vm)
|
|
3
|
+
[](https://npmjs.com/package/js-confuser-vm) [](https://github.com/MichaelXF/js-confuser-vm) [](https://development--confuser.netlify.app/vm)
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
- **Requires Node v24.13.1 or higher**
|
|
7
|
-
- ES5 support only. No complex features: async, generator, and even try..
|
|
7
|
+
- ES5 support only. No complex features: async, generator, and even try..finally are beyond scope.
|
|
8
8
|
- Experimental. Expect issues.
|
|
9
|
+
- [Try the web version.](https://development--confuser.netlify.app/vm)
|
|
9
10
|
|
|
10
11
|
### Installation
|
|
11
12
|
|
|
@@ -39,6 +40,7 @@ JsConfuserVM.obfuscate(`
|
|
|
39
40
|
encodeBytecode: true, // encode bytecode? when off, comments for instructions are added
|
|
40
41
|
selfModifying: true, // do self-modifying bytecode for function bodies?
|
|
41
42
|
timingChecks: true, // add timing checks to detect debuggers?
|
|
43
|
+
minify: true // pass final output through Google Closure Compiler? (Renames VM class properties)
|
|
42
44
|
}).then(result => {
|
|
43
45
|
console.log(result.code)
|
|
44
46
|
})
|
|
@@ -88,13 +90,15 @@ G(new x(d("4AMAANUEAAAjAQAA1QUAAKEFAAAjBgAAGQAAAK0YAAChBwAAIwgAAEsAAAChBQAAoQQAA
|
|
|
88
90
|
- [x] labeled statements
|
|
89
91
|
- [x] for..in loop
|
|
90
92
|
- [x] RegExp literals
|
|
93
|
+
- [x] try..catch
|
|
94
|
+
- [x] getter/setters
|
|
95
|
+
- [x] debugger;
|
|
91
96
|
|
|
92
97
|
### Missing
|
|
93
98
|
|
|
94
|
-
- [ ] try..
|
|
99
|
+
- [ ] try..finally
|
|
95
100
|
- [ ] with statement
|
|
96
101
|
- [ ] arguments.callee, argument parameter syncing
|
|
97
|
-
- [ ] getter/setters
|
|
98
102
|
|
|
99
103
|
### Hardening
|
|
100
104
|
|
|
@@ -116,16 +120,18 @@ G(new x(d("4AMAANUEAAAjAQAA1QUAAKEFAAAjBgAAGQAAAK0YAAChBwAAIwgAAEsAAAChBQAAoQQAA
|
|
|
116
120
|
|
|
117
121
|
The `minify` option uses Google Closure Compiler to minify the JS VM and renames (most) VM property names. This approach helps keep the VM Compiler simple and lets Google do the heavy lifting.
|
|
118
122
|
|
|
119
|
-
### No Try
|
|
123
|
+
### No Try Finally
|
|
120
124
|
|
|
121
|
-
Try
|
|
125
|
+
While Try Catch is supported, Try..Finally is not. You can use Try..Finally by defining an outside helper function:
|
|
122
126
|
|
|
123
127
|
```js
|
|
124
|
-
function
|
|
128
|
+
function TryFinally(cb, _finally) {
|
|
125
129
|
try {
|
|
126
|
-
return { value: cb() }
|
|
130
|
+
return { value: cb() }
|
|
127
131
|
} catch (error) {
|
|
128
132
|
return { error };
|
|
133
|
+
} finally {
|
|
134
|
+
_finally()
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
```
|
|
@@ -179,8 +185,8 @@ main().catch(console.error);
|
|
|
179
185
|
|
|
180
186
|
### WIP
|
|
181
187
|
|
|
182
|
-
-
|
|
183
|
-
- [Test262 (es5-tests)](https://github.com/tc39/test262/tree/es5-tests) percentage:
|
|
188
|
+
- 178 tests, 91.18% coverage
|
|
189
|
+
- [Test262 (es5-tests)](https://github.com/tc39/test262/tree/es5-tests) percentage: 66.67%
|
|
184
190
|
|
|
185
191
|
### Made with AI
|
|
186
192
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { readFileSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
const babel = require("@babel/core");
|
|
4
|
+
const { stripTypeScriptTypes } = require("node:module");
|
|
5
|
+
|
|
6
|
+
module.exports = function inlineRuntimePlugin({ types: t }) {
|
|
7
|
+
const rawContent = readFileSync(join(__dirname, "./src/runtime.ts"), "utf-8");
|
|
8
|
+
|
|
9
|
+
const runtimeContent = stripTypeScriptTypes(rawContent);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: "inline-runtime",
|
|
13
|
+
visitor: {
|
|
14
|
+
VariableDeclarator(path) {
|
|
15
|
+
if (
|
|
16
|
+
path.node.id?.name === "readVMRuntimeFile" &&
|
|
17
|
+
(path.node.init?.type === "ArrowFunctionExpression" ||
|
|
18
|
+
path.node.init?.type === "FunctionExpression")
|
|
19
|
+
) {
|
|
20
|
+
path.node.init = t.arrowFunctionExpression(
|
|
21
|
+
[],
|
|
22
|
+
t.stringLiteral(runtimeContent),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
ImportDeclaration(path) {
|
|
27
|
+
const src = path.node.source.value;
|
|
28
|
+
if (src === "fs" || src === "path") {
|
|
29
|
+
path.remove();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|