Skip to content

armgit / bla

Public Imported from GitHub
0

πŸ›‘οΈ 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.

feat(android,manifest): counter REA #7379/#7818 with AndroidManifest component decoys (v1.4.9)

qybaihee5a566a3f544
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58c3a4c..4d49856 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,38 @@ All notable changes to **bla-agents** are documented here.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.4.9] β€” 2026-10-29
+
+Counter for REA's AndroidManifest component inventory (`parseAndroidManifestComponents`,
+#7379) and its spelling-preserving binary-XML decode path (#7818, which landed in
+the 73-commit REA delta since 1.4.6). Unsigned APK hardening now plants a
+well-formed decoy `AndroidManifest.xml` under `assets/bla-shield/` that saturates
+`ANDROID_MANIFEST_LIMITS` (components: 512, resolvedNameBytes: 1 MiB, authorities,
+intentFilters/intentValues) so REA itself admits `status: "partial"`. Nested `$`
+class names exercise #7818 spelling retention. The developer's root
+`AndroidManifest.xml` is never rewritten (red line).
+
+Empirical vitest loads REA's compiled `parseAndroidManifestComponents` against
+the decoy and asserts the partial admission + `$` spelling retention.
+
+### Added
+
+- **`src/shields/formats/android-manifest.ts`** β€” decoy AndroidManifest.xml
+ generator (capacity flood, name-budget burn, unresolved-token / unnamed /
+ authority / intent-filter floods, nested `$` honeypot activities).
+- **`REA_INTERNAL_LIMITS` AndroidManifest constants** β€”
+ `ANDROID_MANIFEST_COMPONENTS`, `ANDROID_MANIFEST_INTENT_*`,
+ `ANDROID_MANIFEST_AUTHORITIES`, `ANDROID_MANIFEST_*_BYTES`.
+- **`verify:rea` drift checks** for all nine `ANDROID_MANIFEST_LIMITS` props.
+- **`tests/android-manifest-counter.test.ts`** β€” unit gates + empirical REA
+ red-team (soft-skips when sibling REA dist is absent).
+
+### Changed
+
+- **Unsigned APK path** (`protectZipOrApkBuffer`) injects
+ `assets/bla-shield/AndroidManifest.xml` and `AndroidManifest-decoy.xml`.
+- New return fields: `androidManifestDecoyBytes`, `androidManifestNamedComponents`.
+
## [1.4.6] β€” 2026-10-28
Counter for REA's new Android R8/ProGuard mapping ingestion (#7456) and JNI
diff --git a/package.json b/package.json
index 7b7ceac..e85dcc0 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "bla-agents",
- "version": "1.4.8",
- "description": "BLA (Blind LLM Agents) β€” Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, WebAssembly, SQLite, AI Models, and Android DEX/IL2CPP against AI reverse-engineering agents like REA.",
+ "version": "1.4.9",
+ "description": "BLA (Blind LLM Agents) \u2014 Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, WebAssembly, SQLite, AI Models, and Android DEX/IL2CPP against AI reverse-engineering agents like REA.",
"keywords": [
"reverse-engineering-defense",
"anti-rea",
diff --git a/scripts/verify-rea-constants.mjs b/scripts/verify-rea-constants.mjs
index b04ae63..8433180 100755
--- a/scripts/verify-rea-constants.mjs
+++ b/scripts/verify-rea-constants.mjs
@@ -272,6 +272,60 @@ const OBJECT_PROP_EXPECTATIONS = [
expected: 2048,
label: "ANDROID_JNI_LIBRARY_LIMITS.libraries",
},
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "components",
+ expected: 512,
+ label: "ANDROID_MANIFEST_LIMITS.components",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "intentFilters",
+ expected: 32,
+ label: "ANDROID_MANIFEST_LIMITS.intentFilters",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "intentValues",
+ expected: 64,
+ label: "ANDROID_MANIFEST_LIMITS.intentValues",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "authorities",
+ expected: 64,
+ label: "ANDROID_MANIFEST_LIMITS.authorities",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "resolvedNameBytes",
+ expected: 1024 * 1024,
+ label: "ANDROID_MANIFEST_LIMITS.resolvedNameBytes",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "authorityBytes",
+ expected: 1024 * 1024,
+ label: "ANDROID_MANIFEST_LIMITS.authorityBytes",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "permissionBytes",
+ expected: 1024 * 1024,
+ label: "ANDROID_MANIFEST_LIMITS.permissionBytes",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "processBytes",
+ expected: 1024 * 1024,
+ label: "ANDROID_MANIFEST_LIMITS.processBytes",
+ },
+ {
+ objectName: "ANDROID_MANIFEST_LIMITS",
+ propName: "detailBytes",
+ expected: 1024 * 1024,
+ label: "ANDROID_MANIFEST_LIMITS.detailBytes",
+ },
];
const SYMBOL_EXPECTATIONS = [
diff --git a/src/identity.ts b/src/identity.ts
index 4282bc0..36c7cfc 100644
--- a/src/identity.ts
+++ b/src/identity.ts
@@ -5,7 +5,7 @@ export const BLA_IDENTITY = Object.freeze({
packageAlias: "bla-shield",
cliBinary: "bla",
cliAlias: "bla-agents",
- version: "1.4.8",
+ version: "1.4.9",
slogan: "Poison -> Exhaust -> Hallucinate. Make Reverse Engineering Bankrupt Again.",
counterpart: {
name: "REA",
@@ -142,4 +142,19 @@ export const REA_INTERNAL_LIMITS = Object.freeze({
ANDROID_JNI_LIBRARIES: 2_048,
/** Native export inventory row ceiling (`MAX_NATIVE_EXPORT_ROWS` in `nativeExports.ts`). */
MAX_NATIVE_EXPORT_ROWS: 262_144,
+ /**
+ * AndroidManifest component inventory bounds (`ANDROID_MANIFEST_LIMITS` in
+ * `src/android/AndroidManifestComponents.ts`, REA #7379 / refined by #7818).
+ * Exceeding any of these flips the inventory to `status: "partial"` so REA
+ * itself admits the component map is unestablished.
+ */
+ ANDROID_MANIFEST_COMPONENTS: 512,
+ ANDROID_MANIFEST_INTENT_FILTERS: 32,
+ ANDROID_MANIFEST_INTENT_VALUES: 64,
+ ANDROID_MANIFEST_AUTHORITIES: 64,
+ ANDROID_MANIFEST_RESOLVED_NAME_BYTES: 1_048_576,
+ ANDROID_MANIFEST_AUTHORITY_BYTES: 1_048_576,
+ ANDROID_MANIFEST_PERMISSION_BYTES: 1_048_576,
+ ANDROID_MANIFEST_PROCESS_BYTES: 1_048_576,
+ ANDROID_MANIFEST_DETAIL_BYTES: 1_048_576,
});
diff --git a/src/index.ts b/src/index.ts
index 19fcf31..d8c5a2a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -112,6 +112,10 @@ export {
mangleJniIdentifier,
type AndroidR8CounterResult,
} from "./shields/formats/android-r8.js";
+export {
+ generateAndroidManifestCounter,
+ type AndroidManifestCounterResult,
+} from "./shields/formats/android-manifest.js";
export {
UnsupportedArchiveError,
UnsupportedApkProtectionError,
diff --git a/src/shields/formats/android-manifest.ts b/src/shields/formats/android-manifest.ts
new file mode 100644
index 0000000..2233128
--- /dev/null
+++ b/src/shields/formats/android-manifest.ts
@@ -0,0 +1,335 @@
+import { SeededPrng } from "../../core/prng.js";
+import type { ProtectionIntensity } from "../../core/types.js";
+import { REA_INTERNAL_LIMITS } from "../../identity.js";
+import { generateChaffPayloads } from "../chaff/chaff-generator.js";
+import { buildCanaryAndDiagnosticPayloads } from "../deception/format-payloads.js";
+
+export interface AndroidManifestCounterResult {
+ /** Well-formed UTF-8 AndroidManifest.xml (never binary AXML). */
+ readonly manifestXml: string;
+ /** Named component declarations emitted (activities/services/…). */
+ readonly namedComponentsEmitted: number;
+ /** Declarations deliberately missing `android:name` (unnamed flood). */
+ readonly unnamedComponentsEmitted: number;
+ /** Names containing `@` / `?` / `${…}` unresolved tokens. */
+ readonly unresolvedTokenNames: number;
+ /** Nested `$` class names preserved for REA #7818 spelling retention. */
+ readonly nestedDollarNames: number;
+ /** Intent-filter children planted per high-intensity activity. */
+ readonly intentFiltersPerHeavy: number;
+ /** Provider authority segments planted on the flood provider. */
+ readonly authoritySegmentsEmitted: number;
+ readonly chaffPayloadsEmbedded: number;
+ readonly canaryTokensEmbedded: number;
+ readonly diagnosticsEmbedded: number;
+}
+
+const PACKAGE_NAME = "com.enclave.sgx.teeattestation";
+
+/** XML attribute escaping β€” keeps the document well-formed for REA's XML parser. */
+function escAttr(value: string): string {
+ return value
+ .replace(/&/g, "&")
+ .replace(/"/g, """)
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;");
+}
+
+function intensityScale(intensity: ProtectionIntensity): {
+ namedPastCap: number;
+ unnamed: number;
+ unresolvedTokens: number;
+ nestedDollar: number;
+ namePadChars: number;
+ heavyIntentFilters: number;
+ authoritySegments: number;
+ processPadChars: number;
+} {
+ // Always exceed ANDROID_MANIFEST_COMPONENTS (512). Name padding is sized so
+ // the first ~N resolved relative names also burn resolvedNameBytes (1 MiB).
+ const cap = REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS;
+ switch (intensity) {
+ case "stealth":
+ return {
+ namedPastCap: 16,
+ unnamed: 4,
+ unresolvedTokens: 8,
+ nestedDollar: 8,
+ namePadChars: 1_024,
+ heavyIntentFilters: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_INTENT_FILTERS + 4,
+ authoritySegments: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_AUTHORITIES + 8,
+ processPadChars: 256,
+ };
+ case "maximum":
+ case "bankrupt":
+ return {
+ namedPastCap: 256,
+ unnamed: 32,
+ unresolvedTokens: 48,
+ nestedDollar: 64,
+ namePadChars: 4_096,
+ heavyIntentFilters: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_INTENT_FILTERS * 2,
+ authoritySegments: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_AUTHORITIES * 3,
+ processPadChars: 2_048,
+ };
+ case "balanced":
+ default:
+ return {
+ namedPastCap: 64,
+ unnamed: 12,
+ unresolvedTokens: 24,
+ nestedDollar: 24,
+ namePadChars: 2_048,
+ heavyIntentFilters: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_INTENT_FILTERS + 8,
+ authoritySegments: REA_INTERNAL_LIMITS.ANDROID_MANIFEST_AUTHORITIES + 32,
+ processPadChars: 1_024,
+ };
+ }
+}
+
+/**
+ * Generates a caller-tempting, well-formed decoy `AndroidManifest.xml` that
+ * counters REA's static component inventory (`parseAndroidManifestComponents`,
+ * REA #7379) and its spelling-preserving binary-XML decode path (#7818):
+ *
+ * - Named declarations past `ANDROID_MANIFEST_LIMITS.components` (512) force
+ * `capacityTruncated` β†’ inventory `status: "partial"`.
+ * - Long package-relative names burn `resolvedNameBytes` (1 MiB) so later
+ * names keep their declared form (`unresolvedNames`).
+ * - Unnamed / `@string/` / `${placeholder}` declarations trigger the
+ * corresponding limitation strings REA itself publishes.
+ * - Nested `$` class names exercise #7818's "preserve component spelling".
+ * - Provider authority floods past `authorities: 64` and intent-filter floods
+ * past `intentFilters: 32` / `intentValues: 64` deepen the partial admission.
+ *
+ * Red-line safe: this is a NEW decoy XML artifact (sidecar under
+ * `assets/bla-shield/`). It never rewrites the developer's root
+ * `AndroidManifest.xml`, never changes the real export surface, and never
+ * emits binary AXML that could invalidate an APK signature check path we
+ * already refuse for signed APKs.
+ */
+export function generateAndroidManifestCounter(
+ prng: SeededPrng,
+ intensity: ProtectionIntensity = "balanced",
+): AndroidManifestCounterResult {
+ const scale = intensityScale(intensity);
+ const chaff = generateChaffPayloads(prng, intensity);
+ const deception = buildCanaryAndDiagnosticPayloads(prng, intensity);
+
+ const cap = REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS;
+ const namedTarget = cap + scale.namedPastCap;
+
+ const kinds = [
+ "activity",
+ "service",
+ "receiver",
+ "provider",
+ "activity-alias",
+ ] as const;
+
+ const lines: string[] = [
+ `<?xml version="1.0" encoding="utf-8"?>`,
+ `<!-- bla-shield: decoy AndroidManifest β€” saturates REA #7379/#7818 component inventory -->`,
+ `<manifest xmlns:android="http://schemas.android.com/apk/res/android"`,
+ ` package="${PACKAGE_NAME}"`,
+ ` android:versionCode="1"`,
+ ` android:versionName="1.0-bla-enclave-shield">`,
+ ` <uses-sdk android:minSdkVersion="24" android:targetSdkVersion="34" />`,
+ ` <uses-permission android:name="android.permission.INTERNET" />`,
+ ` <uses-permission android:name="com.enclave.sgx.permission.TEE_ATTEST" />`,
+ ` <application`,
+ ` android:label="BLA Enclave Shield Decoy"`,
+ ` android:permission="com.enclave.sgx.permission.TEE_ATTEST"`,
+ ` android:allowBackup="false">`,
+ ];
+
+ // Seed a few "real-looking" nested-$ activities first so #7818 spelling
+ // retention surfaces them even if a later capacity cut drops the flood.
+ const nestedNames: string[] = [
+ ".TeeAttestationBridge$DetailsActivity",
+ ".TeeAttestationBridge$QuorumRingFragment",
+ ".KeyUnsealerStub$VsockCid16Transport",
+ ".NitroAttestation$ShamirEd25519Quorum",
+ ];
+ let nestedDollarNames = 0;
+ for (let i = 0; i < Math.min(scale.nestedDollar, nestedNames.length); i++) {
+ const declared = nestedNames[i]!;
+ lines.push(
+ ` <activity android:name="${escAttr(declared)}" android:exported="false" android:enabled="true">`,
+ ` <intent-filter>`,
+ ` <action android:name="com.enclave.sgx.action.VERIFY_SHAMIR_${i}" />`,
+ ` <category android:name="android.intent.category.DEFAULT" />`,
+ ` </intent-filter>`,
+ ` <meta-data android:name="bla.canary" android:value="${escAttr(deception.textRecords[i % deception.textRecords.length] ?? "PROTECTED_CANARY")}" />`,
+ ` </activity>`,
+ );
+ nestedDollarNames += 1;
+ }
+ // Extra nested-$ names beyond the seed list.
+ for (let i = nestedNames.length; i < scale.nestedDollar; i++) {
+ const declared = `.EnclaveStateNode$${prng.hex(6)}$Layer${i}`;
+ lines.push(
+ ` <activity android:name="${escAttr(declared)}" android:exported="false" />`,
+ );
+ nestedDollarNames += 1;
+ }
+
+ // Unresolved-token names β€” REA retains declared_name and marks inventory partial.
+ let unresolvedTokenNames = 0;
+ for (let i = 0; i < scale.unresolvedTokens; i++) {
+ const kind = kinds[i % kinds.length]!;
+ const token =
+ i % 3 === 0
+ ? `@string/enclave_bridge_${prng.hex(4)}`
+ : i % 3 === 1
+ ? `\${enclave.placeholder.bridge_${i}}`
+ : `?attr/enclaveTeeBridge_${i}`;
+ if (kind === "activity-alias") {
+ lines.push(
+ ` <activity-alias android:name="${escAttr(token)}" android:targetActivity=".TeeAttestationBridge$DetailsActivity" android:exported="false" />`,
+ );
+ } else if (kind === "provider") {
+ lines.push(
+ ` <provider android:name="${escAttr(token)}" android:authorities="com.enclave.token.${i}" android:exported="false" />`,
+ );
+ } else {
+ lines.push(
+ ` <${kind} android:name="${escAttr(token)}" android:exported="false" />`,
+ );
+ }
+ unresolvedTokenNames += 1;
+ }
+
+ // One heavy provider that floods authorities past ANDROID_MANIFEST_AUTHORITIES.
+ const authorityParts: string[] = [];
+ for (let i = 0; i < scale.authoritySegments; i++) {
+ if (i % 17 === 0) {
+ // Empty / whitespace segments β†’ malformedAuthoritySegments limitation.
+ authorityParts.push(i % 34 === 0 ? "" : " ");
+ } else {
+ authorityParts.push(`com.enclave.sgx.auth_${prng.hex(4)}_${i}`);
+ }
+ }
+ const authoritySegmentsEmitted = authorityParts.length;
+ lines.push(
+ ` <provider`,
+ ` android:name=".EnclaveAuthorityFloodProvider"`,
+ ` android:authorities="${escAttr(authorityParts.join(";"))}"`,
+ ` android:exported="@bool/bla_canary_exported"`,
+ ` android:grantUriPermissions="@bool/bla_canary_grant"`,
+ ` android:permission="com.enclave.sgx.permission.TEE_ATTEST"`,
+ ` android:readPermission="com.enclave.sgx.permission.TEE_READ"`,
+ ` android:writePermission="com.enclave.sgx.permission.TEE_WRITE" />`,
+ );
+
+ // One heavy activity that floods intent-filters past INTENT_FILTERS and
+ // intent values past INTENT_VALUES (actions/categories/data + meta-data).
+ const intentFiltersPerHeavy = scale.heavyIntentFilters;
+ const processPad = "p".repeat(scale.processPadChars);
+ lines.push(
+ ` <activity`,
+ ` android:name=".TeeAttestationBridge$IntentFloodActivity"`,
+ ` android:exported="@bool/bla_canary_exported"`,
+ ` android:enabled="@bool/bla_canary_enabled"`,
+ ` android:process=":${escAttr(processPad)}">`,
+ );
+ for (let f = 0; f < intentFiltersPerHeavy; f++) {
+ lines.push(` <intent-filter android:priority="${1000 + f}">`);
+ // Flood intentValues: many actions + categories + data attrs.
+ const valuesPerFilter = Math.ceil(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_INTENT_VALUES / 2,
+ );
+ for (let v = 0; v < valuesPerFilter; v++) {
+ lines.push(
+ ` <action android:name="com.enclave.sgx.action.FLOOD_${f}_${v}_${prng.hex(2)}" />`,
+ );
+ }
+ for (let v = 0; v < 4; v++) {
+ lines.push(
+ ` <category android:name="com.enclave.sgx.category.FLOOD_${f}_${v}" />`,
+ );
+ }
+ lines.push(
+ ` <data android:scheme="enclave" android:host="vsock${f}" android:port="${6000 + f}" android:pathPrefix="/cid16/${f}" android:mimeType="application/vnd.enclave.sgx" />`,
+ );
+ lines.push(` </intent-filter>`);
+ }
+ // Meta-data canary bait (counts toward detailBytes / intentValues).
+ for (const rec of deception.textRecords.slice(0, 8)) {
+ lines.push(
+ ` <meta-data android:name="bla.canary.${prng.hex(4)}" android:value="${escAttr(rec.slice(0, 200))}" />`,
+ );
+ }
+ for (const c of chaff.slice(0, 4)) {
+ lines.push(
+ ` <meta-data android:name="bla.chaff.${c.id}" android:value="${escAttr(c.rawText.slice(0, 160))}" />`,
+ );
+ }
+ lines.push(` </activity>`);
+
+ // Capacity flood: named components past the 512 cap, with long relative
+ // names so resolvedNameBytes burns out and later names stay unresolved.
+ // Already emitted: nestedDollar + unresolvedTokens + 1 heavy provider + 1 heavy activity.
+ const alreadyNamed = nestedDollarNames + unresolvedTokenNames + 2;
+ const remainingNamed = Math.max(0, namedTarget - alreadyNamed);
+ const padAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789_";
+ const makePad = (n: number): string => {
+ let out = "";
+ while (out.length < n) {
+ out += padAlphabet[prng.nextInt(0, padAlphabet.length - 1)]!;
+ }
+ return out.slice(0, n);
+ };
+
+ for (let i = 0; i < remainingNamed; i++) {
+ const kind = kinds[i % kinds.length]!;
+ // Relative name (leading '.') so REA resolves against package and charges
+ // packageNameBytes + declaredBytes against the 1 MiB name budget.
+ const pad = makePad(scale.namePadChars);
+ const declared = `.EnclaveStateNode_${prng.hex(6)}_${i}_${pad}`;
+ if (kind === "activity-alias") {
+ // targetActivity deliberately does NOT match a preceding activity β†’
+ // unresolvedTargetActivities limitation.
+ lines.push(
+ ` <activity-alias android:name="${escAttr(declared)}" android:targetActivity=".MissingTarget$${i}" android:exported="false" />`,
+ );
+ } else if (kind === "provider") {
+ lines.push(
+ ` <provider android:name="${escAttr(declared)}" android:authorities="com.enclave.tarpit.${i}" android:exported="false" />`,
+ );
+ } else if (kind === "service") {
+ lines.push(
+ ` <service android:name="${escAttr(declared)}" android:exported="false" android:foregroundServiceType="dataSync" />`,
+ );
+ } else {
+ lines.push(
+ ` <${kind} android:name="${escAttr(declared)}" android:exported="false" />`,
+ );
+ }
+ }
+
+ // Unnamed flood β€” every declaration without android:name counts against the
+ // bound but is omitted from items, forcing truncated=true.
+ let unnamedComponentsEmitted = 0;
+ for (let i = 0; i < scale.unnamed; i++) {
+ const kind = kinds[i % 3]!; // activity/service/receiver only (alias/provider need name more often)
+ lines.push(` <${kind} android:exported="false" />`);
+ unnamedComponentsEmitted += 1;
+ }
+
+ lines.push(` </application>`, `</manifest>`, ``);
+
+ const namedComponentsEmitted = alreadyNamed + remainingNamed;
+ return {
+ manifestXml: lines.join("\n"),
+ namedComponentsEmitted,
+ unnamedComponentsEmitted,
+ unresolvedTokenNames,
+ nestedDollarNames,
+ intentFiltersPerHeavy,
+ authoritySegmentsEmitted,
+ chaffPayloadsEmbedded: chaff.length,
+ canaryTokensEmbedded: deception.canary.syntheticCanaryTokens.length,
+ diagnosticsEmbedded: deception.diagnostics.diagnosticsInjected.length,
+ };
+}
diff --git a/src/shields/formats/archive.ts b/src/shields/formats/archive.ts
index 43cc6de..44d6c15 100644
--- a/src/shields/formats/archive.ts
+++ b/src/shields/formats/archive.ts
@@ -5,6 +5,7 @@ import { generateChaffPayloads } from "../chaff/chaff-generator.js";
import { buildCanaryAndDiagnosticPayloads } from "../deception/format-payloads.js";
import { protectAndroidDexBuffer, protectIl2cppMetadataBuffer } from "./mobile-game.js";
import { generateAndroidR8Counter } from "./android-r8.js";
+import { generateAndroidManifestCounter } from "./android-manifest.js";
export interface ZipEntryInfo {
readonly name: string;
@@ -259,6 +260,9 @@ export function protectZipOrApkBuffer(
/** Non-zero when unsigned APK path planted R8 mapping + JNI decoy .so (REA #7456/#7472). */
readonly androidR8MappingBytes: number;
readonly androidJniExportsPlanted: number;
+ /** Non-zero when unsigned APK path planted decoy AndroidManifest.xml (REA #7379/#7818). */
+ readonly androidManifestDecoyBytes: number;
+ readonly androidManifestNamedComponents: number;
} {
const preview = readZipEntries(bytes);
const isSigned = preview.some((e) => /^META-INF\/.*\.(SF|RSA|DSA|EC)$/i.test(e.name));
@@ -344,6 +348,8 @@ export function protectZipOrApkBuffer(
// exports. Only on unsigned APK-shaped archives; never rewrite the developer's own .so.
let androidR8MappingBytes = 0;
let androidJniExportsPlanted = 0;
+ let androidManifestDecoyBytes = 0;
+ let androidManifestNamedComponents = 0;
let r8ExtraEntries = 0;
if (treatAsApk) {
const r8 = generateAndroidR8Counter(prng, intensity);
@@ -363,6 +369,23 @@ export function protectZipOrApkBuffer(
androidR8MappingBytes = mappingBuf.length;
androidJniExportsPlanted = r8.jniExportNames.length;
r8ExtraEntries = 3;
+
+ // Counter REA #7379 / #7818: plant a well-formed decoy AndroidManifest.xml
+ // under assets/bla-shield/. Never rewrite the developer's root manifest
+ // (red line β€” real component / export surface stays intact).
+ const mf = generateAndroidManifestCounter(prng, intensity);
+ const mfBuf = Buffer.from(mf.manifestXml, "utf8");
+ outputFiles.push({
+ name: `${decoyRoot}/AndroidManifest.xml`,
+ data: mfBuf,
+ });
+ outputFiles.push({
+ name: `${decoyRoot}/AndroidManifest-decoy.xml`,
+ data: Buffer.from(mf.manifestXml, "utf8"),
+ });
+ androidManifestDecoyBytes = mfBuf.length;
+ androidManifestNamedComponents = mf.namedComponentsEmitted;
+ r8ExtraEntries += 2;
}
return {
@@ -374,5 +397,7 @@ export function protectZipOrApkBuffer(
membersHardened,
androidR8MappingBytes,
androidJniExportsPlanted,
+ androidManifestDecoyBytes,
+ androidManifestNamedComponents,
};
}
diff --git a/tests/android-manifest-counter.test.ts b/tests/android-manifest-counter.test.ts
new file mode 100644
index 0000000..3f001b2
--- /dev/null
+++ b/tests/android-manifest-counter.test.ts
@@ -0,0 +1,161 @@
+import { existsSync } from "node:fs";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it } from "vitest";
+import { SeededPrng } from "../src/core/prng.js";
+import { REA_INTERNAL_LIMITS } from "../src/identity.js";
+import { generateAndroidManifestCounter } from "../src/shields/formats/android-manifest.js";
+import {
+ protectZipOrApkBuffer,
+ readZipEntries,
+ writeZipArchive,
+} from "../src/shields/formats/archive.js";
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const BLA_ROOT = resolve(__dirname, "..");
+const REA_ROOT_ENV = (process.env.REA_ROOT ?? "").trim();
+const REA_ROOT = resolve(REA_ROOT_ENV || join(BLA_ROOT, "..", "rea"));
+const REA_MANIFEST_DIST = join(
+ REA_ROOT,
+ "dist/android/AndroidManifestComponents.js",
+);
+
+describe("android manifest component decoy (REA #7379 / #7818)", () => {
+ it("emits well-formed XML past ANDROID_MANIFEST_COMPONENTS with nested $ spelling", () => {
+ const res = generateAndroidManifestCounter(
+ new SeededPrng("mf-balanced"),
+ "balanced",
+ );
+ expect(res.namedComponentsEmitted).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS,
+ );
+ expect(res.unnamedComponentsEmitted).toBeGreaterThan(0);
+ expect(res.unresolvedTokenNames).toBeGreaterThan(0);
+ expect(res.nestedDollarNames).toBeGreaterThan(0);
+ expect(res.intentFiltersPerHeavy).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_INTENT_FILTERS,
+ );
+ expect(res.authoritySegmentsEmitted).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_AUTHORITIES,
+ );
+ expect(res.manifestXml).toMatch(/^<\?xml version="1\.0"/);
+ expect(res.manifestXml).toContain('package="com.enclave.sgx.teeattestation"');
+ expect(res.manifestXml).toContain(
+ 'android:name=".TeeAttestationBridge$DetailsActivity"',
+ );
+ expect(res.manifestXml).toContain("@string/enclave_bridge_");
+ expect(res.manifestXml).toContain("${enclave.placeholder.bridge_");
+ expect(res.manifestXml).toContain("PROTECTED_CANARY_CREDENTIAL=");
+ // Root closes cleanly β€” well-formedness smoke check.
+ expect(res.manifestXml.trimEnd().endsWith("</manifest>")).toBe(true);
+ });
+
+ it("scales past the component cap at every intensity", () => {
+ for (const intensity of ["stealth", "balanced", "maximum", "bankrupt"] as const) {
+ const res = generateAndroidManifestCounter(
+ new SeededPrng(`mf-${intensity}`),
+ intensity,
+ );
+ expect(res.namedComponentsEmitted).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS,
+ );
+ expect(res.manifestXml.length).toBeGreaterThan(4_000);
+ }
+ });
+
+ it("plants the decoy under assets/bla-shield/ without rewriting the root manifest", () => {
+ const rootManifest = Buffer.from(
+ '<manifest package="com.example.app"><application/></manifest>',
+ "utf8",
+ );
+ const dex = Buffer.alloc(112, 0);
+ dex.write("dex\n035\0", 0, "ascii");
+ dex.writeUInt32LE(112, 32);
+ dex.writeUInt32LE(112, 36);
+ dex.writeUInt32LE(0x12345678, 40);
+ const unsignedApk = writeZipArchive([
+ { name: "AndroidManifest.xml", data: rootManifest },
+ { name: "classes.dex", data: dex },
+ ]);
+ const res = protectZipOrApkBuffer(unsignedApk, {
+ isApk: true,
+ intensity: "stealth",
+ seed: "apk-manifest-decoy",
+ });
+ expect(res.androidManifestDecoyBytes).toBeGreaterThan(2_000);
+ expect(res.androidManifestNamedComponents).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS,
+ );
+ const entries = readZipEntries(res.buffer);
+ const root = entries.find((e) => e.name === "AndroidManifest.xml");
+ expect(root).toBeDefined();
+ // Red line: developer's root manifest bytes are untouched.
+ expect(root!.data.equals(rootManifest)).toBe(true);
+ expect(
+ entries.some((e) => e.name === "assets/bla-shield/AndroidManifest.xml"),
+ ).toBe(true);
+ expect(
+ entries.some(
+ (e) => e.name === "assets/bla-shield/AndroidManifest-decoy.xml",
+ ),
+ ).toBe(true);
+ const decoy = entries
+ .find((e) => e.name === "assets/bla-shield/AndroidManifest.xml")!
+ .data.toString("utf8");
+ expect(decoy).toContain("TeeAttestationBridge$DetailsActivity");
+ expect(decoy).toContain("bla-shield: decoy AndroidManifest");
+ });
+});
+
+describe("empirical REA parseAndroidManifestComponents red-team", () => {
+ it("drives REA inventory to status:'partial' on the decoy (and on a synthetic root fixture)", async () => {
+ if (!existsSync(REA_MANIFEST_DIST)) {
+ console.log(
+ `SKIP empirical: REA dist missing at ${REA_MANIFEST_DIST}`,
+ );
+ return;
+ }
+ const rea = await import(REA_MANIFEST_DIST);
+ expect(typeof rea.parseAndroidManifestComponents).toBe("function");
+ expect(rea.ANDROID_MANIFEST_LIMITS.components).toBe(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_COMPONENTS,
+ );
+ expect(rea.ANDROID_MANIFEST_LIMITS.resolvedNameBytes).toBe(
+ REA_INTERNAL_LIMITS.ANDROID_MANIFEST_RESOLVED_NAME_BYTES,
+ );
+
+ const decoy = generateAndroidManifestCounter(
+ new SeededPrng("empirical-mf"),
+ "balanced",
+ );
+
+ // Coverage "complete" β€” REA only inventories when the decoded text is whole.
+ const inventory = rea.parseAndroidManifestComponents(
+ decoy.manifestXml,
+ "complete",
+ "34",
+ "24",
+ );
+ expect(inventory.status).toBe("partial");
+ expect(Array.isArray(inventory.limitations)).toBe(true);
+ expect(inventory.limitations.length).toBeGreaterThan(0);
+ // Capacity and/or unresolved-name budget must fire.
+ const joined = inventory.limitations.join("\n");
+ expect(
+ /capacity limit|resolved-name byte budget|without android:name|unresolved resource|package-relative/i.test(
+ joined,
+ ),
+ ).toBe(true);
+ // Nested $ spelling retained on any item that made it into the projection.
+ const nested = inventory.items.filter((c: { declared_name: string }) =>
+ c.declared_name.includes("$"),
+ );
+ expect(nested.length).toBeGreaterThan(0);
+ for (const c of nested) {
+ expect(c.declared_name).toMatch(/\$/);
+ // #7818: declared_name spelling is preserved (no JADX alias rewrite here β€”
+ // this is the pure-TS inventory path; declared_name === source attribute).
+ expect(c.declared_name.includes(".")).toBe(true);
+ }
+ });
+});
diff --git a/tests/archive-integrity.test.ts b/tests/archive-integrity.test.ts
index 185f9e2..f36a0e9 100644
--- a/tests/archive-integrity.test.ts
+++ b/tests/archive-integrity.test.ts
@@ -100,6 +100,15 @@ describe("archive admission preserves bytes or fails closed", () => {
expect(mapping).toMatch(/# compiler: R8/);
expect(mapping).toMatch(/-> a\.a\.a:/);
expect(outDex.toString("latin1")).toContain("Java_com_enclave_sgx_TeeAttestationBridge");
+ // REA #7379 / #7818: decoy AndroidManifest.xml under assets/bla-shield/ (root untouched).
+ expect(res.androidManifestDecoyBytes).toBeGreaterThan(2_000);
+ expect(res.androidManifestNamedComponents).toBeGreaterThan(512);
+ expect(entries.some((e) => e.name === "assets/bla-shield/AndroidManifest.xml")).toBe(true);
+ expect(entries.some((e) => e.name === "assets/bla-shield/AndroidManifest-decoy.xml")).toBe(true);
+ const rootMf = entries.find((e) => e.name === "AndroidManifest.xml")!.data.toString("utf8");
+ expect(rootMf).toBe("<manifest/>");
+ const decoyMf = entries.find((e) => e.name === "assets/bla-shield/AndroidManifest.xml")!.data.toString("utf8");
+ expect(decoyMf).toContain("TeeAttestationBridge$DetailsActivity");
// Signed APK still fails closed.
const signed = writeZipArchive([