unpeek 1.2.0 → 1.5.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.
- package/README.md +20 -9
- package/README.tr.md +20 -9
- package/assets/banner-dark.svg +22 -0
- package/assets/banner-light.svg +22 -0
- package/assets/banner.svg +39 -0
- package/dist/ast/index.cjs +79 -20
- package/dist/ast/index.cjs.map +1 -1
- package/dist/ast/index.js +79 -20
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +79 -20
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +79 -20
- package/dist/browser.js.map +1 -1
- package/dist/bundler/unplugin.cjs +79 -20
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +79 -20
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +185 -63
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +185 -63
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/protect.cjs +79 -20
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +79 -20
- package/dist/cli/protect.js.map +1 -1
- package/dist/esbuild.cjs +79 -20
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.js +79 -20
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +185 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +185 -63
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +79 -20
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.js +79 -20
- package/dist/rollup.js.map +1 -1
- package/dist/runtime/index.cjs +3 -1
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/vite.cjs +79 -20
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +79 -20
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +79 -20
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.js +79 -20
- package/dist/webpack.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-dark.svg">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-light.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-light.svg" alt="unpeek - call-graph aware client-side javascript protection" width="100%">
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# unpeek
|
|
2
10
|
|
|
3
|
-
**
|
|
11
|
+
**Nothing to peek at. Nothing to slow down.**
|
|
12
|
+
|
|
13
|
+
Zero-config, call-graph-aware client-side JavaScript protection and runtime anti-tamper toolkit with <2% CPU overhead and <15% Gzip budget.
|
|
4
14
|
|
|
5
|
-
[](LICENSE)
|
|
16
|
+
[](packages/unpeek/benchmarks/overhead.bench.ts)
|
|
17
|
+
[](packages/unpeek/benchmarks/overhead.bench.ts)
|
|
18
|
+
[](https://woffluon.github.io/unpeek)
|
|
19
|
+
[](https://woffluon.github.io/unpeek/docs)
|
|
9
20
|
|
|
10
|
-
English | [Türkçe](./README.tr.md) · [
|
|
21
|
+
English | [Türkçe](./README.tr.md) · [Interactive Showcase](https://woffluon.github.io/unpeek) · [Documentation](https://woffluon.github.io/unpeek/docs) · [Agent Architecture Guide](./AGENTS.md) · [AI Skill](./skills/unpeek/SKILL.md)
|
|
11
22
|
|
|
12
23
|
---
|
|
13
24
|
|
|
@@ -50,9 +61,9 @@ flowchart TD
|
|
|
50
61
|
```
|
|
51
62
|
|
|
52
63
|
1. **Call-Graph Hot-Path Exemption (`<2%` CPU Budget)**
|
|
53
|
-
Before modifying an AST node, [`detectHotPaths`](packages/unpeek/src/ast/index.ts) traverses the file call graph. Functions containing loops (`for`, `while`, `do-while`, `for-of`), array higher-order callbacks (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame` tickers,
|
|
54
|
-
2. **O(1)
|
|
55
|
-
|
|
64
|
+
Before modifying an AST node, [`detectHotPaths`](packages/unpeek/src/ast/index.ts) traverses the file call graph bidirectionally. Functions containing loops (`for`, `while`, `do-while`, `for-of`), array higher-order callbacks (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame` tickers, React/UI render components (`useState`, `useEffect`, `createElement`), and all helper callees invoked from hot loops are flagged as hot paths. `unpeek` exempts hot loops and their callees from both opaque control-flow predicates and string vault rewriting, while protecting cold functions (such as license checks, request signers, and auth validators). V8 JIT optimization inside hot loops remains untouched.
|
|
65
|
+
2. **O(1) Const-Array String Vault & Tamper Entanglement (`<15%` Gzip Budget)**
|
|
66
|
+
Cold string literals (`minStringLength >= 4`) are encrypted at build time with a period-2 polymorphic XOR stream cipher keyed by a per-build 32-bit seed that preserves LZ77/Gzip compressibility. At module initialization, the injected `const _uC` vault decodes strings once into a V8 `kConst` array slot so every subsequent read resolves in O(1) constant time via direct array indexing, while entangling the XOR key with the runtime integrity state.
|
|
56
67
|
3. **Self-Defending `Function.prototype.toString()` Integrity and Passive Deterrent**
|
|
57
68
|
When an analyst formats a protected chunk using DevTools Pretty-Print (`{}`) or edits a branch instruction in the Sources panel, the formatted source alters `Function.prototype.toString()`. [`verifyCodeIntegrity`](packages/unpeek/src/runtime/index.ts) validates a seeded 32-bit FNV-1a checksum against the function source representation with zero false positives on untouched minified code, triggering gradual state degradation (`deterrentMode: 'gradual'`) rather than an obvious crash point that attackers can patch out.
|
|
58
69
|
4. **Automatic Source Map Vault (`.unpeek-maps/`)**
|
package/README.tr.md
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-dark.svg">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-light.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/Woffluon/unpeek/main/assets/banner-light.svg" alt="unpeek - call-graph aware client-side javascript protection" width="100%">
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# unpeek
|
|
2
10
|
|
|
3
|
-
**
|
|
11
|
+
**Bakılacak bir şey yok. Yavaşlayacak hiçbir şey yok.**
|
|
12
|
+
|
|
13
|
+
Sıfır yapılandırma gerektiren, çağrı grafiği (call-graph) farkındalıklı, <%2 CPU ek yükü ve <%15 Gzip bütçesine sahip istemci tarafı JavaScript koruma ve çalışma zamanı (runtime) müdahale önleme aracı.
|
|
4
14
|
|
|
5
|
-
[](LICENSE)
|
|
16
|
+
[](packages/unpeek/benchmarks/overhead.bench.ts)
|
|
17
|
+
[](packages/unpeek/benchmarks/overhead.bench.ts)
|
|
18
|
+
[](https://woffluon.github.io/unpeek)
|
|
19
|
+
[](https://woffluon.github.io/unpeek/docs)
|
|
9
20
|
|
|
10
|
-
[English](./README.md) | Türkçe · [
|
|
21
|
+
[English](./README.md) | Türkçe · [İnteraktif Vitrin](https://woffluon.github.io/unpeek) · [Dokümantasyon](https://woffluon.github.io/unpeek/docs) · [Ajan Mimari Kılavuzu](./AGENTS.md) · [Yapay Zeka Becerisi (SKILL.md)](./skills/unpeek/SKILL.md)
|
|
11
22
|
|
|
12
23
|
---
|
|
13
24
|
|
|
@@ -50,9 +61,9 @@ flowchart TD
|
|
|
50
61
|
```
|
|
51
62
|
|
|
52
63
|
1. **Çağrı Grafiği (Call-Graph) Hot-Path Muafiyeti (`<%2` CPU Bütçesi)**
|
|
53
|
-
[`detectHotPaths`](packages/unpeek/src/ast/index.ts), tek bir AST düğümünü değiştirmeden önce dosyanın çağrı grafiğini tarar. Döngü içeren fonksiyonlar (`for`, `while`, `do-while`, `for-of`), dizi yüksek mertebe geri çağrıları (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame`
|
|
54
|
-
2. **O(1)
|
|
55
|
-
|
|
64
|
+
[`detectHotPaths`](packages/unpeek/src/ast/index.ts), tek bir AST düğümünü değiştirmeden önce dosyanın çağrı grafiğini çift yönlü tarar. Döngü içeren fonksiyonlar (`for`, `while`, `do-while`, `for-of`), dizi yüksek mertebe geri çağrıları (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame` zamanlayıcıları, React/UI bileşenleri (`useState`, `useEffect`, `createElement`) ve sıcak döngülerden çağrılan tüm yardımcı fonksiyonlar sıcak yol (hot path) olarak işaretlenir. `unpeek` sıcak döngüleri ve yardımcılarını hem opak kontrol akışı korumalarından hem de metin kasası dönüşümünden muaf tutar; korumayı yalnızca soğuk fonksiyonlara (lisans doğrulama, istek imzalama, yetki kontrolü gibi) uygular. Sıcak döngülerdeki V8 JIT optimizasyonu doğal hızında çalışmayı sürdürür.
|
|
65
|
+
2. **O(1) Sabit-Dizi Metin Kasası ve Kalkan Dolanıklığı (`<%15` Gzip Bütçesi)**
|
|
66
|
+
Soğuk metin sabitleri (`minStringLength >= 4`), derleme zamanında LZ77/Gzip sıkıştırılabilirliğini koruyan periyot-2 polimorfik bir XOR akış şifresiyle kodlanır. Modül başlangıcında enjekte edilen `const _uC` kasası metinleri tek seferde V8 `kConst` sabit dizi hücrelerine çözer ve XOR anahtarını çalışma zamanı bütünlük kalkanına bağlar. Sonraki tüm okumalar doğrudan dizi indeksleme ile O(1) sürede tamamlanır.
|
|
56
67
|
3. **Öz-Savunmalı `Function.prototype.toString()` Bütünlük Kontrolü ve Pasif Caydırıcı**
|
|
57
68
|
Bir analist korumalı bir dosyayı DevTools Pretty-Print (`{}`) ile biçimlendirdiğinde veya Sources panelinde bir koşulu değiştirdiğinde, biçimlendirilen kod `Function.prototype.toString()` çıktısını değiştirir. [`verifyCodeIntegrity`](packages/unpeek/src/runtime/index.ts), dokunulmamış küçültülmüş kodda sıfır yanlış pozitif oranıyla 32-bit FNV-1a özetini doğrular ve saldırganların doğrudan yamayabileceği ani bir çökme yerine kademeli durum bozulması (`deterrentMode: 'gradual'`) başlatır.
|
|
58
69
|
4. **Otomatik Source Map Kasası (`.unpeek-maps/`)**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 200" width="100%" height="auto" fill="none">
|
|
2
|
+
<!-- Minimalist Carbon Canvas -->
|
|
3
|
+
<rect width="960" height="200" rx="6" fill="#111111" />
|
|
4
|
+
<rect x="0.5" y="0.5" width="959" height="199" rx="5.5" stroke="#2A2A28" />
|
|
5
|
+
|
|
6
|
+
<!-- Signal Orange Top Line -->
|
|
7
|
+
<rect x="0" y="0" width="960" height="2" fill="#FF3300" />
|
|
8
|
+
|
|
9
|
+
<!-- Iconic Brand Mark (Sealed block with open hot-path cut) -->
|
|
10
|
+
<g transform="translate(458, 30) scale(1.833)">
|
|
11
|
+
<path d="M2 2h15l5 5v15H2V2Z" fill="#EDEAE1" />
|
|
12
|
+
<rect x="0" y="10.5" width="24" height="3" fill="#FF3300" />
|
|
13
|
+
</g>
|
|
14
|
+
|
|
15
|
+
<!-- Wordmark -->
|
|
16
|
+
<text x="480" y="122" text-anchor="middle" fill="#EDEAE1" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="38" font-weight="700" letter-spacing="-0.035em">unpeek</text>
|
|
17
|
+
|
|
18
|
+
<!-- Tagline -->
|
|
19
|
+
<text x="480" y="154" text-anchor="middle" fill="#8E8A7E" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="14" font-weight="400" letter-spacing="-0.01em">
|
|
20
|
+
Nothing to peek at. <tspan fill="#EDEAE1">Nothing to slow down.</tspan>
|
|
21
|
+
</text>
|
|
22
|
+
</svg>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 200" width="100%" height="auto" fill="none">
|
|
2
|
+
<!-- Minimalist Paper Canvas (Matches Website Light Theme) -->
|
|
3
|
+
<rect width="960" height="200" rx="6" fill="#F2F0E9" />
|
|
4
|
+
<rect x="0.5" y="0.5" width="959" height="199" rx="5.5" stroke="#D5D0C2" />
|
|
5
|
+
|
|
6
|
+
<!-- Signal Orange Top Line -->
|
|
7
|
+
<rect x="0" y="0" width="960" height="2" fill="#FF3300" />
|
|
8
|
+
|
|
9
|
+
<!-- Iconic Brand Mark (Sealed block with open hot-path cut) -->
|
|
10
|
+
<g transform="translate(458, 30) scale(1.833)">
|
|
11
|
+
<path d="M2 2h15l5 5v15H2V2Z" fill="#111111" />
|
|
12
|
+
<rect x="0" y="10.5" width="24" height="3" fill="#FF3300" />
|
|
13
|
+
</g>
|
|
14
|
+
|
|
15
|
+
<!-- Wordmark -->
|
|
16
|
+
<text x="480" y="122" text-anchor="middle" fill="#111111" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="38" font-weight="700" letter-spacing="-0.035em">unpeek</text>
|
|
17
|
+
|
|
18
|
+
<!-- Tagline -->
|
|
19
|
+
<text x="480" y="154" text-anchor="middle" fill="#5C594F" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="14" font-weight="400" letter-spacing="-0.01em">
|
|
20
|
+
Nothing to peek at. <tspan fill="#111111">Nothing to slow down.</tspan>
|
|
21
|
+
</text>
|
|
22
|
+
</svg>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 200" width="100%" height="auto" fill="none">
|
|
2
|
+
<style>
|
|
3
|
+
.bg { fill: #F2F0E9; }
|
|
4
|
+
.border { stroke: #D5D0C2; }
|
|
5
|
+
.mark { fill: #111111; }
|
|
6
|
+
.wordmark { fill: #111111; }
|
|
7
|
+
.tagline-muted { fill: #5C594F; }
|
|
8
|
+
.tagline-strong { fill: #111111; }
|
|
9
|
+
@media (prefers-color-scheme: dark) {
|
|
10
|
+
.bg { fill: #111111; }
|
|
11
|
+
.border { stroke: #2A2A28; }
|
|
12
|
+
.mark { fill: #EDEAE1; }
|
|
13
|
+
.wordmark { fill: #EDEAE1; }
|
|
14
|
+
.tagline-muted { fill: #8E8A7E; }
|
|
15
|
+
.tagline-strong { fill: #EDEAE1; }
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
|
|
19
|
+
<!-- Adaptive Paper (Light) / Carbon (Dark) Canvas -->
|
|
20
|
+
<rect class="bg" width="960" height="200" rx="6" />
|
|
21
|
+
<rect class="border" x="0.5" y="0.5" width="959" height="199" rx="5.5" />
|
|
22
|
+
|
|
23
|
+
<!-- Signal Orange Top Line -->
|
|
24
|
+
<rect x="0" y="0" width="960" height="2" fill="#FF3300" />
|
|
25
|
+
|
|
26
|
+
<!-- Iconic Brand Mark (Sealed block with open hot-path cut) -->
|
|
27
|
+
<g transform="translate(458, 30) scale(1.833)">
|
|
28
|
+
<path class="mark" d="M2 2h15l5 5v15H2V2Z" />
|
|
29
|
+
<rect x="0" y="10.5" width="24" height="3" fill="#FF3300" />
|
|
30
|
+
</g>
|
|
31
|
+
|
|
32
|
+
<!-- Wordmark -->
|
|
33
|
+
<text class="wordmark" x="480" y="122" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="38" font-weight="700" letter-spacing="-0.035em">unpeek</text>
|
|
34
|
+
|
|
35
|
+
<!-- Tagline -->
|
|
36
|
+
<text class="tagline-muted" x="480" y="154" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="14" font-weight="400" letter-spacing="-0.01em">
|
|
37
|
+
Nothing to peek at. <tspan class="tagline-strong">Nothing to slow down.</tspan>
|
|
38
|
+
</text>
|
|
39
|
+
</svg>
|
package/dist/ast/index.cjs
CHANGED
|
@@ -115,6 +115,8 @@ function isPascalCaseComponent(name) {
|
|
|
115
115
|
function analyzeAstHotPaths(ast) {
|
|
116
116
|
const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
117
117
|
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
118
|
+
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
119
|
+
const directHotNodes = /* @__PURE__ */ new Set();
|
|
118
120
|
const allFunctions = [];
|
|
119
121
|
const fnByName = /* @__PURE__ */ new Map();
|
|
120
122
|
const callerToCallees = /* @__PURE__ */ new Map();
|
|
@@ -125,6 +127,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
125
127
|
fnByName.set(name, node);
|
|
126
128
|
if (isPascalCaseComponent(name)) {
|
|
127
129
|
hotFunctionNodes.add(node);
|
|
130
|
+
directHotNodes.add(node);
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
FunctionExpression(node, _state, ancestors) {
|
|
@@ -133,6 +136,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
133
136
|
fnByName.set(name, node);
|
|
134
137
|
if (isPascalCaseComponent(name)) {
|
|
135
138
|
hotFunctionNodes.add(node);
|
|
139
|
+
directHotNodes.add(node);
|
|
136
140
|
}
|
|
137
141
|
},
|
|
138
142
|
ArrowFunctionExpression(node, _state, ancestors) {
|
|
@@ -141,6 +145,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
141
145
|
fnByName.set(name, node);
|
|
142
146
|
if (isPascalCaseComponent(name)) {
|
|
143
147
|
hotFunctionNodes.add(node);
|
|
148
|
+
directHotNodes.add(node);
|
|
144
149
|
}
|
|
145
150
|
},
|
|
146
151
|
CallExpression(node, _state, ancestors) {
|
|
@@ -167,6 +172,8 @@ function analyzeAstHotPaths(ast) {
|
|
|
167
172
|
for (const arg of node.arguments || []) {
|
|
168
173
|
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
169
174
|
hotFunctionNodes.add(arg);
|
|
175
|
+
directHotNodes.add(arg);
|
|
176
|
+
hotExemptNodes.add(arg);
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
179
|
}
|
|
@@ -174,27 +181,51 @@ function analyzeAstHotPaths(ast) {
|
|
|
174
181
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
175
182
|
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
176
183
|
hotFunctionNodes.add(ancestors[i]);
|
|
184
|
+
directHotNodes.add(ancestors[i]);
|
|
177
185
|
break;
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
}
|
|
181
189
|
},
|
|
182
|
-
ForStatement(
|
|
183
|
-
|
|
190
|
+
ForStatement(node, _state, ancestors) {
|
|
191
|
+
hotExemptNodes.add(node);
|
|
192
|
+
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
184
193
|
},
|
|
185
|
-
ForInStatement(
|
|
186
|
-
|
|
194
|
+
ForInStatement(node, _state, ancestors) {
|
|
195
|
+
hotExemptNodes.add(node);
|
|
196
|
+
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
187
197
|
},
|
|
188
|
-
ForOfStatement(
|
|
189
|
-
|
|
198
|
+
ForOfStatement(node, _state, ancestors) {
|
|
199
|
+
hotExemptNodes.add(node);
|
|
200
|
+
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
190
201
|
},
|
|
191
|
-
WhileStatement(
|
|
192
|
-
|
|
202
|
+
WhileStatement(node, _state, ancestors) {
|
|
203
|
+
hotExemptNodes.add(node);
|
|
204
|
+
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
193
205
|
},
|
|
194
|
-
DoWhileStatement(
|
|
195
|
-
|
|
206
|
+
DoWhileStatement(node, _state, ancestors) {
|
|
207
|
+
hotExemptNodes.add(node);
|
|
208
|
+
markEnclosingFunctionHot(ancestors, hotFunctionNodes, directHotNodes);
|
|
196
209
|
}
|
|
197
210
|
});
|
|
211
|
+
const forwardHotSet = new Set(directHotNodes);
|
|
212
|
+
let forwardChanged = true;
|
|
213
|
+
while (forwardChanged) {
|
|
214
|
+
forwardChanged = false;
|
|
215
|
+
for (const callerNode of Array.from(forwardHotSet)) {
|
|
216
|
+
const calleeNames = callerToCallees.get(callerNode);
|
|
217
|
+
if (!calleeNames) continue;
|
|
218
|
+
for (const cName of calleeNames) {
|
|
219
|
+
const targetNode = fnByName.get(cName);
|
|
220
|
+
if (targetNode && !forwardHotSet.has(targetNode)) {
|
|
221
|
+
forwardHotSet.add(targetNode);
|
|
222
|
+
hotFunctionNodes.add(targetNode);
|
|
223
|
+
hotExemptNodes.add(targetNode);
|
|
224
|
+
forwardChanged = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
198
229
|
let changed = true;
|
|
199
230
|
while (changed) {
|
|
200
231
|
changed = false;
|
|
@@ -227,13 +258,17 @@ function analyzeAstHotPaths(ast) {
|
|
|
227
258
|
coldFunctionsProtected
|
|
228
259
|
},
|
|
229
260
|
hotFunctionNodes,
|
|
230
|
-
coldFunctionNodes
|
|
261
|
+
coldFunctionNodes,
|
|
262
|
+
hotExemptNodes
|
|
231
263
|
};
|
|
232
264
|
}
|
|
233
|
-
function markEnclosingFunctionHot(ancestors, hotSet) {
|
|
265
|
+
function markEnclosingFunctionHot(ancestors, hotSet, directHotSet) {
|
|
234
266
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
235
267
|
if (FUNCTION_NODE_TYPES.has(ancestors[i].type)) {
|
|
236
268
|
hotSet.add(ancestors[i]);
|
|
269
|
+
if (directHotSet) {
|
|
270
|
+
directHotSet.add(ancestors[i]);
|
|
271
|
+
}
|
|
237
272
|
break;
|
|
238
273
|
}
|
|
239
274
|
}
|
|
@@ -263,7 +298,7 @@ var HELPER_TEMPLATE = acorn2.parse(
|
|
|
263
298
|
`const _ = [].map(function(a) {
|
|
264
299
|
var s = "";
|
|
265
300
|
for (var j = 0; j < a.length; j++) {
|
|
266
|
-
s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ ((j & 1) * 0)) & 30) | 1));
|
|
301
|
+
s += String.fromCharCode(a.charCodeAt(j) ^ (((0 ^ (a._u | ((j & 1) * 0))) & 30) | 1));
|
|
267
302
|
}
|
|
268
303
|
return s;
|
|
269
304
|
});`,
|
|
@@ -284,8 +319,8 @@ function createVaultHelperAst(cacheVarName, encryptedPayloads, mask, step) {
|
|
|
284
319
|
const innerLeft = binaryXor.right.left.left;
|
|
285
320
|
innerLeft.left.value = mask;
|
|
286
321
|
innerLeft.left.raw = String(mask);
|
|
287
|
-
innerLeft.right.right.value = step;
|
|
288
|
-
innerLeft.right.right.raw = String(step);
|
|
322
|
+
innerLeft.right.right.right.value = step;
|
|
323
|
+
innerLeft.right.right.right.raw = String(step);
|
|
289
324
|
return node;
|
|
290
325
|
}
|
|
291
326
|
function computeFnv1aHash(input, seed = 2166136261) {
|
|
@@ -305,7 +340,7 @@ function encodeStringWithSeed(str, mask, step) {
|
|
|
305
340
|
}
|
|
306
341
|
return out;
|
|
307
342
|
}
|
|
308
|
-
function applyStringVault(ast, seed = 2654435769, minStringLength = 4) {
|
|
343
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
309
344
|
const suffix = ((seed >>> 0) % 255).toString(36);
|
|
310
345
|
const cacheVarName = `_uC${suffix}`;
|
|
311
346
|
const mask = seed >>> 0 & 30 | 3;
|
|
@@ -319,6 +354,13 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4) {
|
|
|
319
354
|
const val = node.value;
|
|
320
355
|
if (val.length < minStringLength) return;
|
|
321
356
|
if (DIRECTIVE_STRINGS.has(val)) return;
|
|
357
|
+
if (hotExemptNodes) {
|
|
358
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
359
|
+
if (hotExemptNodes.has(ancestors[i])) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
322
364
|
const parent = ancestors[ancestors.length - 2];
|
|
323
365
|
if (!parent) return;
|
|
324
366
|
if (parent.type === "ExpressionStatement" && parent.directive) return;
|
|
@@ -651,7 +693,17 @@ function createOpaqueGuardStatement(seed, fnIndex) {
|
|
|
651
693
|
type: "BinaryExpression",
|
|
652
694
|
operator: "^",
|
|
653
695
|
left: { type: "Literal", value: a, raw: String(a) },
|
|
654
|
-
right: {
|
|
696
|
+
right: {
|
|
697
|
+
type: "BinaryExpression",
|
|
698
|
+
operator: "|",
|
|
699
|
+
left: { type: "Literal", value: b, raw: String(b) },
|
|
700
|
+
right: {
|
|
701
|
+
type: "UnaryExpression",
|
|
702
|
+
operator: "!",
|
|
703
|
+
prefix: true,
|
|
704
|
+
argument: { type: "Identifier", name: "String" }
|
|
705
|
+
}
|
|
706
|
+
}
|
|
655
707
|
},
|
|
656
708
|
right: { type: "Literal", value: 7, raw: "7" }
|
|
657
709
|
},
|
|
@@ -708,6 +760,7 @@ function deriveLocalVar(label, seed) {
|
|
|
708
760
|
}
|
|
709
761
|
function createDeterrentSnippet(config) {
|
|
710
762
|
const seed = config.seed >>> 0;
|
|
763
|
+
const expectedToken = (config.expectedIntegrityHash ?? seed) >>> 0;
|
|
711
764
|
const deterrentMode = config.deterrentMode ?? "passive";
|
|
712
765
|
const fnName = deriveIntegrityFnName(seed);
|
|
713
766
|
const strVar = deriveLocalVar("s", seed);
|
|
@@ -716,9 +769,10 @@ function createDeterrentSnippet(config) {
|
|
|
716
769
|
const methodsVar = deriveLocalVar("m", seed);
|
|
717
770
|
const idxVar = deriveLocalVar("i", seed);
|
|
718
771
|
const errVar = deriveLocalVar("e", seed);
|
|
772
|
+
const tokenBit = expectedToken & 1;
|
|
719
773
|
const gradualConsoleSilence = deterrentMode === "gradual" ? `if(typeof console!=='undefined'){var ${noopVar}=function(){},${methodsVar}=['log','debug','info','table','dir'];for(var ${idxVar}=0;${idxVar}<${methodsVar}.length;${idxVar}++){try{console[${methodsVar}[${idxVar}]]=${noopVar};}catch(${errVar}){}}}` : "";
|
|
720
774
|
const tamperDispatch = `if(typeof window.dispatchEvent==='function'&&typeof CustomEvent==='function'){try{window.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(${errVar}){}}`;
|
|
721
|
-
return `(function ${fnName}(){if(typeof window!=='undefined'){try{var ${strVar}=Function.prototype.toString,${tamperVar}=${strVar}.call(${strVar}).indexOf('[native code]')
|
|
775
|
+
return `(function ${fnName}(){if(typeof window!=='undefined'){try{var ${strVar}=Function.prototype.toString,${tamperVar}=${strVar}.call(${strVar}).indexOf('[native code]')<${tokenBit - 1}||${strVar}.call(${fnName}).indexOf('\\n')!==-1||${strVar}.call(${fnName}).indexOf('\\r')!==-1;if(${tamperVar}){window.__unpeek_tampered=!0;String.prototype._u=14;${tamperDispatch}${gradualConsoleSilence}}}catch(${errVar}){}}})();`;
|
|
722
776
|
}
|
|
723
777
|
|
|
724
778
|
// src/runtime/index.ts
|
|
@@ -764,13 +818,18 @@ function transformJavaScript(code, options = {}) {
|
|
|
764
818
|
integrityToken: computeFnv1aHash(code, seed)
|
|
765
819
|
};
|
|
766
820
|
}
|
|
767
|
-
const {
|
|
821
|
+
const {
|
|
822
|
+
report: hotPathReport,
|
|
823
|
+
coldFunctionNodes,
|
|
824
|
+
hotExemptNodes
|
|
825
|
+
} = analyzeAstHotPaths(ast);
|
|
768
826
|
applyColdFlowGuard(ast, coldFunctionNodes, seed);
|
|
769
827
|
const mangledSymbolsCount = applyPolymorphicMangler(ast, seed);
|
|
770
828
|
const { encryptedStringsCount, integrityToken } = applyStringVault(
|
|
771
829
|
ast,
|
|
772
830
|
seed,
|
|
773
|
-
minStringLength
|
|
831
|
+
minStringLength,
|
|
832
|
+
hotExemptNodes
|
|
774
833
|
);
|
|
775
834
|
const outputCode = (0, import_astring.generate)(ast, { indent: "", lineEnd: "" });
|
|
776
835
|
let finalCode = outputCode;
|