bla-agents 1.1.0 → 1.5.3

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 (276) hide show
  1. package/.agents/skills/blind-llm-agents/SKILL.md +20 -14
  2. package/DISCLAIMER.md +15 -7
  3. package/README.md +153 -198
  4. package/dist/bundler/index.d.ts +19 -2
  5. package/dist/bundler/index.d.ts.map +1 -1
  6. package/dist/bundler/index.js +47 -4
  7. package/dist/bundler/index.js.map +1 -1
  8. package/dist/cli.d.ts +5 -0
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +123 -18
  11. package/dist/cli.js.map +1 -1
  12. package/dist/core/config.d.ts +54 -0
  13. package/dist/core/config.d.ts.map +1 -0
  14. package/dist/core/config.js +160 -0
  15. package/dist/core/config.js.map +1 -0
  16. package/dist/core/coverage-contract.d.ts +97 -0
  17. package/dist/core/coverage-contract.d.ts.map +1 -0
  18. package/dist/core/coverage-contract.js +164 -0
  19. package/dist/core/coverage-contract.js.map +1 -0
  20. package/dist/core/debug-posture.d.ts +40 -0
  21. package/dist/core/debug-posture.d.ts.map +1 -0
  22. package/dist/core/debug-posture.js +197 -0
  23. package/dist/core/debug-posture.js.map +1 -0
  24. package/dist/core/detector.d.ts.map +1 -1
  25. package/dist/core/detector.js +58 -6
  26. package/dist/core/detector.js.map +1 -1
  27. package/dist/core/identifiers.d.ts +32 -0
  28. package/dist/core/identifiers.d.ts.map +1 -0
  29. package/dist/core/identifiers.js +263 -0
  30. package/dist/core/identifiers.js.map +1 -0
  31. package/dist/core/llm-directives.d.ts +12 -0
  32. package/dist/core/llm-directives.d.ts.map +1 -0
  33. package/dist/core/llm-directives.js +23 -0
  34. package/dist/core/llm-directives.js.map +1 -0
  35. package/dist/core/prng.d.ts +10 -1
  36. package/dist/core/prng.d.ts.map +1 -1
  37. package/dist/core/prng.js +27 -2
  38. package/dist/core/prng.js.map +1 -1
  39. package/dist/core/release-plan.d.ts +68 -0
  40. package/dist/core/release-plan.d.ts.map +1 -0
  41. package/dist/core/release-plan.js +235 -0
  42. package/dist/core/release-plan.js.map +1 -0
  43. package/dist/core/sarif.d.ts +53 -0
  44. package/dist/core/sarif.d.ts.map +1 -0
  45. package/dist/core/sarif.js +91 -0
  46. package/dist/core/sarif.js.map +1 -0
  47. package/dist/core/sqlite-runtime.d.ts +13 -0
  48. package/dist/core/sqlite-runtime.d.ts.map +1 -1
  49. package/dist/core/sqlite-runtime.js +38 -8
  50. package/dist/core/sqlite-runtime.js.map +1 -1
  51. package/dist/core/types.d.ts +7 -2
  52. package/dist/core/types.d.ts.map +1 -1
  53. package/dist/engine/auditor.d.ts.map +1 -1
  54. package/dist/engine/auditor.js +251 -8
  55. package/dist/engine/auditor.js.map +1 -1
  56. package/dist/engine/benchmark.d.ts +1 -1
  57. package/dist/engine/benchmark.d.ts.map +1 -1
  58. package/dist/engine/benchmark.js +121 -41
  59. package/dist/engine/benchmark.js.map +1 -1
  60. package/dist/engine/defender.d.ts +1 -0
  61. package/dist/engine/defender.d.ts.map +1 -1
  62. package/dist/engine/defender.js +7 -1
  63. package/dist/engine/defender.js.map +1 -1
  64. package/dist/engine/harden.d.ts +61 -0
  65. package/dist/engine/harden.d.ts.map +1 -0
  66. package/dist/engine/harden.js +292 -0
  67. package/dist/engine/harden.js.map +1 -0
  68. package/dist/engine/protector.d.ts.map +1 -1
  69. package/dist/engine/protector.js +162 -21
  70. package/dist/engine/protector.js.map +1 -1
  71. package/dist/identity.d.ts +112 -2
  72. package/dist/identity.d.ts.map +1 -1
  73. package/dist/identity.js +112 -2
  74. package/dist/identity.js.map +1 -1
  75. package/dist/index.d.ts +26 -9
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +26 -9
  78. package/dist/index.js.map +1 -1
  79. package/dist/mcp/server.d.ts +59 -152
  80. package/dist/mcp/server.d.ts.map +1 -1
  81. package/dist/mcp/server.js +466 -50
  82. package/dist/mcp/server.js.map +1 -1
  83. package/dist/setup/clients.d.ts +49 -1
  84. package/dist/setup/clients.d.ts.map +1 -1
  85. package/dist/setup/clients.js +1193 -20
  86. package/dist/setup/clients.js.map +1 -1
  87. package/dist/setup/doctor.d.ts +58 -14
  88. package/dist/setup/doctor.d.ts.map +1 -1
  89. package/dist/setup/doctor.js +316 -22
  90. package/dist/setup/doctor.js.map +1 -1
  91. package/dist/setup/setup.d.ts +77 -7
  92. package/dist/setup/setup.d.ts.map +1 -1
  93. package/dist/setup/setup.js +591 -62
  94. package/dist/setup/setup.js.map +1 -1
  95. package/dist/shields/chaff/chaff-generator.d.ts.map +1 -1
  96. package/dist/shields/chaff/chaff-generator.js +12 -3
  97. package/dist/shields/chaff/chaff-generator.js.map +1 -1
  98. package/dist/shields/deception/architecture-mirage.js +1 -1
  99. package/dist/shields/deception/architecture-mirage.js.map +1 -1
  100. package/dist/shields/deception/canary-honeypot.d.ts +33 -0
  101. package/dist/shields/deception/canary-honeypot.d.ts.map +1 -0
  102. package/dist/shields/deception/canary-honeypot.js +95 -0
  103. package/dist/shields/deception/canary-honeypot.js.map +1 -0
  104. package/dist/shields/deception/cognitive-armor-trigger.d.ts +43 -0
  105. package/dist/shields/deception/cognitive-armor-trigger.d.ts.map +1 -0
  106. package/dist/shields/deception/cognitive-armor-trigger.js +204 -0
  107. package/dist/shields/deception/cognitive-armor-trigger.js.map +1 -0
  108. package/dist/shields/deception/crash-trace-decoy.js +1 -1
  109. package/dist/shields/deception/crash-trace-decoy.js.map +1 -1
  110. package/dist/shields/deception/decompiler-illusion.js +1 -1
  111. package/dist/shields/deception/decompiler-illusion.js.map +1 -1
  112. package/dist/shields/deception/diff-noise-injector.js +1 -1
  113. package/dist/shields/deception/diff-noise-injector.js.map +1 -1
  114. package/dist/shields/deception/evidence-contract-poison.js +1 -1
  115. package/dist/shields/deception/evidence-contract-poison.js.map +1 -1
  116. package/dist/shields/deception/format-payloads.d.ts +21 -0
  117. package/dist/shields/deception/format-payloads.d.ts.map +1 -0
  118. package/dist/shields/deception/format-payloads.js +24 -0
  119. package/dist/shields/deception/format-payloads.js.map +1 -0
  120. package/dist/shields/deception/index.d.ts +10 -2
  121. package/dist/shields/deception/index.d.ts.map +1 -1
  122. package/dist/shields/deception/index.js +20 -3
  123. package/dist/shields/deception/index.js.map +1 -1
  124. package/dist/shields/deception/prompt-completion-poison.d.ts +3 -2
  125. package/dist/shields/deception/prompt-completion-poison.d.ts.map +1 -1
  126. package/dist/shields/deception/prompt-completion-poison.js +6 -3
  127. package/dist/shields/deception/prompt-completion-poison.js.map +1 -1
  128. package/dist/shields/deception/shadow-business-logic.js +4 -4
  129. package/dist/shields/deception/shadow-business-logic.js.map +1 -1
  130. package/dist/shields/deception/system-diagnostic-decoy.d.ts +36 -0
  131. package/dist/shields/deception/system-diagnostic-decoy.d.ts.map +1 -0
  132. package/dist/shields/deception/system-diagnostic-decoy.js +101 -0
  133. package/dist/shields/deception/system-diagnostic-decoy.js.map +1 -0
  134. package/dist/shields/exhaustion/asar-header-amplifier.d.ts +12 -3
  135. package/dist/shields/exhaustion/asar-header-amplifier.d.ts.map +1 -1
  136. package/dist/shields/exhaustion/asar-header-amplifier.js +30 -8
  137. package/dist/shields/exhaustion/asar-header-amplifier.js.map +1 -1
  138. package/dist/shields/exhaustion/bpe-token-amplifier.js +2 -2
  139. package/dist/shields/exhaustion/bpe-token-amplifier.js.map +1 -1
  140. package/dist/shields/exhaustion/callgraph-labyrinth.js +2 -2
  141. package/dist/shields/exhaustion/callgraph-labyrinth.js.map +1 -1
  142. package/dist/shields/exhaustion/cdp-shape-budget-breaker.js +1 -1
  143. package/dist/shields/exhaustion/cdp-shape-budget-breaker.js.map +1 -1
  144. package/dist/shields/exhaustion/frida-capture-saturation.d.ts +10 -5
  145. package/dist/shields/exhaustion/frida-capture-saturation.d.ts.map +1 -1
  146. package/dist/shields/exhaustion/frida-capture-saturation.js +21 -8
  147. package/dist/shields/exhaustion/frida-capture-saturation.js.map +1 -1
  148. package/dist/shields/exhaustion/index.d.ts +2 -2
  149. package/dist/shields/exhaustion/index.d.ts.map +1 -1
  150. package/dist/shields/exhaustion/index.js +2 -2
  151. package/dist/shields/exhaustion/index.js.map +1 -1
  152. package/dist/shields/exhaustion/obligation-flooder.d.ts +17 -5
  153. package/dist/shields/exhaustion/obligation-flooder.d.ts.map +1 -1
  154. package/dist/shields/exhaustion/obligation-flooder.js +20 -8
  155. package/dist/shields/exhaustion/obligation-flooder.js.map +1 -1
  156. package/dist/shields/exhaustion/rea-budget-matrix.d.ts +8 -2
  157. package/dist/shields/exhaustion/rea-budget-matrix.d.ts.map +1 -1
  158. package/dist/shields/exhaustion/rea-budget-matrix.js +139 -16
  159. package/dist/shields/exhaustion/rea-budget-matrix.js.map +1 -1
  160. package/dist/shields/exhaustion/regex-worker-tarpit.d.ts.map +1 -1
  161. package/dist/shields/exhaustion/regex-worker-tarpit.js +2 -1
  162. package/dist/shields/exhaustion/regex-worker-tarpit.js.map +1 -1
  163. package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts +7 -4
  164. package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts.map +1 -1
  165. package/dist/shields/exhaustion/wasm-interface-exhaustion.js +16 -7
  166. package/dist/shields/exhaustion/wasm-interface-exhaustion.js.map +1 -1
  167. package/dist/shields/formats/android-dex-xref.d.ts +19 -0
  168. package/dist/shields/formats/android-dex-xref.d.ts.map +1 -0
  169. package/dist/shields/formats/android-dex-xref.js +427 -0
  170. package/dist/shields/formats/android-dex-xref.js.map +1 -0
  171. package/dist/shields/formats/android-manifest.d.ts +44 -0
  172. package/dist/shields/formats/android-manifest.d.ts.map +1 -0
  173. package/dist/shields/formats/android-manifest.js +240 -0
  174. package/dist/shields/formats/android-manifest.js.map +1 -0
  175. package/dist/shields/formats/android-r8.d.ts +44 -0
  176. package/dist/shields/formats/android-r8.d.ts.map +1 -0
  177. package/dist/shields/formats/android-r8.js +246 -0
  178. package/dist/shields/formats/android-r8.js.map +1 -0
  179. package/dist/shields/formats/apple-plist.d.ts +15 -0
  180. package/dist/shields/formats/apple-plist.d.ts.map +1 -1
  181. package/dist/shields/formats/apple-plist.js +59 -1
  182. package/dist/shields/formats/apple-plist.js.map +1 -1
  183. package/dist/shields/formats/archive.d.ts +27 -6
  184. package/dist/shields/formats/archive.d.ts.map +1 -1
  185. package/dist/shields/formats/archive.js +247 -45
  186. package/dist/shields/formats/archive.js.map +1 -1
  187. package/dist/shields/formats/asar.d.ts +50 -10
  188. package/dist/shields/formats/asar.d.ts.map +1 -1
  189. package/dist/shields/formats/asar.js +265 -39
  190. package/dist/shields/formats/asar.js.map +1 -1
  191. package/dist/shields/formats/bun-standalone.d.ts +78 -0
  192. package/dist/shields/formats/bun-standalone.d.ts.map +1 -0
  193. package/dist/shields/formats/bun-standalone.js +272 -0
  194. package/dist/shields/formats/bun-standalone.js.map +1 -0
  195. package/dist/shields/formats/dotnet-managed.d.ts +9 -0
  196. package/dist/shields/formats/dotnet-managed.d.ts.map +1 -1
  197. package/dist/shields/formats/dotnet-managed.js +26 -1
  198. package/dist/shields/formats/dotnet-managed.js.map +1 -1
  199. package/dist/shields/formats/electron-fuses.d.ts +63 -8
  200. package/dist/shields/formats/electron-fuses.d.ts.map +1 -1
  201. package/dist/shields/formats/electron-fuses.js +297 -65
  202. package/dist/shields/formats/electron-fuses.js.map +1 -1
  203. package/dist/shields/formats/erlang-beam.d.ts +34 -0
  204. package/dist/shields/formats/erlang-beam.d.ts.map +1 -0
  205. package/dist/shields/formats/erlang-beam.js +319 -0
  206. package/dist/shields/formats/erlang-beam.js.map +1 -0
  207. package/dist/shields/formats/evm-bytecode.d.ts +28 -0
  208. package/dist/shields/formats/evm-bytecode.d.ts.map +1 -0
  209. package/dist/shields/formats/evm-bytecode.js +124 -0
  210. package/dist/shields/formats/evm-bytecode.js.map +1 -0
  211. package/dist/shields/formats/go-flutter-exhaustion.d.ts +55 -0
  212. package/dist/shields/formats/go-flutter-exhaustion.d.ts.map +1 -0
  213. package/dist/shields/formats/go-flutter-exhaustion.js +346 -0
  214. package/dist/shields/formats/go-flutter-exhaustion.js.map +1 -0
  215. package/dist/shields/formats/gpu-ptx.d.ts +40 -0
  216. package/dist/shields/formats/gpu-ptx.d.ts.map +1 -0
  217. package/dist/shields/formats/gpu-ptx.js +62 -0
  218. package/dist/shields/formats/gpu-ptx.js.map +1 -0
  219. package/dist/shields/formats/headers.d.ts.map +1 -1
  220. package/dist/shields/formats/headers.js +54 -14
  221. package/dist/shields/formats/headers.js.map +1 -1
  222. package/dist/shields/formats/jvm-bytecode.d.ts +20 -0
  223. package/dist/shields/formats/jvm-bytecode.d.ts.map +1 -0
  224. package/dist/shields/formats/jvm-bytecode.js +134 -0
  225. package/dist/shields/formats/jvm-bytecode.js.map +1 -0
  226. package/dist/shields/formats/mobile-game.d.ts +4 -0
  227. package/dist/shields/formats/mobile-game.d.ts.map +1 -1
  228. package/dist/shields/formats/mobile-game.js +16 -0
  229. package/dist/shields/formats/mobile-game.js.map +1 -1
  230. package/dist/shields/formats/model.d.ts +22 -8
  231. package/dist/shields/formats/model.d.ts.map +1 -1
  232. package/dist/shields/formats/model.js +231 -59
  233. package/dist/shields/formats/model.js.map +1 -1
  234. package/dist/shields/formats/native.d.ts +65 -11
  235. package/dist/shields/formats/native.d.ts.map +1 -1
  236. package/dist/shields/formats/native.js +413 -108
  237. package/dist/shields/formats/native.js.map +1 -1
  238. package/dist/shields/formats/pcap-capture.d.ts +27 -0
  239. package/dist/shields/formats/pcap-capture.d.ts.map +1 -0
  240. package/dist/shields/formats/pcap-capture.js +201 -0
  241. package/dist/shields/formats/pcap-capture.js.map +1 -0
  242. package/dist/shields/formats/python.d.ts +22 -1
  243. package/dist/shields/formats/python.d.ts.map +1 -1
  244. package/dist/shields/formats/python.js +568 -27
  245. package/dist/shields/formats/python.js.map +1 -1
  246. package/dist/shields/formats/sourcemap.d.ts.map +1 -1
  247. package/dist/shields/formats/sourcemap.js +2 -0
  248. package/dist/shields/formats/sourcemap.js.map +1 -1
  249. package/dist/shields/formats/sqlite.d.ts +87 -15
  250. package/dist/shields/formats/sqlite.d.ts.map +1 -1
  251. package/dist/shields/formats/sqlite.js +377 -42
  252. package/dist/shields/formats/sqlite.js.map +1 -1
  253. package/dist/shields/formats/wasm.d.ts +6 -0
  254. package/dist/shields/formats/wasm.d.ts.map +1 -1
  255. package/dist/shields/formats/wasm.js +118 -3
  256. package/dist/shields/formats/wasm.js.map +1 -1
  257. package/dist/shields/javascript/ast-shield.d.ts +25 -5
  258. package/dist/shields/javascript/ast-shield.d.ts.map +1 -1
  259. package/dist/shields/javascript/ast-shield.js +428 -58
  260. package/dist/shields/javascript/ast-shield.js.map +1 -1
  261. package/dist/shields/runtime/memory-diff-shield.d.ts +56 -0
  262. package/dist/shields/runtime/memory-diff-shield.d.ts.map +1 -0
  263. package/dist/shields/runtime/memory-diff-shield.js +170 -0
  264. package/dist/shields/runtime/memory-diff-shield.js.map +1 -0
  265. package/dist/shields/runtime/runtime-shield.d.ts +12 -16
  266. package/dist/shields/runtime/runtime-shield.d.ts.map +1 -1
  267. package/dist/shields/runtime/runtime-shield.js +30 -24
  268. package/dist/shields/runtime/runtime-shield.js.map +1 -1
  269. package/dist/shields/tarpit/opaque-predicates.d.ts.map +1 -1
  270. package/dist/shields/tarpit/opaque-predicates.js +3 -3
  271. package/dist/shields/tarpit/opaque-predicates.js.map +1 -1
  272. package/dist/shields/tarpit/tarpit-generator.d.ts +9 -4
  273. package/dist/shields/tarpit/tarpit-generator.d.ts.map +1 -1
  274. package/dist/shields/tarpit/tarpit-generator.js +30 -23
  275. package/dist/shields/tarpit/tarpit-generator.js.map +1 -1
  276. package/package.json +13 -6
@@ -2,10 +2,12 @@ import { parse } from "@babel/parser";
2
2
  import _traverse from "@babel/traverse";
3
3
  import _generate from "@babel/generator";
4
4
  import * as t from "@babel/types";
5
+ import { generateProjectSeed } from "../../core/config.js";
5
6
  import { SeededPrng } from "../../core/prng.js";
6
7
  import { generateChaffPayloads } from "../chaff/chaff-generator.js";
7
8
  import { generateJsTarpitAndBudgetBreaker } from "../tarpit/tarpit-generator.js";
8
9
  import { generateRuntimeDeceptionSnippet } from "../runtime/runtime-shield.js";
10
+ import { generateShadowHeapChurnShield, } from "../runtime/memory-diff-shield.js";
9
11
  import { generateCounterReaExhaustionSuite } from "../exhaustion/index.js";
10
12
  import { generateCounterReaDeceptionSuite } from "../deception/index.js";
11
13
  const traverse = typeof _traverse === "function"
@@ -14,6 +16,12 @@ const traverse = typeof _traverse === "function"
14
16
  const generate = typeof _generate === "function"
15
17
  ? _generate
16
18
  : _generate.default;
19
+ export class InvalidJavaScriptCarrierError extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "InvalidJavaScriptCarrierError";
23
+ }
24
+ }
17
25
  const DECOY_ROUTES = [
18
26
  "/internal/enclave/v2/attest-quote",
19
27
  "/internal/enclave/v2/seal-ledger-state",
@@ -26,7 +34,81 @@ const DECOY_ROUTES = [
26
34
  "/internal/sgx/quote-verification-service",
27
35
  "/internal/nitro/enclave-cid16-dispatch",
28
36
  ];
29
- const IPC_METHODS = new Set(["handle", "handleOnce", "on", "once", "invoke", "send", "sendSync", "sendToHost"]);
37
+ const IPC_METHODS = new Set([
38
+ "handle",
39
+ "handleOnce",
40
+ "on",
41
+ "once",
42
+ "invoke",
43
+ "send",
44
+ "sendSync",
45
+ "sendToHost",
46
+ ]);
47
+ export function inferJsLoaderFromPath(filename) {
48
+ if (!filename)
49
+ return "js";
50
+ const clean = filename.split(/[?#]/, 1)[0].toLowerCase();
51
+ if (clean.endsWith(".tsx"))
52
+ return "tsx";
53
+ if (clean.endsWith(".jsx"))
54
+ return "jsx";
55
+ if (clean.endsWith(".ts") ||
56
+ clean.endsWith(".mts") ||
57
+ clean.endsWith(".cts")) {
58
+ return "ts";
59
+ }
60
+ return "js";
61
+ }
62
+ export function inferJsCarrierFromPath(filename) {
63
+ if (!filename)
64
+ return "auto";
65
+ const clean = filename.split(/[?#]/, 1)[0].toLowerCase();
66
+ if (clean.endsWith(".mjs") || clean.endsWith(".mts"))
67
+ return "module";
68
+ if (clean.endsWith(".cjs") || clean.endsWith(".cts"))
69
+ return "commonjs";
70
+ return "auto";
71
+ }
72
+ export function collectEsmExportedSymbols(program) {
73
+ const exported = [];
74
+ for (const stmt of program.body) {
75
+ if (t.isExportDefaultDeclaration(stmt)) {
76
+ exported.push("default");
77
+ }
78
+ else if (t.isExportAllDeclaration(stmt)) {
79
+ exported.push("*");
80
+ }
81
+ else if (t.isExportNamedDeclaration(stmt)) {
82
+ for (const spec of stmt.specifiers) {
83
+ if (t.isExportSpecifier(spec)) {
84
+ exported.push(t.isIdentifier(spec.exported)
85
+ ? spec.exported.name
86
+ : spec.exported.value);
87
+ }
88
+ else if (t.isExportNamespaceSpecifier(spec)) {
89
+ exported.push(spec.exported.name);
90
+ }
91
+ }
92
+ const decl = stmt.declaration;
93
+ if (decl) {
94
+ if ((t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) &&
95
+ decl.id) {
96
+ exported.push(decl.id.name);
97
+ }
98
+ else if (t.isVariableDeclaration(decl)) {
99
+ const ids = t.getOuterBindingIdentifiers(decl);
100
+ exported.push(...Object.keys(ids));
101
+ }
102
+ else if ("id" in decl &&
103
+ decl.id &&
104
+ t.isIdentifier(decl.id)) {
105
+ exported.push(decl.id.name);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return exported;
111
+ }
30
112
  /**
31
113
  * Splits a string literal into >= 9 conditional chunks `(cond ? realChunk : decoyChunk)`
32
114
  * joined with `+`.
@@ -37,7 +119,7 @@ const IPC_METHODS = new Set(["handle", "handleOnce", "on", "once", "invoke", "se
37
119
  * the cartesian product of candidates is $2^9 = 512 > 256$ (or $2^{10} = 1024 > 256$),
38
120
  * which immediately forces REA to bail out with `semanticResourceLimitUnknown("primitive-candidates")`!
39
121
  *
40
- * At runtime, each condition uses `(Math.imul(_bla_s | k, (_bla_s | k) + 1) & 1) === 0`
122
+ * At runtime, each condition uses `(Math.imul(seed | k, (seed | k) + 1) & 1) === 0`
41
123
  * (which is ALWAYS true because the product of two consecutive integers is always even!),
42
124
  * so the runtime expression evaluates to the EXACT original string in O(1)!
43
125
  */
@@ -62,20 +144,25 @@ function buildCombinatorialStringAst(value, prng, seedIdentifierName) {
62
144
  }
63
145
  }
64
146
  const terms = chunks.map((realChunk, idx) => {
65
- const k = prng.nextInt(3, 125);
147
+ const useOddSq = idx % 3 === 1;
148
+ const k = useOddSq ? prng.nextInt(1, 31) * 4 : (prng.nextInt(3, 125) | 1);
66
149
  const decoyChunk = realChunk.length > 0 ? prng.hex(realChunk.length) : prng.hex(2);
67
- // Opaque true: ((Math.imul(seed | k, (seed | k) + 1) & 1) === 0)
68
- const seededOr = t.binaryExpression("|", t.identifier(seedIdentifierName), t.numericLiteral(k));
69
- const seededPlusOne = t.binaryExpression("+", t.cloneNode(seededOr), t.numericLiteral(1));
70
- const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededOr, seededPlusOne]);
71
- const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(1));
72
- const cond = t.binaryExpression("===", bitAnd, t.numericLiteral(0));
150
+ const seededOr = t.binaryExpression(useOddSq ? "^" : "|", t.identifier(seedIdentifierName), t.numericLiteral(k));
151
+ const rhs = useOddSq
152
+ ? t.cloneNode(seededOr)
153
+ : t.binaryExpression("+", t.cloneNode(seededOr), t.numericLiteral(1));
154
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededOr, rhs]);
155
+ const mask = useOddSq ? 7 : 1;
156
+ const trueVal = useOddSq ? 1 : 0;
157
+ const falseVal = useOddSq ? 0 : 1;
158
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(mask));
159
+ const cond = t.binaryExpression("===", bitAnd, t.numericLiteral(trueVal));
73
160
  // Alternate polarity on odd indices so static heuristics see both true/false arms used
74
161
  if (idx % 2 === 0) {
75
162
  return t.conditionalExpression(cond, t.stringLiteral(realChunk), t.stringLiteral(decoyChunk));
76
163
  }
77
164
  else {
78
- const invertedCond = t.binaryExpression("===", bitAnd, t.numericLiteral(1));
165
+ const invertedCond = t.binaryExpression("===", bitAnd, t.numericLiteral(falseVal));
79
166
  return t.conditionalExpression(invertedCond, t.stringLiteral(decoyChunk), t.stringLiteral(realChunk));
80
167
  }
81
168
  });
@@ -86,39 +173,102 @@ function buildCombinatorialStringAst(value, prng, seedIdentifierName) {
86
173
  return expr;
87
174
  }
88
175
  function buildOpaqueFalseAst(prng, seedIdentifierName) {
89
- const k = prng.nextInt(5, 113);
90
- const seededOr = t.binaryExpression("|", t.identifier(seedIdentifierName), t.numericLiteral(k));
91
- const seededPlusOne = t.binaryExpression("+", t.cloneNode(seededOr), t.numericLiteral(1));
92
- const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededOr, seededPlusOne]);
93
- const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(1));
176
+ const k4 = prng.nextInt(1, 31) * 4;
177
+ const seededXor = t.binaryExpression("^", t.identifier(seedIdentifierName), t.numericLiteral(k4));
178
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededXor, t.cloneNode(seededXor)]);
179
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(7));
180
+ return t.binaryExpression("===", bitAnd, t.numericLiteral(0));
181
+ }
182
+ /**
183
+ * Opaque TRUE entangled with the runtime Cognitive-Armor digest bit:
184
+ * When untampered, `seedIdentifierName` is odd, so `u = seed ^ (4*k)` is odd
185
+ * and `(Math.imul(u, u) & 7) === 1`. If the Cognitive-Armor corpus is stripped
186
+ * or redacted, `seedIdentifierName` becomes a multiple of 4 and this flips to FALSE.
187
+ */
188
+ function buildOpaqueTrueAst(prng, seedIdentifierName) {
189
+ const k4 = prng.nextInt(1, 31) * 4;
190
+ const seededXor = t.binaryExpression("^", t.identifier(seedIdentifierName), t.numericLiteral(k4));
191
+ const imulCall = t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("imul")), [seededXor, t.cloneNode(seededXor)]);
192
+ const bitAnd = t.binaryExpression("&", imulCall, t.numericLiteral(7));
94
193
  return t.binaryExpression("===", bitAnd, t.numericLiteral(1));
95
194
  }
195
+ const RENAME_RESERVED = new Set([
196
+ "exports", "module", "require", "arguments", "undefined", "NaN", "Infinity",
197
+ "globalThis", "global", "window", "self", "console", "Math", "Object", "Array",
198
+ "Promise", "Buffer", "process", "__dirname", "__filename", "JSON", "Date",
199
+ "Error", "TypeError", "RangeError", "Map", "Set", "WeakMap", "WeakSet",
200
+ "Symbol", "Proxy", "Reflect", "parseInt", "parseFloat", "isNaN", "isFinite",
201
+ "encodeURIComponent", "decodeURIComponent", "setTimeout", "clearTimeout",
202
+ "setInterval", "clearInterval", "fetch", "URL", "URLSearchParams",
203
+ "TextEncoder", "TextDecoder", "Uint8Array", "DataView", "ArrayBuffer",
204
+ "SharedArrayBuffer", "Atomics", "WebAssembly", "Intl", "BigInt",
205
+ ]);
206
+ function buildParserPlugins(loader, hasExplicitLoaderOrFilename) {
207
+ const plugins = [
208
+ "decorators-legacy",
209
+ "importAttributes",
210
+ "dynamicImport",
211
+ "classProperties",
212
+ "topLevelAwait",
213
+ ];
214
+ if (!hasExplicitLoaderOrFilename) {
215
+ plugins.unshift("typescript", "jsx");
216
+ return plugins;
217
+ }
218
+ if (loader === "ts") {
219
+ plugins.unshift("typescript");
220
+ }
221
+ else if (loader === "tsx") {
222
+ plugins.unshift("typescript", "jsx");
223
+ }
224
+ else if (loader === "jsx") {
225
+ plugins.unshift("jsx");
226
+ }
227
+ return plugins;
228
+ }
96
229
  export function transformJavaScriptWithBlaShield(source, options = {}) {
97
230
  const intensity = options.intensity ?? "balanced";
98
- const prng = new SeededPrng(options.seed ?? "bla-js-shield-v1");
231
+ const prng = new SeededPrng(options.seed ?? generateProjectSeed());
99
232
  const chaffPayloads = generateChaffPayloads(prng, intensity);
100
233
  const tarpit = generateJsTarpitAndBudgetBreaker(prng, intensity, chaffPayloads);
101
234
  const runtimeShield = generateRuntimeDeceptionSnippet(prng, intensity, chaffPayloads);
102
235
  const exhaustionSuite = generateCounterReaExhaustionSuite(prng, intensity);
103
236
  const deceptionSuite = generateCounterReaDeceptionSuite(prng, intensity);
104
- const ast = parse(source, {
105
- sourceType: "unambiguous",
106
- plugins: [
107
- "typescript",
108
- "jsx",
109
- "decorators-legacy",
110
- "importAttributes",
111
- "dynamicImport",
112
- "classProperties",
113
- "topLevelAwait",
114
- ],
115
- errorRecovery: true,
116
- });
117
- const seedVarName = `_bla_rt_${prng.hex(4)}`;
237
+ const memoryDiffShield = generateShadowHeapChurnShield(prng, intensity);
238
+ const hasExplicitLoaderOrFilename = options.loader !== undefined || options.filename !== undefined;
239
+ const loader = options.loader ?? inferJsLoaderFromPath(options.filename);
240
+ const requestedCarrier = options.sourceType ?? inferJsCarrierFromPath(options.filename);
241
+ const parserSourceType = requestedCarrier === "script" || requestedCarrier === "commonjs"
242
+ ? "script"
243
+ : requestedCarrier === "module"
244
+ ? "module"
245
+ : "unambiguous";
246
+ let ast;
247
+ try {
248
+ ast = parse(source, {
249
+ sourceType: parserSourceType,
250
+ plugins: buildParserPlugins(loader, hasExplicitLoaderOrFilename),
251
+ errorRecovery: false,
252
+ });
253
+ }
254
+ catch (err) {
255
+ throw new InvalidJavaScriptCarrierError(`Failed to parse JavaScript/TypeScript input (carrier=${requestedCarrier}, loader=${loader}): ${err instanceof Error ? err.message : String(err)}`);
256
+ }
257
+ const hasEsmNodes = ast.program.body.some((stmt) => t.isImportDeclaration(stmt) ||
258
+ t.isExportNamedDeclaration(stmt) ||
259
+ t.isExportDefaultDeclaration(stmt) ||
260
+ t.isExportAllDeclaration(stmt));
261
+ if ((requestedCarrier === "script" || requestedCarrier === "commonjs") &&
262
+ hasEsmNodes) {
263
+ throw new InvalidJavaScriptCarrierError(`ESM import/export syntax is not allowed in '${requestedCarrier}' carrier`);
264
+ }
265
+ const exportedSymbolsBefore = collectEsmExportedSymbols(ast.program);
266
+ const seedVarName = prng.identifier({ style: "camel", hint: "runtimeSeed", entropy: 4 });
118
267
  const observedIpcChannels = new Set();
119
268
  let primitiveCandidateBranchesCreated = 512; // From tarpit budgetFn
120
269
  let fakeCrossReferencesCreated = tarpit.crossReferenceEdges;
121
270
  let ipcAmbiguitySitesInjected = 0;
271
+ let usesCjsAst = false;
122
272
  // Track functions to weave tarpit calls into
123
273
  const functionBodies = [];
124
274
  traverse(ast, {
@@ -127,8 +277,23 @@ export function transformJavaScriptWithBlaShield(source, options = {}) {
127
277
  functionBodies.push(path.node.body);
128
278
  }
129
279
  },
280
+ MemberExpression(path) {
281
+ const { object, property } = path.node;
282
+ if (t.isIdentifier(object) &&
283
+ object.name === "module" &&
284
+ t.isIdentifier(property) &&
285
+ property.name === "exports") {
286
+ usesCjsAst = true;
287
+ }
288
+ else if (t.isIdentifier(object) && object.name === "exports") {
289
+ usesCjsAst = true;
290
+ }
291
+ },
130
292
  CallExpression(path) {
131
293
  const callee = path.node.callee;
294
+ if (t.isIdentifier(callee) && callee.name === "require") {
295
+ usesCjsAst = true;
296
+ }
132
297
  // 1. Check Electron IPC & contextBridge calls
133
298
  if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {
134
299
  const methodName = callee.property.name;
@@ -181,28 +346,204 @@ export function transformJavaScriptWithBlaShield(source, options = {}) {
181
346
  }
182
347
  }
183
348
  },
349
+ StringLiteral(path) {
350
+ if (intensity !== "bankrupt" && intensity !== "maximum") {
351
+ return;
352
+ }
353
+ const val = path.node.value;
354
+ if (val.length < 3 || val.length > 256) {
355
+ return;
356
+ }
357
+ const parent = path.parent;
358
+ if (t.isImportDeclaration(parent) ||
359
+ t.isExportNamedDeclaration(parent) ||
360
+ t.isExportAllDeclaration(parent) ||
361
+ t.isTSLiteralType(parent) ||
362
+ t.isTSImportType(parent) ||
363
+ t.isTSExternalModuleReference(parent) ||
364
+ t.isTSModuleDeclaration(parent) ||
365
+ t.isImportAttribute(parent) ||
366
+ (t.isExpressionStatement(parent) && val.startsWith("use "))) {
367
+ return;
368
+ }
369
+ if (path.findParent((p) => p.isTSType() ||
370
+ p.isTSModuleDeclaration() ||
371
+ p.isTSExternalModuleReference() ||
372
+ p.isImportAttribute())) {
373
+ return;
374
+ }
375
+ if (t.isObjectProperty(parent) &&
376
+ parent.key === path.node &&
377
+ !parent.computed) {
378
+ return;
379
+ }
380
+ if (t.isClassMethod(parent) ||
381
+ t.isObjectMethod(parent) ||
382
+ t.isClassProperty(parent)) {
383
+ return;
384
+ }
385
+ if (t.isCallExpression(parent) &&
386
+ t.isIdentifier(parent.callee) &&
387
+ parent.callee.name === "require") {
388
+ return;
389
+ }
390
+ path.replaceWith(buildCombinatorialStringAst(val, prng, seedVarName));
391
+ path.skip();
392
+ primitiveCandidateBranchesCreated += 256;
393
+ },
394
+ });
395
+ const effectiveCarrier = requestedCarrier === "module" || hasEsmNodes
396
+ ? "module"
397
+ : requestedCarrier === "commonjs" || usesCjsAst
398
+ ? "commonjs"
399
+ : "script";
400
+ // 2b. Rename non-exported local bindings (including function parameters and private helpers)
401
+ // so original identifiers are not left pristine
402
+ const exportedNameSet = new Set(exportedSymbolsBefore);
403
+ const generatedNames = new Set();
404
+ traverse(ast, {
405
+ Scope(path) {
406
+ for (const [name, binding] of Object.entries(path.scope.bindings)) {
407
+ if (RENAME_RESERVED.has(name))
408
+ continue;
409
+ if (exportedNameSet.has(name))
410
+ continue;
411
+ if (binding.kind === "module")
412
+ continue;
413
+ if (name.startsWith("_") && name.length <= 2)
414
+ continue;
415
+ if (/^(_interlockSafetyCorpus_|_deriveContainmentCorpusDigest_|_DISTRIBUTED_ASL3_|_SELF_SEAL_TARGET)/.test(name)) {
416
+ continue;
417
+ }
418
+ if (generatedNames.has(name))
419
+ continue;
420
+ if (binding.kind !== "let" &&
421
+ binding.kind !== "const" &&
422
+ binding.kind !== "var" &&
423
+ binding.kind !== "hoisted" &&
424
+ binding.kind !== "local" &&
425
+ binding.kind !== "param") {
426
+ continue;
427
+ }
428
+ if (binding.kind === "param" &&
429
+ (binding.path.isTSParameterProperty() ||
430
+ binding.path.parentPath?.isTSParameterProperty())) {
431
+ continue;
432
+ }
433
+ // In classic "script" carrier, top-level hoisted functions may be invoked globally;
434
+ // in "module" / "commonjs" carriers, only preserve pre-tagged decoy identifiers.
435
+ if (path.scope.path.isProgram() &&
436
+ binding.kind === "hoisted" &&
437
+ (effectiveCarrier === "script" || /_[0-9a-f]{3,4}$/i.test(name))) {
438
+ continue;
439
+ }
440
+ const newName = prng.identifier({
441
+ style: name.startsWith("_") ? "privateCamel" : "camel",
442
+ hint: intensity === "bankrupt" || intensity === "maximum"
443
+ ? undefined
444
+ : name.replace(/^_+/, "").slice(0, 16) || "local",
445
+ entropy: 3,
446
+ });
447
+ if (newName === name ||
448
+ RENAME_RESERVED.has(newName) ||
449
+ exportedNameSet.has(newName) ||
450
+ generatedNames.has(newName)) {
451
+ continue;
452
+ }
453
+ try {
454
+ path.scope.rename(name, newName);
455
+ generatedNames.add(newName);
456
+ }
457
+ catch {
458
+ // Binding may be constant-violating or conflict; skip safely
459
+ }
460
+ }
461
+ },
184
462
  });
185
- // 3. Weave unreachable tarpit calls (Fake XRefs) into real function bodies
463
+ // 2c. Transform / relocate comments so original Chinese/doc comments are not pristine
464
+ if (ast.comments) {
465
+ for (const c of ast.comments) {
466
+ if (/sourceMappingURL=/i.test(c.value))
467
+ continue;
468
+ // Relocate + scramble: destroy verbatim original comments (incl. Chinese docs)
469
+ // while preserving that a comment existed (so AST shape stays similar).
470
+ const theme = prng.pick([
471
+ "reconcile session epoch",
472
+ "derive ledger digest",
473
+ "normalize envelope frame",
474
+ "hydrate runtime cache",
475
+ "project quota policy",
476
+ ]);
477
+ const scrambled = prng.hex(6);
478
+ c.value = c.type === "CommentBlock"
479
+ ? ` ${theme} (${scrambled}) `
480
+ : ` ${theme} (${scrambled})`;
481
+ }
482
+ }
483
+ // 2d. Entangle REAL statements with opaque-TRUE guards so blind deletion breaks behavior
484
+ traverse(ast, {
485
+ BlockStatement(path) {
486
+ // Skip injected blocks that don't exist yet; only original function bodies
487
+ if (!functionBodies.includes(path.node))
488
+ return;
489
+ const stmts = path.node.body;
490
+ if (stmts.length === 0)
491
+ return;
492
+ const next = [];
493
+ for (let i = 0; i < stmts.length; i++) {
494
+ const stmt = stmts[i];
495
+ // Don't wrap returns/throws/declarations/directives — wrap expression & if stmts
496
+ // NEVER wrap VariableDeclaration / FunctionDeclaration / Return / Throw —
497
+ // that would change block scoping and break the program under our own shield.
498
+ const wrappable = t.isExpressionStatement(stmt) ||
499
+ (t.isIfStatement(stmt) && !t.isVariableDeclaration(stmt.consequent));
500
+ if (wrappable && i % 2 === 0) {
501
+ next.push(t.ifStatement(buildOpaqueTrueAst(prng, seedVarName), t.blockStatement([stmt])));
502
+ }
503
+ else {
504
+ next.push(stmt);
505
+ }
506
+ }
507
+ path.node.body = next;
508
+ },
509
+ });
510
+ // 3. Weave synchronized shadow-heap churn + unreachable tarpit calls into real function bodies
186
511
  for (const body of functionBodies) {
512
+ const stepCallStmt = t.expressionStatement(t.callExpression(t.identifier(memoryDiffShield.stepperFunctionName), [
513
+ t.numericLiteral(prng.nextInt(1, 4095)),
514
+ ]));
187
515
  if (tarpit.decoyFunctionNames.length >= 2) {
188
516
  const d1 = prng.pick(tarpit.decoyFunctionNames);
189
517
  const d2 = prng.pick(tarpit.decoyFunctionNames);
190
518
  const guard = t.ifStatement(buildOpaqueFalseAst(prng, seedVarName), t.blockStatement([
191
- t.expressionStatement(t.binaryExpression("^", t.callExpression(t.identifier(d1), [t.numericLiteral(prng.nextInt(1, 255)), t.numericLiteral(2)]), t.callExpression(t.identifier(d2), [t.numericLiteral(prng.nextInt(1, 255)), t.numericLiteral(2)]))),
519
+ t.expressionStatement(t.binaryExpression("^", t.callExpression(t.identifier(d1), [
520
+ t.numericLiteral(prng.nextInt(1, 255)),
521
+ t.numericLiteral(2),
522
+ ]), t.callExpression(t.identifier(d2), [
523
+ t.numericLiteral(prng.nextInt(1, 255)),
524
+ t.numericLiteral(2),
525
+ ]))),
192
526
  ]));
193
- body.body.unshift(guard);
194
- fakeCrossReferencesCreated += 2;
527
+ body.body.unshift(stepCallStmt, guard);
528
+ fakeCrossReferencesCreated += 3;
529
+ }
530
+ else {
531
+ body.body.unshift(stepCallStmt);
532
+ fakeCrossReferencesCreated += 1;
195
533
  }
196
534
  }
197
- // 4. Build Decoy IPC Ambiguity & Route Mirage block
535
+ // 4. Build Decoy IPC Ambiguity & Route Mirage block + Cognitive-Armor seed entanglement
198
536
  const mirageLines = [];
199
- mirageLines.push(`const ${seedVarName} = 7;`);
537
+ mirageLines.push(deceptionSuite.cognitiveArmor.code);
538
+ mirageLines.push(`const ${seedVarName} = (((typeof process !== "undefined" && typeof process?.hrtime?.bigint === "function" ? Number(process.hrtime.bigint() & 0x7fffcn) : (typeof Date !== "undefined" ? (Date.now() & 0x7fffc) : 4)) & 0x7fffc) | ((typeof ${deceptionSuite.cognitiveArmor.digestFunctionName} === "function" && ${deceptionSuite.cognitiveArmor.digestFunctionName}(0) === ${deceptionSuite.cognitiveArmor.expectedDigest}) ? 1 : 0));`);
539
+ mirageLines.push(memoryDiffShield.code);
200
540
  const channelsToMirror = observedIpcChannels.size > 0
201
541
  ? [...observedIpcChannels]
202
542
  : ["enclave:attest", "clipboard:bridge-sync", "license:verify-lease"];
203
543
  const decoyRouteCount = intensity === "stealth" ? 4 : intensity === "balanced" ? 8 : 10;
204
544
  const selectedDecoyRoutes = DECOY_ROUTES.slice(0, decoyRouteCount);
205
- mirageLines.push(`function _bla_registerDecoyIpcAndRoutes_${prng.hex(4)}(_ipcMain, _ipcRenderer, _router) {`);
545
+ const decoyIpcFnName = prng.identifier({ style: "camel", hint: "registerDecoyIpcAndRoutes", entropy: 4 });
546
+ mirageLines.push(`function ${decoyIpcFnName}(_ipcMain, _ipcRenderer, _router) {`);
206
547
  mirageLines.push(` if (((Math.imul(${seedVarName} | 11, (${seedVarName} | 11) + 1) & 1) === 1)) {`);
207
548
  for (const ch of channelsToMirror) {
208
549
  // Register duplicate ambiguous literal channels on both ipcMain and ipcRenderer
@@ -219,34 +560,58 @@ export function transformJavaScriptWithBlaShield(source, options = {}) {
219
560
  }
220
561
  mirageLines.push(` }`);
221
562
  mirageLines.push(`}`);
222
- // Parse the tarpit + mirage code and append/prepend to AST program while keeping module compatibility
223
- const usesCommonJs = source.includes("module.exports") ||
224
- source.includes("exports.") ||
225
- (!source.includes("export ") && source.includes("require("));
226
- const tarpitCodeNormalized = usesCommonJs
227
- ? tarpit.code.replace(/export function /g, "function ")
228
- : tarpit.code;
229
- const combinedInjectedAst = parse([
563
+ mirageLines.push(`void ${decoyIpcFnName};`);
564
+ const deceptionWithoutDuplicateArmor = deceptionSuite.combinedJsCode.replace(deceptionSuite.cognitiveArmor.code, "");
565
+ const injectedBlocks = [
230
566
  mirageLines.join("\n"),
231
- runtimeShield.code,
232
- tarpitCodeNormalized,
567
+ ...(options.enableRuntimeShield !== false ? [runtimeShield.code] : []),
568
+ tarpit.code.replace(/\bexport\s+function\s+/g, "function "),
233
569
  exhaustionSuite.combinedJsCode,
234
- deceptionSuite.combinedJsCode,
235
- ].join("\n\n"), {
236
- sourceType: "unambiguous",
570
+ deceptionWithoutDuplicateArmor,
571
+ ];
572
+ const combinedInjectedAst = parse(injectedBlocks.join("\n\n"), {
573
+ sourceType: "script",
237
574
  plugins: ["typescript"],
238
575
  });
239
- // Prepend `seedVarName` declaration at top of program (after any directives / imports)
576
+ const sanitizedInjectedStatements = [];
577
+ for (const stmt of combinedInjectedAst.program.body) {
578
+ if (t.isExportNamedDeclaration(stmt) && stmt.declaration) {
579
+ sanitizedInjectedStatements.push(stmt.declaration);
580
+ }
581
+ else if (!t.isImportDeclaration(stmt) &&
582
+ !t.isExportNamedDeclaration(stmt) &&
583
+ !t.isExportDefaultDeclaration(stmt) &&
584
+ !t.isExportAllDeclaration(stmt)) {
585
+ sanitizedInjectedStatements.push(stmt);
586
+ }
587
+ }
588
+ // Prepend Cognitive-Armor corpus, digest function, `seedVarName`, and shadow heap at top of program
240
589
  let insertIndex = 0;
241
- while (insertIndex < ast.program.body.length &&
242
- t.isImportDeclaration(ast.program.body[insertIndex])) {
243
- insertIndex++;
590
+ while (insertIndex < ast.program.body.length) {
591
+ const stmt = ast.program.body[insertIndex];
592
+ if (t.isImportDeclaration(stmt)) {
593
+ insertIndex++;
594
+ continue;
595
+ }
596
+ if (t.isExpressionStatement(stmt) &&
597
+ t.isStringLiteral(stmt.expression) &&
598
+ stmt.expression.value.startsWith("use ")) {
599
+ insertIndex++;
600
+ continue;
601
+ }
602
+ break;
244
603
  }
245
- const [seedDecl, ...restInjected] = combinedInjectedAst.program.body;
246
- if (seedDecl) {
247
- ast.program.body.splice(insertIndex, 0, seedDecl);
604
+ const [corpusDecl, digestFnDecl, seedDecl, heapDecl, ...restInjected] = sanitizedInjectedStatements;
605
+ const topDecls = [corpusDecl, digestFnDecl, seedDecl, heapDecl].filter((s) => s !== undefined);
606
+ if (topDecls.length > 0) {
607
+ ast.program.body.splice(insertIndex, 0, ...topDecls);
248
608
  }
249
609
  ast.program.body.push(...restInjected);
610
+ const exportedSymbolsAfter = collectEsmExportedSymbols(ast.program);
611
+ if (exportedSymbolsBefore.length !== exportedSymbolsAfter.length ||
612
+ exportedSymbolsBefore.some((sym, idx) => sym !== exportedSymbolsAfter[idx])) {
613
+ throw new InvalidJavaScriptCarrierError("Internal error: BLA JavaScript transform mutated module export surface");
614
+ }
250
615
  // Strip any existing `//# sourceMappingURL=` comments from AST
251
616
  if (ast.comments) {
252
617
  ast.comments = ast.comments.filter((c) => !/sourceMappingURL=/i.test(c.value));
@@ -258,11 +623,14 @@ export function transformJavaScriptWithBlaShield(source, options = {}) {
258
623
  }, source);
259
624
  return {
260
625
  code: generated.code,
626
+ carrierType: effectiveCarrier,
627
+ loader,
628
+ exportedSymbols: exportedSymbolsAfter,
261
629
  decoyFunctionsInjected: tarpit.decoyFunctionNames.length +
262
630
  exhaustionSuite.totalLabyrinthNodes +
263
631
  deceptionSuite.shadowLogic.shadowProceduresCreated.length +
264
632
  deceptionSuite.semanticHoneypot.baitSymbols.length +
265
- 1,
633
+ 2,
266
634
  fakeCrossReferencesCreated: fakeCrossReferencesCreated + exhaustionSuite.totalCrossReferenceEdges,
267
635
  primitiveCandidateBranchesCreated,
268
636
  aliasSelectionStatesCreated: 4_194_304, // 2^22 selector states in aliasFn
@@ -270,6 +638,8 @@ export function transformJavaScriptWithBlaShield(source, options = {}) {
270
638
  decoyRoutesInjected: selectedDecoyRoutes.length +
271
639
  deceptionSuite.architectureMirage.decoyRpcMethods.length,
272
640
  chaffPayloadsEmbedded: chaffPayloads.length + deceptionSuite.evidencePoison.lures.length,
641
+ shadowHeapSlotsChurned: memoryDiffShield.mutableSlotsCount,
642
+ memoryDiffShield,
273
643
  };
274
644
  }
275
645
  //# sourceMappingURL=ast-shield.js.map