js-confuser-vm 0.0.1 → 0.0.2
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/README.MD +191 -0
- package/babel.config.json +24 -0
- package/dist/compiler.js +1505 -0
- package/dist/index.js +9 -0
- package/dist/minify.js +18 -0
- package/{minify_empty_externs.js → dist/minify_empty_externs.js} +1 -1
- package/dist/options.js +1 -0
- package/dist/random.js +27 -0
- package/dist/runtime.js +620 -0
- package/dist/runtimeObf.js +36 -0
- package/dist/utilts.js +3 -0
- package/index.ts +23 -12
- package/jest.config.js +16 -5
- package/package.json +13 -6
- package/src/compiler.ts +420 -360
- package/src/index.ts +13 -0
- package/src/minify.ts +21 -0
- package/src/options.ts +10 -0
- package/src/random.ts +31 -0
- package/src/runtime.ts +53 -39
- package/src/runtimeObf.ts +48 -0
- package/src/utilts.ts +3 -0
- package/.claude/settings.local.json +0 -8
- package/ReadME.MD +0 -164
- package/input.js +0 -15
- package/minify.js +0 -17
- package/obfuscate.js +0 -12
- package/src/index.js +0 -5
- package/src/random.js +0 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generate } from "@babel/generator";
|
|
2
|
+
import { parse } from "@babel/parser";
|
|
3
|
+
import traverseImport from "@babel/traverse";
|
|
4
|
+
import { ok } from "assert";
|
|
5
|
+
import { shuffle } from "./random.js";
|
|
6
|
+
import { minify } from "./minify.js";
|
|
7
|
+
const traverse = traverseImport.default;
|
|
8
|
+
export async function obfuscateRuntime(runtime, options) {
|
|
9
|
+
const ast = parse(runtime, {
|
|
10
|
+
sourceType: "unambiguous"
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// shuffle order of opcode handlers
|
|
14
|
+
|
|
15
|
+
if (options.shuffleOpcodes) {
|
|
16
|
+
let switchStatement = null;
|
|
17
|
+
traverse(ast, {
|
|
18
|
+
SwitchStatement(path) {
|
|
19
|
+
if (path.node.leadingComments?.some(comment => comment.value.includes("@SWITCH"))) {
|
|
20
|
+
switchStatement = path.node;
|
|
21
|
+
path.stop();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
ok(switchStatement, "Could not find opcode handlers switch statement");
|
|
26
|
+
|
|
27
|
+
// simply shuffle the order of the cases
|
|
28
|
+
|
|
29
|
+
switchStatement.cases = shuffle(switchStatement.cases);
|
|
30
|
+
}
|
|
31
|
+
let generated = generate(ast).code;
|
|
32
|
+
if (options.minify) {
|
|
33
|
+
generated = await minify(generated);
|
|
34
|
+
}
|
|
35
|
+
return generated;
|
|
36
|
+
}
|
package/dist/utilts.js
ADDED
package/index.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import JsConfuserVM from "./src/index.ts";
|
|
2
2
|
import { readFileSync, writeFileSync } from "fs";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
4
|
+
async function main() {
|
|
5
|
+
// Compile and write the output to a file
|
|
6
|
+
const sourceCode = readFileSync("input.js", "utf-8");
|
|
7
|
+
const { code: output } = await JsConfuserVM.obfuscate(sourceCode, {
|
|
8
|
+
minify: true,
|
|
9
|
+
encodeBytecode: true,
|
|
10
|
+
randomizeOpcodes: true,
|
|
11
|
+
selfModifying: true,
|
|
12
|
+
shuffleOpcodes: true,
|
|
13
|
+
timingChecks: true,
|
|
14
|
+
});
|
|
7
15
|
|
|
8
|
-
writeFileSync("output.js", output, "utf-8");
|
|
9
|
-
console.log(output);
|
|
16
|
+
writeFileSync("output.js", output, "utf-8");
|
|
17
|
+
console.log(output);
|
|
10
18
|
|
|
11
|
-
// Eval the code like our test suite does
|
|
12
|
-
var window = { TEST_OUTPUT: null };
|
|
13
|
-
eval(output);
|
|
14
|
-
console.log(window.TEST_OUTPUT);
|
|
19
|
+
// Eval the code like our test suite does
|
|
20
|
+
var window = { TEST_OUTPUT: null };
|
|
21
|
+
eval(output);
|
|
22
|
+
console.log(window.TEST_OUTPUT);
|
|
15
23
|
|
|
16
|
-
// Minify using Google Closure Compiler (optional)
|
|
17
|
-
import("./minify.js");
|
|
24
|
+
// Minify using Google Closure Compiler (optional)
|
|
25
|
+
// import("./minify.js");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main();
|
package/jest.config.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
const OPTIONS_MATRIX = [
|
|
2
|
+
{ displayName: "default", VM_OPTIONS: {} },
|
|
3
|
+
{ displayName: "randomizeOpcodes", VM_OPTIONS: { randomizeOpcodes: true } },
|
|
4
|
+
{ displayName: "shuffleOpcodes", VM_OPTIONS: { shuffleOpcodes: true } },
|
|
5
|
+
{ displayName: "encodeBytecode", VM_OPTIONS: { encodeBytecode: true } },
|
|
6
|
+
{ displayName: "selfModifying", VM_OPTIONS: { selfModifying: true } },
|
|
7
|
+
{ displayName: "timingChecks", VM_OPTIONS: { timingChecks: true } },
|
|
8
|
+
];
|
|
9
|
+
|
|
1
10
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
11
|
+
projects: OPTIONS_MATRIX.map(({ displayName, VM_OPTIONS }) => ({
|
|
12
|
+
displayName,
|
|
13
|
+
extensionsToTreatAsEsm: [".ts"],
|
|
14
|
+
moduleFileExtensions: ["ts", "js", "json"],
|
|
15
|
+
transform: { "\\.ts$": "./jest-strip-types.js" },
|
|
16
|
+
globals: { VM_OPTIONS },
|
|
17
|
+
})),
|
|
7
18
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-confuser-vm",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
+
"build": "babel src --out-dir dist --extensions '.ts,.js'",
|
|
6
7
|
"index": "NODE_OPTIONS=\"--disable-warning=ExperimentalWarning\" node index.ts",
|
|
7
|
-
"test": "NODE_OPTIONS=\"--experimental-vm-modules --experimental-strip-types --disable-warning=ExperimentalWarning\" jest --coverage --coverageReporters=html",
|
|
8
|
+
"test": "NODE_OPTIONS=\"--experimental-vm-modules --experimental-strip-types --disable-warning=ExperimentalWarning\" jest --coverage --coverageReporters=html --selectProjects default",
|
|
9
|
+
"test-all": "NODE_OPTIONS=\"--experimental-vm-modules --experimental-strip-types --disable-warning=ExperimentalWarning\" jest --coverage --coverageReporters=html",
|
|
8
10
|
"test262": "NODE_OPTIONS=\"--experimental-vm-modules --experimental-strip-types --disable-warning=ExperimentalWarning\" node test262-scripts/run-test262.ts",
|
|
9
|
-
"prepublishOnly": "npm run test"
|
|
11
|
+
"prepublishOnly": "npm run build && npm run test"
|
|
10
12
|
},
|
|
11
13
|
"type": "module",
|
|
12
14
|
"keywords": [
|
|
@@ -28,14 +30,19 @@
|
|
|
28
30
|
"@babel/traverse": "^7.29.0",
|
|
29
31
|
"@babel/types": "^7.29.0",
|
|
30
32
|
"google-closure-compiler": "^20260216.0.0",
|
|
31
|
-
"js-confuser": "^2.0.0",
|
|
32
33
|
"json5": "^2.2.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
36
|
+
"@babel/cli": "^7.28.6",
|
|
37
|
+
"@babel/core": "^7.29.0",
|
|
38
|
+
"@babel/preset-env": "^7.29.0",
|
|
39
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
35
40
|
"@types/node": "^25.3.0",
|
|
41
|
+
"babel-plugin-module-resolver": "^5.0.2",
|
|
42
|
+
"babel-plugin-replace-import-extension": "^1.1.5",
|
|
36
43
|
"jest": "^30.2.0"
|
|
37
44
|
},
|
|
38
45
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
46
|
+
"node": ">=18.0.0"
|
|
40
47
|
}
|
|
41
48
|
}
|