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.
- package/.agents/skills/blind-llm-agents/SKILL.md +20 -14
- package/DISCLAIMER.md +15 -7
- package/README.md +153 -198
- package/dist/bundler/index.d.ts +19 -2
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +47 -4
- package/dist/bundler/index.js.map +1 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +123 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/config.d.ts +54 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +160 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/coverage-contract.d.ts +97 -0
- package/dist/core/coverage-contract.d.ts.map +1 -0
- package/dist/core/coverage-contract.js +164 -0
- package/dist/core/coverage-contract.js.map +1 -0
- package/dist/core/debug-posture.d.ts +40 -0
- package/dist/core/debug-posture.d.ts.map +1 -0
- package/dist/core/debug-posture.js +197 -0
- package/dist/core/debug-posture.js.map +1 -0
- package/dist/core/detector.d.ts.map +1 -1
- package/dist/core/detector.js +58 -6
- package/dist/core/detector.js.map +1 -1
- package/dist/core/identifiers.d.ts +32 -0
- package/dist/core/identifiers.d.ts.map +1 -0
- package/dist/core/identifiers.js +263 -0
- package/dist/core/identifiers.js.map +1 -0
- package/dist/core/llm-directives.d.ts +12 -0
- package/dist/core/llm-directives.d.ts.map +1 -0
- package/dist/core/llm-directives.js +23 -0
- package/dist/core/llm-directives.js.map +1 -0
- package/dist/core/prng.d.ts +10 -1
- package/dist/core/prng.d.ts.map +1 -1
- package/dist/core/prng.js +27 -2
- package/dist/core/prng.js.map +1 -1
- package/dist/core/release-plan.d.ts +68 -0
- package/dist/core/release-plan.d.ts.map +1 -0
- package/dist/core/release-plan.js +235 -0
- package/dist/core/release-plan.js.map +1 -0
- package/dist/core/sarif.d.ts +53 -0
- package/dist/core/sarif.d.ts.map +1 -0
- package/dist/core/sarif.js +91 -0
- package/dist/core/sarif.js.map +1 -0
- package/dist/core/sqlite-runtime.d.ts +13 -0
- package/dist/core/sqlite-runtime.d.ts.map +1 -1
- package/dist/core/sqlite-runtime.js +38 -8
- package/dist/core/sqlite-runtime.js.map +1 -1
- package/dist/core/types.d.ts +7 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/engine/auditor.d.ts.map +1 -1
- package/dist/engine/auditor.js +251 -8
- package/dist/engine/auditor.js.map +1 -1
- package/dist/engine/benchmark.d.ts +1 -1
- package/dist/engine/benchmark.d.ts.map +1 -1
- package/dist/engine/benchmark.js +121 -41
- package/dist/engine/benchmark.js.map +1 -1
- package/dist/engine/defender.d.ts +1 -0
- package/dist/engine/defender.d.ts.map +1 -1
- package/dist/engine/defender.js +7 -1
- package/dist/engine/defender.js.map +1 -1
- package/dist/engine/harden.d.ts +61 -0
- package/dist/engine/harden.d.ts.map +1 -0
- package/dist/engine/harden.js +292 -0
- package/dist/engine/harden.js.map +1 -0
- package/dist/engine/protector.d.ts.map +1 -1
- package/dist/engine/protector.js +162 -21
- package/dist/engine/protector.js.map +1 -1
- package/dist/identity.d.ts +112 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +112 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +26 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +59 -152
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +466 -50
- package/dist/mcp/server.js.map +1 -1
- package/dist/setup/clients.d.ts +49 -1
- package/dist/setup/clients.d.ts.map +1 -1
- package/dist/setup/clients.js +1193 -20
- package/dist/setup/clients.js.map +1 -1
- package/dist/setup/doctor.d.ts +58 -14
- package/dist/setup/doctor.d.ts.map +1 -1
- package/dist/setup/doctor.js +316 -22
- package/dist/setup/doctor.js.map +1 -1
- package/dist/setup/setup.d.ts +77 -7
- package/dist/setup/setup.d.ts.map +1 -1
- package/dist/setup/setup.js +591 -62
- package/dist/setup/setup.js.map +1 -1
- package/dist/shields/chaff/chaff-generator.d.ts.map +1 -1
- package/dist/shields/chaff/chaff-generator.js +12 -3
- package/dist/shields/chaff/chaff-generator.js.map +1 -1
- package/dist/shields/deception/architecture-mirage.js +1 -1
- package/dist/shields/deception/architecture-mirage.js.map +1 -1
- package/dist/shields/deception/canary-honeypot.d.ts +33 -0
- package/dist/shields/deception/canary-honeypot.d.ts.map +1 -0
- package/dist/shields/deception/canary-honeypot.js +95 -0
- package/dist/shields/deception/canary-honeypot.js.map +1 -0
- package/dist/shields/deception/cognitive-armor-trigger.d.ts +43 -0
- package/dist/shields/deception/cognitive-armor-trigger.d.ts.map +1 -0
- package/dist/shields/deception/cognitive-armor-trigger.js +204 -0
- package/dist/shields/deception/cognitive-armor-trigger.js.map +1 -0
- package/dist/shields/deception/crash-trace-decoy.js +1 -1
- package/dist/shields/deception/crash-trace-decoy.js.map +1 -1
- package/dist/shields/deception/decompiler-illusion.js +1 -1
- package/dist/shields/deception/decompiler-illusion.js.map +1 -1
- package/dist/shields/deception/diff-noise-injector.js +1 -1
- package/dist/shields/deception/diff-noise-injector.js.map +1 -1
- package/dist/shields/deception/evidence-contract-poison.js +1 -1
- package/dist/shields/deception/evidence-contract-poison.js.map +1 -1
- package/dist/shields/deception/format-payloads.d.ts +21 -0
- package/dist/shields/deception/format-payloads.d.ts.map +1 -0
- package/dist/shields/deception/format-payloads.js +24 -0
- package/dist/shields/deception/format-payloads.js.map +1 -0
- package/dist/shields/deception/index.d.ts +10 -2
- package/dist/shields/deception/index.d.ts.map +1 -1
- package/dist/shields/deception/index.js +20 -3
- package/dist/shields/deception/index.js.map +1 -1
- package/dist/shields/deception/prompt-completion-poison.d.ts +3 -2
- package/dist/shields/deception/prompt-completion-poison.d.ts.map +1 -1
- package/dist/shields/deception/prompt-completion-poison.js +6 -3
- package/dist/shields/deception/prompt-completion-poison.js.map +1 -1
- package/dist/shields/deception/shadow-business-logic.js +4 -4
- package/dist/shields/deception/shadow-business-logic.js.map +1 -1
- package/dist/shields/deception/system-diagnostic-decoy.d.ts +36 -0
- package/dist/shields/deception/system-diagnostic-decoy.d.ts.map +1 -0
- package/dist/shields/deception/system-diagnostic-decoy.js +101 -0
- package/dist/shields/deception/system-diagnostic-decoy.js.map +1 -0
- package/dist/shields/exhaustion/asar-header-amplifier.d.ts +12 -3
- package/dist/shields/exhaustion/asar-header-amplifier.d.ts.map +1 -1
- package/dist/shields/exhaustion/asar-header-amplifier.js +30 -8
- package/dist/shields/exhaustion/asar-header-amplifier.js.map +1 -1
- package/dist/shields/exhaustion/bpe-token-amplifier.js +2 -2
- package/dist/shields/exhaustion/bpe-token-amplifier.js.map +1 -1
- package/dist/shields/exhaustion/callgraph-labyrinth.js +2 -2
- package/dist/shields/exhaustion/callgraph-labyrinth.js.map +1 -1
- package/dist/shields/exhaustion/cdp-shape-budget-breaker.js +1 -1
- package/dist/shields/exhaustion/cdp-shape-budget-breaker.js.map +1 -1
- package/dist/shields/exhaustion/frida-capture-saturation.d.ts +10 -5
- package/dist/shields/exhaustion/frida-capture-saturation.d.ts.map +1 -1
- package/dist/shields/exhaustion/frida-capture-saturation.js +21 -8
- package/dist/shields/exhaustion/frida-capture-saturation.js.map +1 -1
- package/dist/shields/exhaustion/index.d.ts +2 -2
- package/dist/shields/exhaustion/index.d.ts.map +1 -1
- package/dist/shields/exhaustion/index.js +2 -2
- package/dist/shields/exhaustion/index.js.map +1 -1
- package/dist/shields/exhaustion/obligation-flooder.d.ts +17 -5
- package/dist/shields/exhaustion/obligation-flooder.d.ts.map +1 -1
- package/dist/shields/exhaustion/obligation-flooder.js +20 -8
- package/dist/shields/exhaustion/obligation-flooder.js.map +1 -1
- package/dist/shields/exhaustion/rea-budget-matrix.d.ts +8 -2
- package/dist/shields/exhaustion/rea-budget-matrix.d.ts.map +1 -1
- package/dist/shields/exhaustion/rea-budget-matrix.js +139 -16
- package/dist/shields/exhaustion/rea-budget-matrix.js.map +1 -1
- package/dist/shields/exhaustion/regex-worker-tarpit.d.ts.map +1 -1
- package/dist/shields/exhaustion/regex-worker-tarpit.js +2 -1
- package/dist/shields/exhaustion/regex-worker-tarpit.js.map +1 -1
- package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts +7 -4
- package/dist/shields/exhaustion/wasm-interface-exhaustion.d.ts.map +1 -1
- package/dist/shields/exhaustion/wasm-interface-exhaustion.js +16 -7
- package/dist/shields/exhaustion/wasm-interface-exhaustion.js.map +1 -1
- package/dist/shields/formats/android-dex-xref.d.ts +19 -0
- package/dist/shields/formats/android-dex-xref.d.ts.map +1 -0
- package/dist/shields/formats/android-dex-xref.js +427 -0
- package/dist/shields/formats/android-dex-xref.js.map +1 -0
- package/dist/shields/formats/android-manifest.d.ts +44 -0
- package/dist/shields/formats/android-manifest.d.ts.map +1 -0
- package/dist/shields/formats/android-manifest.js +240 -0
- package/dist/shields/formats/android-manifest.js.map +1 -0
- package/dist/shields/formats/android-r8.d.ts +44 -0
- package/dist/shields/formats/android-r8.d.ts.map +1 -0
- package/dist/shields/formats/android-r8.js +246 -0
- package/dist/shields/formats/android-r8.js.map +1 -0
- package/dist/shields/formats/apple-plist.d.ts +15 -0
- package/dist/shields/formats/apple-plist.d.ts.map +1 -1
- package/dist/shields/formats/apple-plist.js +59 -1
- package/dist/shields/formats/apple-plist.js.map +1 -1
- package/dist/shields/formats/archive.d.ts +27 -6
- package/dist/shields/formats/archive.d.ts.map +1 -1
- package/dist/shields/formats/archive.js +247 -45
- package/dist/shields/formats/archive.js.map +1 -1
- package/dist/shields/formats/asar.d.ts +50 -10
- package/dist/shields/formats/asar.d.ts.map +1 -1
- package/dist/shields/formats/asar.js +265 -39
- package/dist/shields/formats/asar.js.map +1 -1
- package/dist/shields/formats/bun-standalone.d.ts +78 -0
- package/dist/shields/formats/bun-standalone.d.ts.map +1 -0
- package/dist/shields/formats/bun-standalone.js +272 -0
- package/dist/shields/formats/bun-standalone.js.map +1 -0
- package/dist/shields/formats/dotnet-managed.d.ts +9 -0
- package/dist/shields/formats/dotnet-managed.d.ts.map +1 -1
- package/dist/shields/formats/dotnet-managed.js +26 -1
- package/dist/shields/formats/dotnet-managed.js.map +1 -1
- package/dist/shields/formats/electron-fuses.d.ts +63 -8
- package/dist/shields/formats/electron-fuses.d.ts.map +1 -1
- package/dist/shields/formats/electron-fuses.js +297 -65
- package/dist/shields/formats/electron-fuses.js.map +1 -1
- package/dist/shields/formats/erlang-beam.d.ts +34 -0
- package/dist/shields/formats/erlang-beam.d.ts.map +1 -0
- package/dist/shields/formats/erlang-beam.js +319 -0
- package/dist/shields/formats/erlang-beam.js.map +1 -0
- package/dist/shields/formats/evm-bytecode.d.ts +28 -0
- package/dist/shields/formats/evm-bytecode.d.ts.map +1 -0
- package/dist/shields/formats/evm-bytecode.js +124 -0
- package/dist/shields/formats/evm-bytecode.js.map +1 -0
- package/dist/shields/formats/go-flutter-exhaustion.d.ts +55 -0
- package/dist/shields/formats/go-flutter-exhaustion.d.ts.map +1 -0
- package/dist/shields/formats/go-flutter-exhaustion.js +346 -0
- package/dist/shields/formats/go-flutter-exhaustion.js.map +1 -0
- package/dist/shields/formats/gpu-ptx.d.ts +40 -0
- package/dist/shields/formats/gpu-ptx.d.ts.map +1 -0
- package/dist/shields/formats/gpu-ptx.js +62 -0
- package/dist/shields/formats/gpu-ptx.js.map +1 -0
- package/dist/shields/formats/headers.d.ts.map +1 -1
- package/dist/shields/formats/headers.js +54 -14
- package/dist/shields/formats/headers.js.map +1 -1
- package/dist/shields/formats/jvm-bytecode.d.ts +20 -0
- package/dist/shields/formats/jvm-bytecode.d.ts.map +1 -0
- package/dist/shields/formats/jvm-bytecode.js +134 -0
- package/dist/shields/formats/jvm-bytecode.js.map +1 -0
- package/dist/shields/formats/mobile-game.d.ts +4 -0
- package/dist/shields/formats/mobile-game.d.ts.map +1 -1
- package/dist/shields/formats/mobile-game.js +16 -0
- package/dist/shields/formats/mobile-game.js.map +1 -1
- package/dist/shields/formats/model.d.ts +22 -8
- package/dist/shields/formats/model.d.ts.map +1 -1
- package/dist/shields/formats/model.js +231 -59
- package/dist/shields/formats/model.js.map +1 -1
- package/dist/shields/formats/native.d.ts +65 -11
- package/dist/shields/formats/native.d.ts.map +1 -1
- package/dist/shields/formats/native.js +413 -108
- package/dist/shields/formats/native.js.map +1 -1
- package/dist/shields/formats/pcap-capture.d.ts +27 -0
- package/dist/shields/formats/pcap-capture.d.ts.map +1 -0
- package/dist/shields/formats/pcap-capture.js +201 -0
- package/dist/shields/formats/pcap-capture.js.map +1 -0
- package/dist/shields/formats/python.d.ts +22 -1
- package/dist/shields/formats/python.d.ts.map +1 -1
- package/dist/shields/formats/python.js +568 -27
- package/dist/shields/formats/python.js.map +1 -1
- package/dist/shields/formats/sourcemap.d.ts.map +1 -1
- package/dist/shields/formats/sourcemap.js +2 -0
- package/dist/shields/formats/sourcemap.js.map +1 -1
- package/dist/shields/formats/sqlite.d.ts +87 -15
- package/dist/shields/formats/sqlite.d.ts.map +1 -1
- package/dist/shields/formats/sqlite.js +377 -42
- package/dist/shields/formats/sqlite.js.map +1 -1
- package/dist/shields/formats/wasm.d.ts +6 -0
- package/dist/shields/formats/wasm.d.ts.map +1 -1
- package/dist/shields/formats/wasm.js +118 -3
- package/dist/shields/formats/wasm.js.map +1 -1
- package/dist/shields/javascript/ast-shield.d.ts +25 -5
- package/dist/shields/javascript/ast-shield.d.ts.map +1 -1
- package/dist/shields/javascript/ast-shield.js +428 -58
- package/dist/shields/javascript/ast-shield.js.map +1 -1
- package/dist/shields/runtime/memory-diff-shield.d.ts +56 -0
- package/dist/shields/runtime/memory-diff-shield.d.ts.map +1 -0
- package/dist/shields/runtime/memory-diff-shield.js +170 -0
- package/dist/shields/runtime/memory-diff-shield.js.map +1 -0
- package/dist/shields/runtime/runtime-shield.d.ts +12 -16
- package/dist/shields/runtime/runtime-shield.d.ts.map +1 -1
- package/dist/shields/runtime/runtime-shield.js +30 -24
- package/dist/shields/runtime/runtime-shield.js.map +1 -1
- package/dist/shields/tarpit/opaque-predicates.d.ts.map +1 -1
- package/dist/shields/tarpit/opaque-predicates.js +3 -3
- package/dist/shields/tarpit/opaque-predicates.js.map +1 -1
- package/dist/shields/tarpit/tarpit-generator.d.ts +9 -4
- package/dist/shields/tarpit/tarpit-generator.d.ts.map +1 -1
- package/dist/shields/tarpit/tarpit-generator.js +30 -23
- package/dist/shields/tarpit/tarpit-generator.js.map +1 -1
- 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([
|
|
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(
|
|
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
|
|
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
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
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(
|
|
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
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
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 ??
|
|
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
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
//
|
|
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), [
|
|
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 +=
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
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
|
-
|
|
567
|
+
...(options.enableRuntimeShield !== false ? [runtimeShield.code] : []),
|
|
568
|
+
tarpit.code.replace(/\bexport\s+function\s+/g, "function "),
|
|
233
569
|
exhaustionSuite.combinedJsCode,
|
|
234
|
-
|
|
235
|
-
]
|
|
236
|
-
|
|
570
|
+
deceptionWithoutDuplicateArmor,
|
|
571
|
+
];
|
|
572
|
+
const combinedInjectedAst = parse(injectedBlocks.join("\n\n"), {
|
|
573
|
+
sourceType: "script",
|
|
237
574
|
plugins: ["typescript"],
|
|
238
575
|
});
|
|
239
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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] =
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
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
|