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 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
- [![NPM](https://img.shields.io/badge/NPM-%23000000.svg?style=for-the-badge&logo=npm&logoColor=white)](https://npmjs.com/package/js-confuser-vm) [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/MichaelXF/js-confuser-vm)
3
+ [![NPM](https://img.shields.io/badge/NPM-%23000000.svg?style=for-the-badge&logo=npm&logoColor=white)](https://npmjs.com/package/js-confuser-vm) [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/MichaelXF/js-confuser-vm) [![Netlify](https://img.shields.io/badge/netlify-%23000000.svg?style=for-the-badge&logo=netlify&logoColor=#00C7B7)](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..catch are beyond scope.
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..catch
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 Catch
123
+ ### No Try Finally
120
124
 
121
- Try..Catch is complex operator that may not get added. You can use Try..Catch by defining an outside helper function:
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 TryCatch(cb) {
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
- - 146 tests, 91.18% coverage
183
- - [Test262 (es5-tests)](https://github.com/tc39/test262/tree/es5-tests) percentage: 52.39%
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
+ };
package/babel.config.json CHANGED
@@ -9,11 +9,10 @@
9
9
  "modules": false
10
10
  }
11
11
  ],
12
- [
13
- "@babel/preset-typescript"
14
- ]
12
+ ["@babel/preset-typescript"]
15
13
  ],
16
14
  "plugins": [
15
+ "./babel-plugin-inline-runtime.cjs",
17
16
  [
18
17
  "replace-import-extension",
19
18
  {