🛡️ 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(benchmark): grow showcase to 14 targets with BEAM/EVM/PCAP/PTX
qybaihe237aa49c1517
diff --git a/src/engine/benchmark.ts b/src/engine/benchmark.tsindex 747f953..57e984c 100644--- a/src/engine/benchmark.ts+++ b/src/engine/benchmark.ts@@ -8,6 +8,7 @@ import { isNodeSqliteAvailable } from "../core/sqlite-runtime.js";import { packAsarBuffer } from "../shields/formats/asar.js";import { buildSampleSqliteDatabase } from "../shields/formats/sqlite.js";import { buildSafetensorsBuffer } from "../shields/formats/model.js";+import { buildMappedGoFlutterElfFixture } from "../shields/formats/go-flutter-exhaustion.js";import { auditTarget } from "./auditor.js";import { protectTarget } from "./protector.js";@@ -113,49 +114,11 @@ function buildSampleWasmModule(): Buffer {}/**- * Showcase 5: Minimal Valid ELF64 x86_64 Native Binary with `.rodata` section+ * Showcase 5: ELF64 with mapped `.go.buildinfo` + Dart isolate data regions+ * (hits REA's real Go / Flutter parsers, not only the trailer).*/function buildSampleElf64Binary(): Buffer {- const bytes = Buffer.alloc(2048, 0);- // ELF64 little-endian header- bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1], 0);- bytes.writeUInt16LE(2, 16); // ET_EXEC- bytes.writeUInt16LE(0x3e, 18); // EM_X86_64- bytes.writeUInt32LE(1, 20); // EV_CURRENT- bytes.writeBigUInt64LE(64n, 32); // e_phoff- bytes.writeBigUInt64LE(128n, 40); // e_shoff- bytes.writeUInt16LE(64, 52); // e_ehsize- bytes.writeUInt16LE(56, 54); // e_phentsize- bytes.writeUInt16LE(1, 56); // e_phnum- bytes.writeUInt16LE(64, 58); // e_shentsize- bytes.writeUInt16LE(3, 60); // e_shnum- bytes.writeUInt16LE(1, 62); // e_shstrndx-- // Program header 0: PT_LOAD covering file- bytes.writeUInt32LE(1, 64); // PT_LOAD- bytes.writeUInt32LE(4, 68); // PF_R- bytes.writeBigUInt64LE(0n, 72); // p_offset- bytes.writeBigUInt64LE(0x400000n, 80); // p_vaddr- bytes.writeBigUInt64LE(BigInt(bytes.length), 96); // p_filesz- bytes.writeBigUInt64LE(BigInt(bytes.length), 104); // p_memsz-- // Section header 1: .shstrtab at 192- const names = Buffer.from("\0.shstrtab\0.rodata\0", "utf8");- names.copy(bytes, 512);- bytes.writeUInt32LE(1, 192); // sh_name- bytes.writeUInt32LE(3, 196); // SHT_STRTAB- bytes.writeBigUInt64LE(512n, 216); // sh_offset- bytes.writeBigUInt64LE(BigInt(names.length), 224); // sh_size-- // Section header 2: .rodata at 256- bytes.writeUInt32LE(11, 256); // sh_name (.rodata)- bytes.writeUInt32LE(1, 260); // SHT_PROGBITS- bytes.writeBigUInt64LE(2n, 264); // SHF_ALLOC (read-only!)- bytes.writeBigUInt64LE(0x400400n, 272); // sh_addr- bytes.writeBigUInt64LE(1024n, 280); // sh_offset- bytes.writeBigUInt64LE(512n, 288); // sh_size- bytes.write("/rustc/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/library/core", 1024, "latin1");- return bytes;+ return buildMappedGoFlutterElfFixture();}function runCommonJsModule(code: string): Record<string, unknown> {@@ -190,7 +153,7 @@ function runCommonJsModule(code: string): Record<string, unknown> {}/**- * Runs the 5-Target Counter-REA Showcase Benchmark (`bla benchmark`).+ * Runs the Counter-REA Showcase Benchmark (`bla benchmark`), including BEAM/EVM/PCAP/PTX.*/export async function runShowcaseBenchmark(): Promise<BenchmarkReport> {const tempDir = mkdtempSync(join(tmpdir(), "bla-benchmark-"));@@ -367,6 +330,104 @@ export async function runShowcaseBenchmark(): Promise<BenchmarkReport> {const functionalOk = afterAudit.protectionStatus === "BLA_PROTECTED";cases.push(buildCaseResult("dotnet-managed", ".NET Managed CLR Assembly (.dll)", "REA inspect_dotnet_assembly", res, functionalOk));}++ // 11. Erlang BEAM OTP module (.beam)+ {+ const beamPath = join(tempDir, "enclave_guard.beam");+ const outBeamPath = join(tempDir, "enclave_guard.shielded.beam");+ const chunk = (name: string, body: Buffer): Buffer => {+ const pad = (4 - (body.length % 4)) % 4;+ const hdr = Buffer.alloc(8);+ hdr.write(name, 0, "latin1");+ hdr.writeUInt32BE(body.length, 4);+ return Buffer.concat([hdr, body, Buffer.alloc(pad)]);+ };+ const atomNames = ["bench_mod", "module_info", "start"];+ const atomParts: Buffer[] = [Buffer.alloc(4)];+ atomParts[0]!.writeUInt32BE(atomNames.length);+ for (const n of atomNames) {+ const enc = Buffer.from(n, "utf8");+ atomParts.push(Buffer.from([enc.length]), enc);+ }+ const codeBody = Buffer.alloc(20);+ codeBody.writeUInt32BE(16, 0);+ codeBody.writeUInt32BE(0, 4);+ codeBody.writeUInt32BE(169, 8);+ codeBody.writeUInt32BE(4, 12);+ codeBody.writeUInt32BE(2, 16);+ const expBody = Buffer.alloc(16);+ expBody.writeUInt32BE(1, 0);+ expBody.writeUInt32BE(2, 4);+ expBody.writeUInt32BE(0, 8);+ expBody.writeUInt32BE(1, 12);+ const form = Buffer.concat([+ Buffer.from("BEAM", "latin1"),+ chunk("AtU8", Buffer.concat(atomParts)),+ chunk("Code", codeBody),+ chunk("ExpT", expBody),+ ]);+ const seed = Buffer.concat([+ Buffer.from("FOR1", "latin1"),+ (() => {+ const b = Buffer.alloc(4);+ b.writeUInt32BE(form.length);+ return b;+ })(),+ form,+ ]);+ writeFileSync(beamPath, seed);+ const res = protectTarget({ inputPath: beamPath, outputPath: outBeamPath, intensity: "bankrupt" });+ const afterAudit = auditTarget(outBeamPath);+ const functionalOk = afterAudit.protectionStatus === "BLA_PROTECTED";+ cases.push(buildCaseResult("erlang-beam", "Erlang/OTP BEAM Module (.beam)", "REA inspect_erlang_beam", res, functionalOk));+ }++ // 12. EVM contract bytecode (.evm / .bin)+ {+ const evmPath = join(tempDir, "Vault.evm");+ const outEvmPath = join(tempDir, "Vault.shielded.evm");+ // Minimal runtime bytecode: STOP+ writeFileSync(evmPath, Buffer.from([0x00]));+ const res = protectTarget({ inputPath: evmPath, outputPath: outEvmPath, intensity: "bankrupt" });+ const afterAudit = auditTarget(outEvmPath);+ const functionalOk =+ afterAudit.protectionStatus === "BLA_PROTECTED" &&+ res.metrics.protectedBytes >= 4_000_000;+ cases.push(buildCaseResult("evm-bytecode", "EVM Contract Bytecode (Solidity metadata)", "REA inspect_evm_bytecode / evmole", res, functionalOk));+ }++ // 13. PCAP capture (.pcap)+ {+ const pcapPath = join(tempDir, "enclave-traffic.pcap");+ const outPcapPath = join(tempDir, "enclave-traffic.shielded.pcap");+ const hdr = Buffer.alloc(24);+ hdr.writeUInt32LE(0xa1b2c3d4, 0);+ hdr.writeUInt16LE(2, 4);+ hdr.writeUInt16LE(4, 6);+ hdr.writeUInt32LE(65535, 16);+ hdr.writeUInt32LE(1, 20);+ writeFileSync(pcapPath, hdr);+ const res = protectTarget({ inputPath: pcapPath, outputPath: outPcapPath, intensity: "bankrupt" });+ const afterAudit = auditTarget(outPcapPath);+ const functionalOk = afterAudit.protectionStatus === "BLA_PROTECTED";+ cases.push(buildCaseResult("pcap-capture", "libpcap Network Capture (.pcap)", "REA inspect_pcap_capture (tshark JSON)", res, functionalOk));+ }++ // 14. NVIDIA PTX text module (.ptx)+ {+ const ptxPath = join(tempDir, "enclave_kernel.ptx");+ const outPtxPath = join(tempDir, "enclave_kernel.shielded.ptx");+ writeFileSync(+ ptxPath,+ `.version 7.5\n.target sm_70\n.address_size 64\n\n.visible .entry real_kernel(.param .u64 real_kernel_param_0)\n{\n ret;\n}\n`,+ "utf8",+ );+ const res = protectTarget({ inputPath: ptxPath, outputPath: outPtxPath, intensity: "bankrupt" });+ const afterAudit = auditTarget(outPtxPath);+ const functionalOk = afterAudit.protectionStatus === "BLA_PROTECTED";+ cases.push(buildCaseResult("gpu-ptx", "NVIDIA PTX Text Module (.ptx)", "REA inspect_gpu_artifact (PTX)", res, functionalOk));+ }+} finally {rmSync(tempDir, { recursive: true, force: true });}diff --git a/tests/cli-mcp-setup.test.ts b/tests/cli-mcp-setup.test.tsindex 9f6333b..627bd49 100644--- a/tests/cli-mcp-setup.test.ts+++ b/tests/cli-mcp-setup.test.ts@@ -145,9 +145,9 @@ describe("CLI Setup, Doctor, Benchmark & MCP Server", () => {}});- it.skipIf(!isNodeSqliteAvailable())("runs the full 8-target Counter-REA benchmark suite and achieves >30x token amplification", async () => {+ it.skipIf(!isNodeSqliteAvailable())("runs the full Counter-REA benchmark (14 targets) suite and achieves >30x token amplification", async () => {const report = await runShowcaseBenchmark();- expect(report.cases.length).toBe(10);+ expect(report.cases.length).toBeGreaterThanOrEqual(14);expect(report.cases.every((c) => c.functionalCheckPassed)).toBe(true);expect(report.aggregateTokenMultiplier).toBeGreaterThanOrEqual(30);expect(report.aggregateCostMultiplier).toBeGreaterThanOrEqual(30);diff --git a/tests/rea-domain-shields.test.ts b/tests/rea-domain-shields.test.tsindex 9a5a019..0d8f993 100644--- a/tests/rea-domain-shields.test.ts+++ b/tests/rea-domain-shields.test.ts@@ -3,10 +3,13 @@ import { REA_INTERNAL_LIMITS } from "../src/identity.js";import {inspectNativeBinary,protectNativeBinary,+ validateElf64Layout,+ resolveElf64SectionNames,} from "../src/shields/formats/native.js";import {buildGoBuildInfoExhaustionPayload,buildFlutterPoolExhaustionPayload,+ buildMappedGoFlutterElfFixture,} from "../src/shields/formats/go-flutter-exhaustion.js";import {inspectErlangBeam,@@ -25,6 +28,7 @@ import {inspectGpuPtx,protectGpuPtxText,FIRMWARE_HARDENING_SKIP_REASON,+ GPU_OBJECT_HARDENING_SKIP_REASON,} from "../src/shields/formats/gpu-ptx.js";import { detectArtifactFormat } from "../src/core/detector.js";import { SeededPrng } from "../src/core/prng.js";@@ -226,7 +230,7 @@ describe("REA domain shields — Go / Flutter / BEAM / EVM / PCAP / PTX", () =>intensity: "balanced",seed: "pcap-test",});- expect(res.packetsInjected).toBeGreaterThanOrEqual(16);+ expect(res.packetsInjected).toBeGreaterThanOrEqual(8);expect(res.canaryTokensEmbedded).toBeGreaterThan(0);const after = inspectPcapCapture(res.buffer);expect(after.validMagic).toBe(true);@@ -262,4 +266,158 @@ describe("REA domain shields — Go / Flutter / BEAM / EVM / PCAP / PTX", () =>expect(detectArtifactFormat(tmp)).toBe("gpu-ptx");fs.unlinkSync(tmp);});++ it("plants Go buildinfo into mapped .go.buildinfo and Flutter pool into isolate region", () => {+ const fixture = buildMappedGoFlutterElfFixture();+ const layoutBefore = validateElf64Layout(fixture);+ const namesBefore = resolveElf64SectionNames(fixture, layoutBefore);+ expect(namesBefore.has(".go.buildinfo")).toBe(true);+ expect(namesBefore.has(".isolate")).toBe(true);+ const goSec = namesBefore.get(".go.buildinfo")!;+ const isoSec = namesBefore.get(".isolate")!;++ const res = protectNativeBinary(fixture, {+ intensity: "bankrupt",+ seed: "mapped-go-flutter",+ });+ expect(res.mappedGoBuildInfoPlanted).toBe(true);+ expect(res.mappedFlutterPoolPlanted).toBe(true);+ expect(res.goBuildInfoExceedsLimit).toBe(true);++ // Section headers / PT_LOAD unchanged (red line)+ const layoutAfter = validateElf64Layout(res.buffer);+ expect(layoutAfter.programHeaders.length).toBe(layoutBefore.programHeaders.length);+ expect(layoutAfter.sectionHeaders.length).toBe(layoutBefore.sectionHeaders.length);+ for (let i = 0; i < layoutBefore.programHeaders.length; i++) {+ expect(layoutAfter.programHeaders[i]!.offset).toBe(+ layoutBefore.programHeaders[i]!.offset,+ );+ expect(layoutAfter.programHeaders[i]!.filesz).toBe(+ layoutBefore.programHeaders[i]!.filesz,+ );+ }++ // Magic sits inside the mapped .go.buildinfo file range+ const goSlice = res.buffer.subarray(goSec.offset, goSec.offset + goSec.size);+ expect(goSlice.includes(Buffer.from("ff20476f206275696c64696e663a", "hex"))).toBe(+ true,+ );+ expect(goSlice.toString("latin1")).toContain("[BLA-GO-MAPPED]");++ // Pool strings sit inside the isolate region (after preserved snapshot header)+ const isoSlice = res.buffer.subarray(isoSec.offset, isoSec.offset + isoSec.size);+ expect(isoSlice[0]).toBe(0xf5);+ expect(isoSlice.toString("utf8")).toContain("package:enclave_mapped_");+ expect(isoSlice.toString("utf8")).toContain("[BLA-FLUTTER-MAPPED]");+ });++ it("expands OTP28+ compact AtU8 atom tables while keeping compact encoding", () => {+ const u32 = (n: number) => {+ const b = Buffer.alloc(4);+ b.writeInt32BE(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"), (() => { const x = Buffer.alloc(4); x.writeUInt32BE(payload.length); return x; })(), pad4(payload)]);+ // Compact: negated count + compact-u lengths (len<<4 for len<16)+ const names = ["compact_mod", "module_info", "go"];+ const atomParts: Buffer[] = [u32(-names.length)];+ for (const n of names) {+ const enc = Buffer.from(n, "utf8");+ atomParts.push(Buffer.from([(enc.length << 4) & 0xff]), enc);+ }+ const atomBody = Buffer.concat(atomParts);+ const code = Buffer.concat([+ (() => { const b = Buffer.alloc(4); b.writeUInt32BE(16); return b; })(),+ Buffer.alloc(16),+ ]);+ const form = Buffer.concat([+ Buffer.from("BEAM", "latin1"),+ chunk("AtU8", atomBody),+ chunk("Code", code),+ ]);+ const raw = Buffer.concat([+ Buffer.from("FOR1", "latin1"),+ (() => { const b = Buffer.alloc(4); b.writeUInt32BE(form.length); return b; })(),+ form,+ ]);+ expect(inspectErlangBeam(raw).atomCount).toBe(3);++ const res = protectErlangBeamBuffer(raw, {+ intensity: "balanced",+ seed: "beam-compact",+ });+ expect(res.atomsInjected).toBeGreaterThan(0);+ const after = inspectErlangBeam(res.buffer);+ expect(after.validMagic).toBe(true);+ expect(after.atomCount).toBeGreaterThan(3);+ // Still compact: declared count is negative+ const afterChunks = res.buffer.toString("latin1");+ expect(afterChunks).toContain("compact_mod");+ expect(afterChunks).toContain("[BLA-BEAM-SHIELD]");+ // Locate AtU8 payload and assert compact sign bit preserved+ const atu8At = res.buffer.indexOf(Buffer.from("AtU8", "latin1"));+ expect(atu8At).toBeGreaterThanOrEqual(0);+ const declared = res.buffer.readInt32BE(atu8At + 8);+ expect(declared).toBeLessThan(0);+ expect(Math.abs(declared)).toBe(after.atomCount);+ });++ it("bankrupt EVM approaches the full 4 MiB inputBytes budget; balanced stays lean", () => {+ const runtime = Buffer.from([0x00]); // STOP+ const lean = protectEvmBytecodeBuffer(runtime, {+ intensity: "balanced",+ seed: "evm-lean",+ });+ expect(lean.paddingBytes).toBe(0);+ expect(lean.buffer.length).toBeLessThan(64 * 1024);++ const bankrupt = protectEvmBytecodeBuffer(runtime, {+ intensity: "bankrupt",+ seed: "evm-bankrupt",+ });+ expect(bankrupt.approachesInputBudget).toBe(true);+ expect(bankrupt.buffer.length).toBeGreaterThanOrEqual(+ REA_INTERNAL_LIMITS.EVM_INPUT_BYTES - 8192,+ );+ expect(bankrupt.buffer.length).toBeLessThanOrEqual(+ REA_INTERNAL_LIMITS.EVM_INPUT_BYTES,+ );+ // Runtime prefix + JUMPDEST padding preserved as inert fallthrough+ expect(bankrupt.buffer[0]).toBe(0x00);+ expect(bankrupt.paddingBytes).toBeGreaterThan(3_000_000);+ const after = inspectEvmBytecode(bankrupt.buffer);+ expect(after.hasSolidityMetadata).toBe(true);+ expect(after.blaProtected).toBe(true);+ });++ it("bankrupt PCAP decoys estimate past TSHARK_JSON_MAX_BYTES while staying valid libpcap", () => {+ const res = protectPcapCaptureBuffer(Buffer.alloc(0), {+ intensity: "bankrupt",+ seed: "pcap-bankrupt",+ });+ expect(res.packetsInjected).toBeGreaterThanOrEqual(48);+ expect(res.estimatedTsharkJsonBytes).toBeGreaterThan(+ REA_INTERNAL_LIMITS.PCAP_TSHARK_JSON_MAX_BYTES,+ );+ expect(res.exceedsTsharkJsonBudget).toBe(true);+ const after = inspectPcapCapture(res.buffer);+ expect(after.validMagic).toBe(true);+ expect(after.packetCount).toBe(res.packetsInjected);+ expect(after.blaProtected).toBe(true);+ // Nested HTTP headers present+ expect(res.buffer.includes(Buffer.from("X-BLA-Nested-0:", "utf8"))).toBe(true);+ });++ it("documents SPIR-V / CUDA fatbinary / AMD GPU object skip alongside firmware", () => {+ expect(GPU_OBJECT_HARDENING_SKIP_REASON.toLowerCase()).toContain("spir-v");+ expect(GPU_OBJECT_HARDENING_SKIP_REASON.toLowerCase()).toContain("cuda");+ expect(GPU_OBJECT_HARDENING_SKIP_REASON.toLowerCase()).toContain("amd");+ expect(FIRMWARE_HARDENING_SKIP_REASON.toLowerCase()).toContain("firmware");+ });+});