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.
- package/CHANGELOG.md +125 -0
- package/LICENSE +21 -21
- package/README.MD +370 -190
- package/babel-plugin-inline-runtime.cjs +34 -0
- package/babel.config.json +23 -24
- package/index.ts +34 -28
- package/jest-strip-types.js +10 -10
- package/jest.config.js +35 -18
- package/package.json +50 -48
- package/src/build-runtime.ts +57 -0
- package/src/compiler.ts +2069 -1677
- package/src/index.ts +14 -13
- package/src/minify.ts +21 -21
- package/src/options.ts +14 -10
- package/src/runtime.ts +771 -645
- 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/bytecode/selfModifying.ts +121 -0
- 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 -0
- package/src/utilts.ts +3 -3
- package/tsconfig.json +12 -12
- package/dist/compiler.js +0 -1505
- package/dist/index.js +0 -9
- package/dist/minify.js +0 -18
- package/dist/minify_empty_externs.js +0 -4
- package/dist/options.js +0 -1
- package/dist/random.js +0 -27
- package/dist/runtime.js +0 -620
- package/dist/runtimeObf.js +0 -36
- package/dist/utilts.js +0 -3
- package/src/runtimeObf.ts +0 -48
package/dist/runtimeObf.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
DELETED
package/src/runtimeObf.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
import { generate } from "@babel/generator";
|
|
3
|
-
import { parse } from "@babel/parser";
|
|
4
|
-
import traverseImport from "@babel/traverse";
|
|
5
|
-
import { ok } from "assert";
|
|
6
|
-
import { choice, shuffle } from "./random.ts";
|
|
7
|
-
import type { Options } from "./options.ts";
|
|
8
|
-
import { escapeRegex } from "./utilts.ts";
|
|
9
|
-
import { minify } from "./minify.ts";
|
|
10
|
-
const traverse = traverseImport.default;
|
|
11
|
-
|
|
12
|
-
export async function obfuscateRuntime(runtime: string, options: Options) {
|
|
13
|
-
const ast = parse(runtime, {
|
|
14
|
-
sourceType: "unambiguous",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// shuffle order of opcode handlers
|
|
18
|
-
|
|
19
|
-
if (options.shuffleOpcodes) {
|
|
20
|
-
let switchStatement: t.SwitchStatement | null = null;
|
|
21
|
-
traverse(ast, {
|
|
22
|
-
SwitchStatement(path) {
|
|
23
|
-
if (
|
|
24
|
-
path.node.leadingComments?.some((comment) =>
|
|
25
|
-
comment.value.includes("@SWITCH"),
|
|
26
|
-
)
|
|
27
|
-
) {
|
|
28
|
-
switchStatement = path.node;
|
|
29
|
-
path.stop();
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
ok(switchStatement, "Could not find opcode handlers switch statement");
|
|
35
|
-
|
|
36
|
-
// simply shuffle the order of the cases
|
|
37
|
-
|
|
38
|
-
switchStatement.cases = shuffle(switchStatement.cases);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let generated = generate(ast).code;
|
|
42
|
-
|
|
43
|
-
if (options.minify) {
|
|
44
|
-
generated = await minify(generated);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return generated;
|
|
48
|
-
}
|