Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(ida): share string-page failure interpretation

morlutobfacfbac3081
diff --git a/src/ida/IdaNativeProtocol.ts b/src/ida/IdaNativeProtocol.ts
index a7ac782d5..35a88d57c 100644
--- a/src/ida/IdaNativeProtocol.ts
+++ b/src/ida/IdaNativeProtocol.ts
@@ -5,7 +5,6 @@ import {
disassemblySchema,
idaAddressSchema,
modernCalleesSchema,
- modernStringsSchema,
modernXrefsSchema,
} from "./IdaProtocolValues.js";
@@ -83,17 +82,6 @@ export const nativeXrefsSchema = z
.array(modernXrefsSchema.element.extend({ error: nativeErrorSchema }))
.length(1);
-/** Native regex failures carry an empty page, which must not imply absence. */
-export const nativeStringsSchema = modernStringsSchema
- .extend({ error: z.string().optional() })
- .transform((page) => {
- if (page.error !== undefined)
- throw new AnalysisProtocolError(
- `Native IDA string search failed: ${page.error}`,
- );
- return page;
- });
-
/**
* Native regexes fold bytes, while REA's insensitive literal search folds
* Unicode strings. Include every non-ASCII value as a candidate, then apply
diff --git a/src/ida/IdaOperationRunner.ts b/src/ida/IdaOperationRunner.ts
index f7cf5ae2b..4e42a063e 100644
--- a/src/ida/IdaOperationRunner.ts
+++ b/src/ida/IdaOperationRunner.ts
@@ -5,7 +5,6 @@ import {
nativeCalleesSchema,
nativeXrefsSchema,
nativeLiteralSearchPattern,
- nativeStringsSchema,
} from "./IdaNativeProtocol.js";
import {
analysisSearchPredicate,
@@ -35,6 +34,7 @@ import {
disassemblySchema,
idaAddressSchema,
idaFunctionSchema,
+ idaStringsPageSchema,
legacyCalleesSchema,
legacyPageSchema,
legacyStringSchema,
@@ -45,7 +45,6 @@ import {
modernLookupSchema,
modernLookupBatchSchema,
modernPageSchema,
- modernStringsSchema,
modernXrefsSchema,
nextOffset,
surveySegmentsSchema,
@@ -321,9 +320,7 @@ export class IdaOperationRunner {
}
offset = page.next_offset;
} else {
- const page = (
- this.protocol === "native" ? nativeStringsSchema : modernStringsSchema
- ).parse(
+ const page = idaStringsPageSchema.parse(
await this.call("find_regex", {
pattern:
this.protocol === "native"
@@ -333,6 +330,10 @@ export class IdaOperationRunner {
limit: 100,
}),
);
+ if (page.error !== undefined && page.error !== null)
+ throw new AnalysisProtocolError(
+ `${this.protocol === "native" ? "Native IDA" : "IDA"} string search failed: ${page.error}`,
+ );
result.push(
...page.matches.map((s) => ({ address: s.addr, value: s.string })),
);
diff --git a/src/ida/IdaProtocolValues.ts b/src/ida/IdaProtocolValues.ts
index f18e85ee0..f070f052d 100644
--- a/src/ida/IdaProtocolValues.ts
+++ b/src/ida/IdaProtocolValues.ts
@@ -135,9 +135,10 @@ export const legacyStringSchema = z.object({
string: z.string(),
length: z.number().int().nonnegative(),
});
-export const modernStringsSchema = z.object({
+export const idaStringsPageSchema = z.object({
matches: z.array(z.object({ addr: idaAddressSchema, string: z.string() })),
cursor: cursorSchema,
+ error: z.string().nullish(),
});
export const legacyXrefsSchema = z.array(
z.object({
diff --git a/src/ida/IdaSessionClient.test.ts b/src/ida/IdaSessionClient.test.ts
index c6bffd2e0..b9e34485e 100644
--- a/src/ida/IdaSessionClient.test.ts
+++ b/src/ida/IdaSessionClient.test.ts
@@ -9,6 +9,7 @@ import {
import { IdaSessionClient } from "./IdaSessionClient.js";
import { functionDossierSchema } from "../domain/hopperValues.js";
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
+import { AnalysisProtocolError } from "../domain/analysisErrorCore.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { WindowsPrivateRuntime } from "../windows/WindowsPrivateRuntime.js";
@@ -153,6 +154,76 @@ describe("headless IDA producer pagination", () => {
});
});
+describe("headless IDA modern string search failures", () => {
+ it("rejects a producer error before returning page matches and retains both replies as partial evidence", async () => {
+ const { producer, client } = await fixture("headless");
+ producer.overrideCall = (name, args) => {
+ if (name !== "find_regex") return undefined;
+ if (args.offset === 0)
+ return {
+ matches: [{ addr: "0x3000", string: "complete page" }],
+ cursor: { next: 1 },
+ error: null,
+ };
+ return {
+ matches: [{ addr: "0x3001", string: "untrusted partial page" }],
+ cursor: { done: true },
+ error: "Search fixture failed",
+ };
+ };
+ try {
+ const failed = await client.execute("search_strings", {
+ pattern: "needle",
+ });
+ expect(failed.ok).toBe(false);
+ if (!failed.ok) {
+ expect(failed.error).toBeInstanceOf(AnalysisProtocolError);
+ expect(failed.error.message).toContain("Search fixture failed");
+ expect(failed.error.partialObservation).toMatchObject({
+ normalized_result: {
+ status: "partial",
+ failed_operation: "search_strings",
+ observations: expect.arrayContaining([
+ expect.objectContaining({
+ tool: "find_regex",
+ result: expect.objectContaining({
+ matches: [{ addr: "0x3000", string: "complete page" }],
+ error: null,
+ }),
+ }),
+ expect.objectContaining({
+ tool: "find_regex",
+ result: expect.objectContaining({
+ matches: [
+ { addr: "0x3001", string: "untrusted partial page" },
+ ],
+ error: "Search fixture failed",
+ }),
+ }),
+ ]),
+ },
+ });
+ }
+ expect(
+ producer.calls
+ .filter(({ name }) => name === "find_regex")
+ .map(({ args }) => args.offset),
+ ).toEqual([0, 1]);
+
+ producer.overrideCall = (name) =>
+ name === "find_regex"
+ ? { matches: [], cursor: { done: true }, error: null }
+ : undefined;
+ const empty = await client.execute("search_strings", {
+ pattern: "needle",
+ });
+ expect(empty.ok && empty.value.result).toEqual([]);
+ } finally {
+ expect((await client.close()).ok).toBe(true);
+ }
+ });
+});
+
describe("attached IDA readiness and queued cancellation", () => {
it("allows ready-only work after an attached provider has initialized", async () => {
const { producer, client } = await fixture("attached");