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.
Files changed (39) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/LICENSE +21 -21
  3. package/README.MD +370 -190
  4. package/babel-plugin-inline-runtime.cjs +34 -0
  5. package/babel.config.json +23 -24
  6. package/index.ts +34 -28
  7. package/jest-strip-types.js +10 -10
  8. package/jest.config.js +35 -18
  9. package/package.json +50 -48
  10. package/src/build-runtime.ts +57 -0
  11. package/src/compiler.ts +2069 -1677
  12. package/src/index.ts +14 -13
  13. package/src/minify.ts +21 -21
  14. package/src/options.ts +14 -10
  15. package/src/runtime.ts +771 -645
  16. package/src/transforms/bytecode/macroOpcodes.ts +177 -0
  17. package/src/transforms/bytecode/resolveContants.ts +62 -0
  18. package/src/transforms/bytecode/resolveLabels.ts +107 -0
  19. package/src/transforms/bytecode/selfModifying.ts +121 -0
  20. package/src/transforms/bytecode/specializedOpcodes.ts +118 -0
  21. package/src/transforms/runtime/macroOpcodes.ts +111 -0
  22. package/src/transforms/runtime/minify.ts +1 -0
  23. package/src/transforms/runtime/shuffleOpcodes.ts +24 -0
  24. package/src/transforms/runtime/specializedOpcodes.ts +146 -0
  25. package/src/transforms/utils/op-utils.ts +26 -0
  26. package/src/{random.ts → transforms/utils/random-utils.ts} +31 -31
  27. package/src/types.ts +33 -0
  28. package/src/utilts.ts +3 -3
  29. package/tsconfig.json +12 -12
  30. package/dist/compiler.js +0 -1505
  31. package/dist/index.js +0 -9
  32. package/dist/minify.js +0 -18
  33. package/dist/minify_empty_externs.js +0 -4
  34. package/dist/options.js +0 -1
  35. package/dist/random.js +0 -27
  36. package/dist/runtime.js +0 -620
  37. package/dist/runtimeObf.js +0 -36
  38. package/dist/utilts.js +0 -3
  39. package/src/runtimeObf.ts +0 -48
@@ -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
@@ -1,3 +0,0 @@
1
- export function escapeRegex(s) {
2
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
- }
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
- }