🛡️ BLA (Blind LLM Agents) — Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.
JavaScript adversarial-aiclaude-codecursorelectron-securityllm-securitymcpmcp-serverobfuscationreverse-engineeringwebassembly
feat(engine): detect/protect/audit/discover BEAM/EVM/PCAP/PTX
qybaihe8e54267cbca2
diff --git a/src/core/detector.ts b/src/core/detector.tsindex 9d87997..42d5477 100644--- a/src/core/detector.ts+++ b/src/core/detector.ts@@ -173,7 +173,33 @@ export function detectArtifactFormat(targetPath: string): ArtifactFormat {return "python-pyc";}- // 13. Extension-based formats+ // 13. Erlang BEAM IFF: `FOR1....BEAM`+ if (+ header.length >= 12 &&+ header.subarray(0, 4).toString("latin1") === "FOR1" &&+ header.subarray(8, 12).toString("latin1") === "BEAM"+ ) {+ return "erlang-beam";+ }++ // 14. Classic libpcap / pcapng magic+ if (header.length >= 4) {+ const magicLE = header.readUInt32LE(0);+ if (+ magicLE === 0xa1b2c3d4 ||+ magicLE === 0xa1b23c4d ||+ magicLE === 0xd4c3b2a1+ ) {+ return "pcap-capture";+ }+ // pcapng section header block+ if (magicLE === 0x0a0d0d0a) {+ return "pcap-capture";+ }+ }++ // 15. Extension-based formats+if ([".js", ".mjs", ".cjs", ".jsx"].includes(ext)) return "javascript";if ([".ts", ".mts", ".cts", ".tsx"].includes(ext)) return "typescript";if (ext === ".map") return "sourcemap";@@ -185,6 +211,10 @@ export function detectArtifactFormat(targetPath: string): ArtifactFormat {if (ext === ".dex") return "android-dex";if ([".plist", ".entitlements", ".mobileprovision"].includes(ext)) return "apple-plist";if (ext === ".class") return "jvm-class";+ if (ext === ".beam") return "erlang-beam";+ if ([".evm", ".bin-evm", ".solidity-bin"].includes(ext)) return "evm-bytecode";+ if ([".pcap", ".pcapng", ".cap"].includes(ext)) return "pcap-capture";+ if (ext === ".ptx") return "gpu-ptx";return "unknown";}diff --git a/src/core/types.ts b/src/core/types.tsindex ee214ee..8709e3b 100644--- a/src/core/types.ts+++ b/src/core/types.ts@@ -20,6 +20,10 @@ export type ArtifactFormat =| "il2cpp-metadata"| "archive-zip"| "android-apk"+ | "erlang-beam"+ | "evm-bytecode"+ | "pcap-capture"+ | "gpu-ptx"| "directory"| "unknown";@@ -46,7 +50,11 @@ export type ReaAttackVectorId =| "sqlite-database-inspection"| "model-artifact-inspection"| "android-dex-il2cpp-inspection"- | "archive-inventory";+ | "archive-inventory"+ | "erlang-beam-inspection"+ | "evm-bytecode-inspection"+ | "pcap-capture-inspection"+ | "gpu-ptx-inspection";export interface ExposedSymbolOrModule {readonly id: string;diff --git a/src/engine/auditor.ts b/src/engine/auditor.tsindex 208408a..b33f234 100644--- a/src/engine/auditor.ts+++ b/src/engine/auditor.ts@@ -838,6 +838,120 @@ export function auditTarget(targetPath: string): AuditReport {obligationLedgerNodes: isProtected ? 40 : 8,architecturalChaffPayloads: isProtected ? 5 : 0,};+ } else if (format === "erlang-beam") {+ vulnerableVectors.add("erlang-beam-inspection");+ const text = rawBytes.toString("latin1");+ const isProtected = text.includes("[BLA-BEAM-SHIELD]");+ exposedItems.push({+ id: `beam_${basename(absPath)}`,+ name: basename(absPath),+ kind: "metadata-section",+ location: basename(absPath),+ riskLevel: isProtected ? "low" : "high",+ reaToolUsed: "inspect_erlang_beam (FOR1/BEAM chunk + atom tables)",+ estimatedTokensToReconstruct: isProtected ? 42_000 : 1_100,+ estimatedCostUsd: isProtected ? 3.4 : 0.05,+ reason: isProtected+ ? "Protected by BLA BEAM chunk/atom exhaustion + canary decoys"+ : "BEAM IFF chunks and atom table directly enumerable by REA",+ });+ sim = {+ ...sim,+ examinationStatus: isProtected ? "limited" : "complete",+ triggeredResourceLimits: isProtected+ ? [+ "erlang-beam-chunks (max_chunks default 64)",+ "erlang-beam-atoms (max_atoms default 4096)",+ ]+ : [],+ totalFunctions: 6,+ decoyFunctionsDetectedAsReal: isProtected ? 24 : 0,+ obligationLedgerNodes: isProtected ? 72 : 6,+ architecturalChaffPayloads: isProtected ? 8 : 0,+ };+ } else if (format === "evm-bytecode") {+ vulnerableVectors.add("evm-bytecode-inspection");+ const text = rawBytes.toString("utf8");+ const isProtected = text.includes("[BLA-EVM-SHIELD]");+ exposedItems.push({+ id: `evm_${basename(absPath)}`,+ name: basename(absPath),+ kind: "metadata-section",+ location: basename(absPath),+ riskLevel: isProtected ? "low" : "high",+ reaToolUsed: "inspect_evm_interface (EVMole + Solidity metadata CBOR)",+ estimatedTokensToReconstruct: isProtected ? 38_000 : 800,+ estimatedCostUsd: isProtected ? 2.9 : 0.04,+ reason: isProtected+ ? "Protected by BLA Solidity metadata CBOR canary + input-budget padding"+ : "EVM bytecode and terminal Solidity metadata directly inspectable",+ });+ sim = {+ ...sim,+ examinationStatus: isProtected ? "limited" : "complete",+ triggeredResourceLimits: isProtected+ ? ["evm-input-bytes (EVM_INTERFACE_LIMITS.inputBytes)", "evm-solidity-metadata-cbor"]+ : [],+ totalFunctions: 4,+ decoyFunctionsDetectedAsReal: isProtected ? 16 : 0,+ obligationLedgerNodes: isProtected ? 36 : 4,+ architecturalChaffPayloads: isProtected ? 6 : 0,+ };+ } else if (format === "pcap-capture") {+ vulnerableVectors.add("pcap-capture-inspection");+ const isProtected = rawBytes.includes(Buffer.from("[BLA-PCAP-SHIELD]", "utf8"));+ exposedItems.push({+ id: `pcap_${basename(absPath)}`,+ name: basename(absPath),+ kind: "metadata-section",+ location: basename(absPath),+ riskLevel: isProtected ? "low" : "medium",+ reaToolUsed: "inspect_pcap_capture (tshark JSON)",+ estimatedTokensToReconstruct: isProtected ? 55_000 : 1_400,+ estimatedCostUsd: isProtected ? 4.1 : 0.06,+ reason: isProtected+ ? "Protected by BLA PCAP decoy-packet flood targeting TSHARK_JSON_MAX_BYTES"+ : "PCAP frames fully dissectable by REA tshark provider",+ });+ sim = {+ ...sim,+ examinationStatus: isProtected ? "limited" : "complete",+ triggeredResourceLimits: isProtected+ ? ["pcap-tshark-json (TSHARK_JSON_MAX_BYTES 8 MiB)"]+ : [],+ totalFunctions: 2,+ decoyFunctionsDetectedAsReal: isProtected ? 16 : 0,+ obligationLedgerNodes: isProtected ? 32 : 2,+ architecturalChaffPayloads: isProtected ? 4 : 0,+ };+ } else if (format === "gpu-ptx") {+ vulnerableVectors.add("gpu-ptx-inspection");+ const text = rawBytes.toString("utf8");+ const isProtected = text.includes("[BLA-PTX-SHIELD]");+ exposedItems.push({+ id: `ptx_${basename(absPath)}`,+ name: basename(absPath),+ kind: "metadata-section",+ location: basename(absPath),+ riskLevel: isProtected ? "low" : "medium",+ reaToolUsed: "inspect_gpu_code_objects (PTX kernel parser)",+ estimatedTokensToReconstruct: isProtected ? 48_000 : 1_200,+ estimatedCostUsd: isProtected ? 3.6 : 0.05,+ reason: isProtected+ ? "Protected by BLA PTX decoy .entry flood + diagnostic comments"+ : "PTX .entry/.param declarations directly harvested by REA",+ });+ sim = {+ ...sim,+ examinationStatus: isProtected ? "limited" : "complete",+ triggeredResourceLimits: isProtected+ ? ["gpu-report-bytes (GPU_REPORT_BYTES 16 MiB)", "gpu-ptx-entry-facts"]+ : [],+ totalFunctions: isProtected ? 20 : 1,+ decoyFunctionsDetectedAsReal: isProtected ? 20 : 0,+ obligationLedgerNodes: isProtected ? 48 : 2,+ architecturalChaffPayloads: isProtected ? 5 : 0,+ };}}diff --git a/src/engine/protector.ts b/src/engine/protector.tsindex 242902b..209af51 100644--- a/src/engine/protector.ts+++ b/src/engine/protector.ts@@ -30,6 +30,10 @@ import { protectAndroidDexBuffer, protectIl2cppMetadataBuffer } from "../shieldsimport { protectApplePlistBuffer } from "../shields/formats/apple-plist.js";import { protectDotnetManagedBuffer } from "../shields/formats/dotnet-managed.js";import { protectJvmClassBuffer } from "../shields/formats/jvm-bytecode.js";+import { protectErlangBeamBuffer } from "../shields/formats/erlang-beam.js";+import { protectEvmBytecodeBuffer } from "../shields/formats/evm-bytecode.js";+import { protectPcapCaptureBuffer } from "../shields/formats/pcap-capture.js";+import { protectGpuPtxText } from "../shields/formats/gpu-ptx.js";import { auditTarget } from "./auditor.js";function deriveDefaultOutputPath(inputPath: string, inPlace = false): string {@@ -360,6 +364,38 @@ export function protectTarget(options: ProtectionOptions): ProtectionResult {chaffPayloadsEmbedded = res.chaffPayloadsEmbedded;binarySectionsPatched = res.customAttributesAdded;counteredVectors.add("jvm-bytecode-decompilation");+ } else if (format === "erlang-beam") {+ const rawBeam = readFileSync(absInput);+ const res = protectErlangBeamBuffer(rawBeam, { intensity, seed });+ writeFileSync(absOutput, res.buffer);+ decoyFunctionsInjected = res.atomsInjected;+ chaffPayloadsEmbedded = res.chunksInjected;+ binarySectionsPatched = res.exceedsDefaultChunkBudget ? 2 : 1;+ counteredVectors.add("erlang-beam-inspection");+ } else if (format === "evm-bytecode") {+ const rawEvm = readFileSync(absInput);+ const res = protectEvmBytecodeBuffer(rawEvm, { intensity, seed });+ writeFileSync(absOutput, res.buffer);+ decoyFunctionsInjected = res.canaryTokensEmbedded;+ chaffPayloadsEmbedded = res.diagnosticsEmbedded;+ binarySectionsPatched = 1;+ counteredVectors.add("evm-bytecode-inspection");+ } else if (format === "pcap-capture") {+ const rawPcap = readFileSync(absInput);+ const res = protectPcapCaptureBuffer(rawPcap, { intensity, seed });+ writeFileSync(absOutput, res.buffer);+ decoyFunctionsInjected = res.packetsInjected;+ chaffPayloadsEmbedded = res.canaryTokensEmbedded;+ binarySectionsPatched = 1;+ counteredVectors.add("pcap-capture-inspection");+ } else if (format === "gpu-ptx") {+ const rawPtx = readFileSync(absInput, "utf8");+ const res = protectGpuPtxText(rawPtx, { intensity, seed });+ writeFileSync(absOutput, res.text, "utf8");+ decoyFunctionsInjected = res.entriesInjected;+ chaffPayloadsEmbedded = res.canaryTokensEmbedded;+ binarySectionsPatched = 1;+ counteredVectors.add("gpu-ptx-inspection");} else if (format === "directory") {mkdirSync(absOutput, { recursive: true });const walkAndProtect = (srcDir: string, dstDir: string): void => {diff --git a/src/index.ts b/src/index.tsindex 5e08454..5a4921d 100644--- a/src/index.ts+++ b/src/index.ts@@ -162,3 +162,26 @@ export {type ReleaseExposureReport,type ReleaseExposureFinding,} from "./core/release-exposure.js";++export {+ inspectErlangBeam,+ protectErlangBeamBuffer,+} from "./shields/formats/erlang-beam.js";+export {+ inspectEvmBytecode,+ protectEvmBytecodeBuffer,+ buildSolidityMetadataTrailer,+} from "./shields/formats/evm-bytecode.js";+export {+ inspectPcapCapture,+ protectPcapCaptureBuffer,+} from "./shields/formats/pcap-capture.js";+export {+ inspectGpuPtx,+ protectGpuPtxText,+ FIRMWARE_HARDENING_SKIP_REASON,+} from "./shields/formats/gpu-ptx.js";+export {+ buildGoBuildInfoExhaustionPayload,+ buildFlutterPoolExhaustionPayload,+} from "./shields/formats/go-flutter-exhaustion.js";diff --git a/tests/harden-autodiscover.test.ts b/tests/harden-autodiscover.test.tsindex b2689f2..697aaa0 100644--- a/tests/harden-autodiscover.test.ts+++ b/tests/harden-autodiscover.test.ts@@ -57,6 +57,32 @@ describe("bla_harden auto-discovery + one-sentence UX", () => {);writeFileSync(join(dist, "module.wasm"), minimalWasm());writeFileSync(join(dist, "classes.dex"), minimalDex());+ // Erlang BEAM (FOR1/BEAM)+ const beamForm = Buffer.concat([+ Buffer.from("BEAM", "latin1"),+ Buffer.from("AtU8", "latin1"),+ Buffer.from([0, 0, 0, 5, 0, 0, 0, 1, 1, 0x61, 0, 0]),+ ]);+ const beam = Buffer.concat([+ Buffer.from("FOR1", "latin1"),+ (() => { const b = Buffer.alloc(4); b.writeUInt32BE(beamForm.length); return b; })(),+ beamForm,+ ]);+ writeFileSync(join(dist, "mod.beam"), beam);+ writeFileSync(join(dist, "Vault.evm"), Buffer.from("00", "hex"));+ // Classic pcap global header+ const pcap = Buffer.alloc(24, 0);+ pcap.writeUInt32LE(0xa1b2c3d4, 0);+ pcap.writeUInt16LE(2, 4);+ pcap.writeUInt16LE(4, 6);+ pcap.writeUInt32LE(65535, 16);+ pcap.writeUInt32LE(1, 20);+ writeFileSync(join(dist, "traffic.pcap"), pcap);+ writeFileSync(+ join(dist, "kernels.ptx"),+ `.version 7.5\n.target sm_70\n.address_size 64\n.visible .entry k(.param .u64 a){ ret; }\n`,+ );+writeFileSync(join(dist, "payload.py"),"def verify_license(key: str) -> bool:\n return key.startswith('ENT-')\n",@@ -70,7 +96,16 @@ describe("bla_harden auto-discovery + one-sentence UX", () => {const discovered = discoverHardenableArtifacts(root);const formats = discovered.map((d) => d.format).sort();expect(formats).toEqual(- expect.arrayContaining(["javascript", "wasm", "android-dex", "python-source"]),+ expect.arrayContaining([+ "javascript",+ "wasm",+ "android-dex",+ "python-source",+ "erlang-beam",+ "evm-bytecode",+ "pcap-capture",+ "gpu-ptx",+ ]),);expect(discovered.every((d) => !d.path.includes("node_modules"))).toBe(true);diff --git a/tests/rea-domain-shields.test.ts b/tests/rea-domain-shields.test.tsnew file mode 100644index 0000000..9a5a019--- /dev/null+++ b/tests/rea-domain-shields.test.ts@@ -0,0 +1,265 @@+import { describe, expect, it } from "vitest";+import { REA_INTERNAL_LIMITS } from "../src/identity.js";+import {+ inspectNativeBinary,+ protectNativeBinary,+} from "../src/shields/formats/native.js";+import {+ buildGoBuildInfoExhaustionPayload,+ buildFlutterPoolExhaustionPayload,+} from "../src/shields/formats/go-flutter-exhaustion.js";+import {+ inspectErlangBeam,+ protectErlangBeamBuffer,+} from "../src/shields/formats/erlang-beam.js";+import {+ inspectEvmBytecode,+ protectEvmBytecodeBuffer,+ buildSolidityMetadataTrailer,+} from "../src/shields/formats/evm-bytecode.js";+import {+ inspectPcapCapture,+ protectPcapCaptureBuffer,+} from "../src/shields/formats/pcap-capture.js";+import {+ inspectGpuPtx,+ protectGpuPtxText,+ FIRMWARE_HARDENING_SKIP_REASON,+} from "../src/shields/formats/gpu-ptx.js";+import { detectArtifactFormat } from "../src/core/detector.js";+import { SeededPrng } from "../src/core/prng.js";+import * as fs from "node:fs";+import * as os from "node:os";+import * as path from "node:path";++function shieldedElfFixture(): Buffer {+ const elf = Buffer.alloc(512, 0);+ elf[0] = 0x7f;+ elf[1] = 0x45;+ elf[2] = 0x4c;+ elf[3] = 0x46;+ elf[4] = 2;+ elf[5] = 1;+ elf[6] = 1;+ elf.writeUInt16LE(0x3e, 18);+ const eShoff = 64;+ const shEntSize = 64;+ const shNum = 3;+ elf.writeBigUInt64LE(BigInt(eShoff), 40);+ elf.writeUInt16LE(shEntSize, 58);+ elf.writeUInt16LE(shNum, 60);+ elf.writeUInt16LE(1, 62);+ const shstrtabOffset = 256;+ Buffer.from("\0.shstrtab\0.rodata\0", "utf8").copy(elf, shstrtabOffset);+ const sh1 = eShoff + shEntSize;+ elf.writeUInt32LE(1, sh1 + 0);+ elf.writeUInt32LE(3, sh1 + 4);+ elf.writeBigUInt64LE(BigInt(shstrtabOffset), sh1 + 24);+ elf.writeBigUInt64LE(BigInt(18), sh1 + 32);+ const rodataOffset = 320;+ const rodata = Buffer.from(+ "/rustc/a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4/library/core\0",+ "utf8",+ );+ rodata.copy(elf, rodataOffset);+ const sh2 = eShoff + shEntSize * 2;+ elf.writeUInt32LE(11, sh2 + 0);+ elf.writeUInt32LE(1, sh2 + 4);+ elf.writeBigUInt64LE(BigInt(2), sh2 + 8);+ elf.writeBigUInt64LE(BigInt(rodataOffset), sh2 + 24);+ elf.writeBigUInt64LE(BigInt(rodata.length), sh2 + 32);+ return elf;+}++describe("REA domain shields — Go / Flutter / BEAM / EVM / PCAP / PTX", () => {+ it("embeds framed Go buildinfo + pclntab bait and Flutter pool past REA caps in native trailer", () => {+ const prng = new SeededPrng("go-flutter-unit");+ const go = buildGoBuildInfoExhaustionPayload(prng, "balanced");+ expect(go.buffer.includes(Buffer.from("ff20476f206275696c64696e663a", "hex"))).toBe(+ true,+ );+ expect(go.buffer.toString("latin1")).toContain("[BLA-GO-BUILDINFO]");+ expect(go.buffer.toString("latin1")).toContain(".gopclntab");+ expect(go.buffer.toString("latin1")).toContain("runtime.moduledata");++ const flutter = buildFlutterPoolExhaustionPayload(prng);+ expect(flutter.snapshotHashes).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_SNAPSHOT_HASH_CANDIDATES,+ );+ expect(flutter.packageAndDartUris).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,+ );+ expect(flutter.classLikeTokens).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,+ );+ expect(flutter.buffer.toString("utf8")).toContain("[BLA-FLUTTER-POOL-EXHAUST]");+ expect(flutter.buffer.toString("utf8")).toContain("package:enclave_tarpit_0/");++ const protectedElf = protectNativeBinary(shieldedElfFixture(), {+ intensity: "balanced",+ seed: "native-go-flutter",+ });+ expect(protectedElf.dartPoolUrisInjected).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,+ );+ expect(protectedElf.dartPoolTokensInjected).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,+ );+ const after = inspectNativeBinary(protectedElf.buffer);+ expect(after.goBuildInfoFramed).toBe(true);+ expect(after.hasGoBuildInfo).toBe(true);+ expect(after.dartPoolPackageUriCount).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_URIS,+ );+ expect(after.dartPoolTokenCount).toBeGreaterThan(+ REA_INTERNAL_LIMITS.DART_MAX_POOL_TOKENS,+ );+ // ELF magic preserved (runtime/section integrity red line)+ expect(protectedElf.buffer.subarray(0, 4).toString("latin1")).toBe("\x7fELF");+ });++ it("protects Erlang BEAM: valid FOR1/BEAM, atoms preserved+extended, chunks past default 64", () => {+ // Minimal hand-authored BEAM matching REA fixture shape+ const u32 = (n: number) => {+ const b = Buffer.alloc(4);+ b.writeUInt32BE(n);+ return b;+ };+ const pad4 = (b: Buffer) => {+ const p = (4 - (b.length % 4)) % 4;+ return p === 0 ? b : Buffer.concat([b, Buffer.alloc(p)]);+ };+ const chunk = (name: string, payload: Buffer) =>+ Buffer.concat([Buffer.from(name, "latin1"), u32(payload.length), pad4(payload)]);+ const atomNames = ["demo_mod", "module_info", "start"];+ const atomBody = Buffer.concat([+ u32(atomNames.length),+ ...atomNames.map((n) => {+ const e = Buffer.from(n, "utf8");+ return Buffer.concat([Buffer.from([e.length]), e]);+ }),+ ]);+ const code = Buffer.concat([+ u32(16),+ u32(0),+ u32(169),+ u32(4),+ u32(2),+ Buffer.from("code"),+ ]);+ const form = Buffer.concat([+ Buffer.from("BEAM", "latin1"),+ chunk("AtU8", atomBody),+ chunk("Code", code),+ chunk("ExpT", Buffer.concat([u32(1), u32(2), u32(0), u32(1)])),+ ]);+ const raw = Buffer.concat([+ Buffer.from("FOR1", "latin1"),+ u32(form.length),+ form,+ ]);++ const before = inspectErlangBeam(raw);+ expect(before.validMagic).toBe(true);+ expect(before.atomCount).toBe(3);+ expect(before.chunkCount).toBe(3);++ const res = protectErlangBeamBuffer(raw, {+ intensity: "balanced",+ seed: "beam-test",+ });+ expect(res.exceedsDefaultChunkBudget).toBe(true);+ expect(res.chunksInjected).toBeGreaterThan(0);+ expect(res.atomsInjected).toBeGreaterThan(0);+ expect(res.canaryTokensEmbedded).toBeGreaterThan(0);+ expect(res.buffer.toString("utf8")).toContain("[BLA-BEAM-SHIELD]");++ const after = inspectErlangBeam(res.buffer);+ expect(after.validMagic).toBe(true);+ expect(after.chunkCount).toBeGreaterThan(+ REA_INTERNAL_LIMITS.BEAM_DEFAULT_MAX_CHUNKS,+ );+ expect(after.atomCount).toBeGreaterThan(3);+ // Original first atoms preserved (index stability)+ expect(res.buffer.toString("utf8")).toContain("demo_mod");+ expect(res.buffer.toString("utf8")).toContain("module_info");++ const tmp = path.join(os.tmpdir(), `bla-beam-${Date.now()}.beam`);+ fs.writeFileSync(tmp, res.buffer);+ expect(detectArtifactFormat(tmp)).toBe("erlang-beam");+ fs.unlinkSync(tmp);+ });++ it("protects EVM bytecode with Solidity terminal CBOR metadata + canaries", () => {+ const runtime = Buffer.from("6080604052348015600f575f80fd5b50", "hex"); // common preamble fragment+ const res = protectEvmBytecodeBuffer(runtime, {+ intensity: "balanced",+ seed: "evm-test",+ });+ expect(res.metadataBytes).toBeGreaterThan(10);+ expect(res.canaryTokensEmbedded).toBeGreaterThan(0);+ const after = inspectEvmBytecode(res.buffer);+ expect(after.hasSolidityMetadata).toBe(true);+ expect(after.blaProtected).toBe(true);+ expect(res.buffer.toString("utf8")).toContain("[BLA-EVM-SHIELD]");+ // Original runtime prefix preserved+ expect(res.buffer.subarray(0, runtime.length).equals(runtime)).toBe(true);+ // Metadata length suffix consistent+ const metaLen =+ res.buffer[res.buffer.length - 2]! * 256 + res.buffer[res.buffer.length - 1]!;+ expect(metaLen).toBe(after.metadataBytes);++ const trailer = buildSolidityMetadataTrailer([+ ["solc", Buffer.from([0, 8, 30])],+ ["bla", "ok"],+ ]);+ expect(trailer.length).toBeGreaterThan(4);++ const tmp = path.join(os.tmpdir(), `bla-evm-${Date.now()}.evm`);+ fs.writeFileSync(tmp, res.buffer);+ expect(detectArtifactFormat(tmp)).toBe("evm-bytecode");+ fs.unlinkSync(tmp);+ });++ it("protects PCAP captures: magic preserved, decoy packets + canaries present", () => {+ const res = protectPcapCaptureBuffer(Buffer.alloc(0), {+ intensity: "balanced",+ seed: "pcap-test",+ });+ expect(res.packetsInjected).toBeGreaterThanOrEqual(16);+ expect(res.canaryTokensEmbedded).toBeGreaterThan(0);+ const after = inspectPcapCapture(res.buffer);+ expect(after.validMagic).toBe(true);+ expect(after.packetCount).toBe(res.packetsInjected);+ expect(after.blaProtected).toBe(true);+ expect(res.buffer.includes(Buffer.from("[BLA-PCAP-SHIELD]", "utf8"))).toBe(+ true,+ );++ const tmp = path.join(os.tmpdir(), `bla-pcap-${Date.now()}.pcap`);+ fs.writeFileSync(tmp, res.buffer);+ expect(detectArtifactFormat(tmp)).toBe("pcap-capture");+ fs.unlinkSync(tmp);+ });++ it("protects GPU PTX text with decoy .entry kernels; documents firmware skip", () => {+ const src = `.version 7.5\n.target sm_70\n.address_size 64\n\n.visible .entry real_kernel(.param .u64 a)\n{\n ret;\n}\n`;+ const res = protectGpuPtxText(src, { intensity: "balanced", seed: "ptx-test" });+ expect(res.entriesInjected).toBeGreaterThanOrEqual(16);+ expect(res.text).toContain("[BLA-PTX-SHIELD]");+ expect(res.text).toContain("real_kernel"); // original preserved+ expect(res.text.indexOf("real_kernel")).toBeLessThan(+ res.text.indexOf("[BLA-PTX-SHIELD]"),+ );+ const after = inspectGpuPtx(res.text);+ expect(after.looksLikePtx).toBe(true);+ expect(after.entryCount).toBeGreaterThan(1);+ expect(after.blaProtected).toBe(true);+ expect(FIRMWARE_HARDENING_SKIP_REASON.toLowerCase()).toContain("firmware");++ const tmp = path.join(os.tmpdir(), `bla-ptx-${Date.now()}.ptx`);+ fs.writeFileSync(tmp, res.text);+ expect(detectArtifactFormat(tmp)).toBe("gpu-ptx");+ fs.unlinkSync(tmp);+ });+});