js-confuser-vm 0.0.3 → 0.0.5

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 (51) hide show
  1. package/CHANGELOG.md +125 -28
  2. package/LICENSE +21 -21
  3. package/README.MD +370 -196
  4. package/babel-plugin-inline-runtime.cjs +34 -34
  5. package/babel.config.json +23 -23
  6. package/dist/build-runtime.js +53 -0
  7. package/dist/compiler.js +107 -117
  8. package/dist/runtime.js +78 -84
  9. package/dist/transforms/bytecode/macroOpcodes.js +152 -0
  10. package/dist/transforms/{resolveContants.js → bytecode/resolveContants.js} +16 -6
  11. package/dist/transforms/bytecode/resolveLabels.js +80 -0
  12. package/dist/transforms/{selfModifying.js → bytecode/selfModifying.js} +33 -33
  13. package/dist/transforms/bytecode/specializedOpcodes.js +103 -0
  14. package/dist/transforms/runtime/macroOpcodes.js +88 -0
  15. package/dist/transforms/runtime/minify.js +1 -0
  16. package/dist/transforms/runtime/shuffleOpcodes.js +20 -0
  17. package/dist/transforms/runtime/specializedOpcodes.js +102 -0
  18. package/dist/transforms/utils/op-utils.js +25 -0
  19. package/dist/{random.js → transforms/utils/random-utils.js} +3 -3
  20. package/dist/types.js +4 -2
  21. package/index.ts +34 -22
  22. package/jest-strip-types.js +10 -10
  23. package/jest.config.js +35 -28
  24. package/package.json +49 -48
  25. package/src/build-runtime.ts +57 -0
  26. package/src/compiler.ts +2069 -2066
  27. package/src/index.ts +14 -14
  28. package/src/minify.ts +21 -21
  29. package/src/options.ts +14 -12
  30. package/src/runtime.ts +771 -779
  31. package/src/transforms/bytecode/macroOpcodes.ts +177 -0
  32. package/src/transforms/bytecode/resolveContants.ts +62 -0
  33. package/src/transforms/bytecode/resolveLabels.ts +107 -0
  34. package/src/transforms/{selfModifying.ts → bytecode/selfModifying.ts} +37 -40
  35. package/src/transforms/bytecode/specializedOpcodes.ts +118 -0
  36. package/src/transforms/runtime/macroOpcodes.ts +111 -0
  37. package/src/transforms/runtime/minify.ts +1 -0
  38. package/src/transforms/runtime/shuffleOpcodes.ts +24 -0
  39. package/src/transforms/runtime/specializedOpcodes.ts +146 -0
  40. package/src/transforms/utils/op-utils.ts +26 -0
  41. package/src/{random.ts → transforms/utils/random-utils.ts} +31 -31
  42. package/src/types.ts +33 -24
  43. package/src/utilts.ts +3 -3
  44. package/tsconfig.json +12 -12
  45. package/dist/runtimeObf.js +0 -56
  46. package/dist/transforms/controlFlowFlattening.js +0 -22
  47. package/dist/transforms/resolveLabels.js +0 -59
  48. package/src/runtimeObf.ts +0 -62
  49. package/src/transforms/controlFlowFlattening.ts +0 -30
  50. package/src/transforms/resolveContants.ts +0 -42
  51. package/src/transforms/resolveLabels.ts +0 -83
@@ -1,83 +0,0 @@
1
- // --- Label IR ---
2
- // During compilation, jump targets are symbolic labels instead of hard-coded
3
- // PC numbers. Two IR "pseudo operands" carry the label information:
4
- //
5
- // defineLabel operand : [null, {type:"defineLabel", label:"FN_ENTRY_1"}]
6
- // Marks a position in the bytecode array.
7
- // resolveLabels() strips these out entirely.
8
- //
9
- // label ref operand : [OP.JUMP, {type:"label", label:"FN_ENTRY_1"}]
10
- // Used as the operand of any jump instruction. resolveLabels() replaces
11
- // it with the integer PC that the corresponding defineLabel resolves to.
12
-
13
- import type { Instruction } from "../types.ts";
14
- import { Compiler } from "../compiler.ts";
15
-
16
- // Resolve symbolic labels to absolute PC indices within a bytecode array.
17
- // defineLabel pseudo-instructions are stripped; label-ref operands become ints.
18
- // Mutates `bc` in place so callers holding a reference see the resolved result.
19
- export function resolveLabels(
20
- bc: Instruction[],
21
- compiler: Compiler,
22
- ): {
23
- bytecode: Instruction[];
24
- } {
25
- // Pass 1 – walk the array and record each label's real PC, counting only
26
- // real instructions (defineLabel pseudo-ops don't occupy a PC slot).
27
- const labelToPc = new Map<string, number>();
28
- let realPc = 0;
29
- for (const instr of bc) {
30
- const op = instr[0];
31
- const operand = instr[1];
32
- if (
33
- op === null &&
34
- operand !== null &&
35
- typeof operand === "object" &&
36
- operand.type === "defineLabel"
37
- ) {
38
- labelToPc.set(operand.label, realPc);
39
- } else {
40
- realPc++;
41
- }
42
- }
43
-
44
- // Pass 2 – build the resolved instruction list.
45
- const resolved: any[] = [];
46
- for (const instr of bc) {
47
- const op = instr[0];
48
- const operand = instr[1];
49
-
50
- // Strip defineLabel pseudo-ops.
51
- if (
52
- op === null &&
53
- typeof operand === "object" &&
54
- operand?.type === "defineLabel"
55
- ) {
56
- continue;
57
- }
58
-
59
- // Replace label-ref operands with integer PCs.
60
- if (
61
- operand !== undefined &&
62
- operand !== null &&
63
- typeof operand === "object" &&
64
- operand.type === "label"
65
- ) {
66
- const pc = labelToPc.get(operand.label);
67
- if (pc === undefined)
68
- throw new Error(`Undefined label: ${operand.label}`);
69
- resolved.push([op, pc + (operand.offset ?? 0)]);
70
- } else {
71
- resolved.push(instr);
72
- }
73
- }
74
-
75
- // Patch each function descriptor's startPc now that labels are resolved.
76
- for (const desc of compiler.fnDescriptors) {
77
- desc.startPc = labelToPc.get(desc.startLabel);
78
- }
79
-
80
- return {
81
- bytecode: resolved,
82
- };
83
- }