@tsvm/transforms 0.1.0

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 (3) hide show
  1. package/dist/index.d.ts +130 -0
  2. package/dist/index.js +2854 -0
  3. package/package.json +35 -0
@@ -0,0 +1,130 @@
1
+ import { ObfuscationProfile, TransformPass, TransformContext, TransformResult } from '@tsvm/shared';
2
+
3
+ declare class TransformRegistry {
4
+ private passes;
5
+ constructor(profile: ObfuscationProfile);
6
+ addPass(pass: TransformPass): void;
7
+ removePass(name: string): void;
8
+ getPass(name: string): TransformPass | undefined;
9
+ getOrderedPasses(): TransformPass[];
10
+ }
11
+ declare function createTransformRegistry(profile: ObfuscationProfile): TransformRegistry;
12
+
13
+ /**
14
+ * 1) Invariant đầu vào: IR module có chứa các functions với type signatures rõ ràng (từ TypeScript).
15
+ * 2) Invariant đầu ra: IR module được chèn thêm các khối mã (fake type guards / phantom branches)
16
+ * để đánh lừa static analysis (nhưng không đổi runtime behavior).
17
+ * 3) Node kinds đụng tới: IRFunction, BasicBlock, Instruction.
18
+ * 4) Edge cases: Không áp dụng vào các hàm quá ngắn hoặc generator/async để tránh overhead/vỡ luồng.
19
+ */
20
+ declare class PreserveTypeIllusionsPass implements TransformPass {
21
+ readonly name = "PreserveTypeIllusionsPass";
22
+ readonly priority = 10;
23
+ execute(ctx: TransformContext): TransformResult;
24
+ }
25
+
26
+ /**
27
+ * 1) Invariant đầu vào: IRModule chứa hàm có gọi tới generic functions hoặc có type parameters (qua semantic graph).
28
+ * 2) Invariant đầu ra: Tạo các branch giả mạo (phi/dispatch) kiểm tra type object ở runtime
29
+ * để mô phỏng generic instantiation tĩnh của TypeScript.
30
+ * 3) Node kinds đụng tới: Call, FunctionRef, BasicBlock.
31
+ * 4) Edge cases: Bỏ qua các hàm không thể trace type rõ ràng.
32
+ * 5) Pseudo-code:
33
+ * For each call instruction:
34
+ * if it calls a generic function (using typeFacts):
35
+ * replace call with a dynamic type-check dispatch wrapper
36
+ */
37
+ declare class GenericConfusionPass implements TransformPass {
38
+ readonly name = "GenericConfusionPass";
39
+ readonly priority = 20;
40
+ execute(ctx: TransformContext): TransformResult;
41
+ }
42
+
43
+ declare class DecoratorAwareLoweringPass implements TransformPass {
44
+ readonly name = "DecoratorAwareLoweringPass";
45
+ readonly priority = 30;
46
+ execute(ctx: TransformContext): TransformResult;
47
+ }
48
+
49
+ /**
50
+ * 1) Invariant đầu vào: Hàm truy cập các symbol thông qua namespace hoặc exported object (PropGet/PropSet).
51
+ * 2) Invariant đầu ra: Các lookup namespace tĩnh bị biến thành lookup động trên một object graph ảo
52
+ * được quản lý ở runtime.
53
+ * 3) Node kinds đụng tới: PropGet, PropSet, ComputedGet, ComputedSet.
54
+ * 4) Edge cases: Bỏ qua các object native như window, document hoặc module của bên thứ ba không thể virtualize.
55
+ * 5) Pseudo-code:
56
+ * For each instruction:
57
+ * if it is PropGet(obj, "propName"):
58
+ * replace with ComputedGet(virtual_namespace_map(obj), hash("propName"))
59
+ */
60
+ declare class NamespaceVirtualizationPass implements TransformPass {
61
+ readonly name = "NamespaceVirtualizationPass";
62
+ readonly priority = 40;
63
+ execute(ctx: TransformContext): TransformResult;
64
+ }
65
+
66
+ /**
67
+ * Type-level fake path pass: injects dead branches with opaque predicates
68
+ * that are always false but hard to statically analyze.
69
+ */
70
+ declare class TypeLevelFakePathPass implements TransformPass {
71
+ readonly name = "TypeLevelFakePathPass";
72
+ readonly priority = 30;
73
+ execute(ctx: TransformContext): TransformResult;
74
+ }
75
+
76
+ /**
77
+ * 1) Invariant đầu vào: Các hàm và biến nội bộ có tên symbol giữ nguyên từ mã gốc (trừ khi đã rename).
78
+ * 2) Invariant đầu ra: Toàn bộ tên biến, hàm nội bộ (không export, không phải API public)
79
+ * được mã hóa/ẩn đi thông qua alias map.
80
+ * 3) Node kinds đụng tới: IRFunction, IRLocal, IRGlobal.
81
+ * 4) Edge cases: Bỏ qua các exported symbols nếu config yêu cầu (ví dụ làm thư viện).
82
+ * 5) Pseudo-code:
83
+ * For each function, local, global:
84
+ * if not exported:
85
+ * rename to a random hashed string
86
+ * update alias map
87
+ */
88
+ declare class SymbolIndirectionPass implements TransformPass {
89
+ readonly name = "SymbolIndirectionPass";
90
+ readonly priority = 50;
91
+ execute(ctx: TransformContext): TransformResult;
92
+ }
93
+
94
+ declare class StringPoolEncodingPass implements TransformPass {
95
+ readonly name = "StringPoolEncodingPass";
96
+ readonly priority = 70;
97
+ execute(ctx: TransformContext): TransformResult;
98
+ }
99
+
100
+ declare class FunctionVirtualizationPass implements TransformPass {
101
+ readonly name = "FunctionVirtualizationPass";
102
+ readonly priority = 80;
103
+ execute(ctx: TransformContext): TransformResult;
104
+ }
105
+
106
+ declare class DeadCodeInjectionPass implements TransformPass {
107
+ readonly name = "DeadCodeInjectionPass";
108
+ readonly priority = 25;
109
+ execute(ctx: TransformContext): TransformResult;
110
+ }
111
+
112
+ declare class ControlFlowFlatteningPass implements TransformPass {
113
+ readonly name = "ControlFlowFlatteningPass";
114
+ readonly priority = 26;
115
+ execute(ctx: TransformContext): TransformResult;
116
+ }
117
+
118
+ declare class StripDebugPass implements TransformPass {
119
+ readonly name = "StripDebugPass";
120
+ readonly priority = 5;
121
+ execute(ctx: TransformContext): TransformResult;
122
+ }
123
+
124
+ declare class InstructionSubstitutionPass implements TransformPass {
125
+ readonly name = "InstructionSubstitutionPass";
126
+ readonly priority = 20;
127
+ execute(ctx: TransformContext): TransformResult;
128
+ }
129
+
130
+ export { ControlFlowFlatteningPass, DeadCodeInjectionPass, DecoratorAwareLoweringPass, FunctionVirtualizationPass, GenericConfusionPass, InstructionSubstitutionPass, NamespaceVirtualizationPass, PreserveTypeIllusionsPass, StringPoolEncodingPass, StripDebugPass, SymbolIndirectionPass, TransformRegistry, TypeLevelFakePathPass, createTransformRegistry };