Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(artifacts): bound mobile projection candidates

morluto0cc9d468c4d6
diff --git a/src/domain/androidApplication.ts b/src/domain/androidApplication.ts
index 9255f3217..6f2758e24 100644
--- a/src/domain/androidApplication.ts
+++ b/src/domain/androidApplication.ts
@@ -4,6 +4,7 @@ import canonicalize from "canonicalize";
import { z } from "zod";
import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js";
+import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
import { evidenceSchema } from "./evidence.js";
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
@@ -248,16 +249,19 @@ const bridgeCandidates = (
native: readonly Component[],
maximum: number,
) => {
- const candidates = managed.flatMap((source) =>
- native.map((target) => ({
+ const projection = projectBoundedCartesian(
+ managed,
+ native,
+ maximum,
+ (source, target) => ({
managed_path: source.path,
native_path: target.path,
basis: bridgeBasis(target.path),
- })),
+ }),
);
return {
- candidates: candidates.slice(0, maximum),
- omitted: Math.max(0, candidates.length - maximum),
+ candidates: projection.values,
+ omitted: projection.omitted,
};
};
diff --git a/src/domain/appleApplication.ts b/src/domain/appleApplication.ts
index 82f5c4b37..5a22e8fc6 100644
--- a/src/domain/appleApplication.ts
+++ b/src/domain/appleApplication.ts
@@ -4,6 +4,7 @@ import canonicalize from "canonicalize";
import { z } from "zod";
import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js";
+import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
import { evidenceSchema } from "./evidence.js";
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
@@ -114,13 +115,14 @@ export const projectAppleApplication = (
format: node.format,
} satisfies Component;
});
- const roots = inventory.occurrences
- .filter(
- ({ logical_path: path, entry_kind: kind }) =>
- kind === "directory" && /^Payload\/[^/]+\.app$/u.test(path),
- )
- .map(({ logical_path: path }) => path)
- .sort(compare);
+ const roots = [
+ ...new Set(
+ inventory.occurrences.flatMap(({ logical_path: path }) => {
+ const match = /^(Payload\/[^/]+\.app)(?:\/|$)/u.exec(path);
+ return match?.[1] === undefined ? [] : [match[1]];
+ }),
+ ),
+ ].sort(compare);
const classified = classifyComponents(all, roots);
const retained = retainComponents(classified, parsed.limits.max_components);
const omitted = componentCount(classified) - componentCount(retained);
@@ -249,16 +251,19 @@ const identifyBridgeCandidates = (
native: readonly Component[],
maximum: number,
) => {
- const candidates = scripts.flatMap((script) =>
- native.map((item) => ({
+ const projection = projectBoundedCartesian(
+ scripts,
+ native,
+ maximum,
+ (script, item) => ({
source_path: script.path,
native_path: item.path,
basis: bridgeBasis(item.path),
- })),
+ }),
);
return {
- candidates: candidates.slice(0, maximum),
- omitted: Math.max(0, candidates.length - maximum),
+ candidates: projection.values,
+ omitted: projection.omitted,
};
};
diff --git a/src/domain/boundedCartesianProjection.ts b/src/domain/boundedCartesianProjection.ts
new file mode 100644
index 000000000..e237be547
--- /dev/null
+++ b/src/domain/boundedCartesianProjection.ts
@@ -0,0 +1,20 @@
+/** Project a Cartesian product without materializing values beyond the output limit. */
+export const projectBoundedCartesian = <Left, Right, Value>(
+ left: readonly Left[],
+ right: readonly Right[],
+ maximum: number,
+ project: (left: Left, right: Right) => Value,
+): { readonly values: Value[]; readonly omitted: number } => {
+ const values: Value[] = [];
+ for (const leftValue of left) {
+ for (const rightValue of right) {
+ if (values.length === maximum)
+ return {
+ values,
+ omitted: left.length * right.length - values.length,
+ };
+ values.push(project(leftValue, rightValue));
+ }
+ }
+ return { values, omitted: 0 };
+};
diff --git a/src/domain/runtimeIdentification.ts b/src/domain/runtimeIdentification.ts
index 7418506e4..981f4af79 100644
--- a/src/domain/runtimeIdentification.ts
+++ b/src/domain/runtimeIdentification.ts
@@ -81,9 +81,9 @@ type RuntimeProvider = {
const PROVIDERS: Readonly<Record<RuntimeFamily, RuntimeProvider>> = {
android: {
- inspection: "provider-missing",
- id: null,
- reason: "Install or configure an Android semantic-analysis provider.",
+ inspection: "available",
+ id: "rea-android-application",
+ reason: null,
},
apple: { inspection: "available", id: "rea-apple-application", reason: null },
javascript: {
diff --git a/tests/appleApplication.test.ts b/tests/appleApplication.test.ts
index 779c300e4..34b3a7ed2 100644
--- a/tests/appleApplication.test.ts
+++ b/tests/appleApplication.test.ts
@@ -111,4 +111,34 @@ describe("Apple application projection", () => {
error: { _tag: "AnalysisInputError" },
});
});
+
+ it("infers an application root when the IPA omits directory entries", async () => {
+ const root = await mkdtemp(join(tmpdir(), "rea-apple-root-"));
+ const path = join(root, "Fixture.ipa");
+ const writer = new ZipWriter(new Uint8ArrayWriter());
+ await writer.add(
+ "Payload/Fixture.app/Fixture",
+ new Uint8ArrayReader(
+ Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
+ ),
+ );
+ await writeFile(path, await writer.close());
+
+ const inventory = parseEvidence(
+ await runProviderAnalysis(path, "inventory_artifact", {}),
+ );
+ const result = projectAppleApplicationEvidence({
+ inventory_evidence: [inventory],
+ });
+ expect(result.ok).toBe(true);
+ if (!result.ok) return;
+ expect(
+ appleApplicationProjectionResultSchema.parse(
+ result.value.normalized_result,
+ ),
+ ).toMatchObject({
+ application_roots: ["Payload/Fixture.app"],
+ components: { executables: [expect.any(Object)] },
+ });
+ });
});
diff --git a/tests/boundedCartesianProjection.test.ts b/tests/boundedCartesianProjection.test.ts
new file mode 100644
index 000000000..9a8953c5d
--- /dev/null
+++ b/tests/boundedCartesianProjection.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from "vitest";
+
+import { projectBoundedCartesian } from "../src/domain/boundedCartesianProjection.js";
+
+describe("bounded Cartesian projection", () => {
+ it("stops projection work at the output limit", () => {
+ const values = Array.from({ length: 10_000 }, (_, index) => index);
+ let projections = 0;
+
+ const result = projectBoundedCartesian(values, values, 3, (left, right) => {
+ projections += 1;
+ return [left, right] as const;
+ });
+
+ expect(result).toEqual({
+ values: [
+ [0, 0],
+ [0, 1],
+ [0, 2],
+ ],
+ omitted: 100_000_000 - 3,
+ });
+ expect(projections).toBe(3);
+ });
+});
diff --git a/tests/runtimeIdentification.test.ts b/tests/runtimeIdentification.test.ts
index 07bc65857..2a7111dc7 100644
--- a/tests/runtimeIdentification.test.ts
+++ b/tests/runtimeIdentification.test.ts
@@ -78,6 +78,11 @@ describe("runtime identification", () => {
]);
expect(first.runtimes).toEqual(
expect.arrayContaining([
+ expect.objectContaining({
+ family: "android",
+ inspection: "available",
+ provider_id: "rea-android-application",
+ }),
expect.objectContaining({
family: "jvm",
inspection: "provider-missing",