Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(objc): validate direct protocol enumeration input (#4405)

lyly414ad52b2093
diff --git a/src/application/EnhancedTools.inputValidation.test.ts b/src/application/EnhancedTools.inputValidation.test.ts
new file mode 100644
index 000000000..643ae1ca3
--- /dev/null
+++ b/src/application/EnhancedTools.inputValidation.test.ts
@@ -0,0 +1,63 @@
+import { describe, expect, it, vi } from "vitest";
+
+import {
+ createAnalysisExecution,
+ type AnalysisOperationPort,
+} from "./AnalysisProvider.js";
+import { EnhancedTools } from "./EnhancedTools.js";
+import { ok } from "../domain/result.js";
+
+const provider = { id: "fixture", name: "Fixture", version: "1" };
+
+describe("direct Objective-C protocol input validation", () => {
+ it.each([
+ { label: "extra property", input: { unexpected: "benign" } },
+ { label: "null", input: null },
+ { label: "undefined", input: undefined },
+ { label: "array", input: [] },
+ { label: "string", input: "protocols" },
+ ])("rejects $label before invoking the provider", async ({ input }) => {
+ const execute = vi
+ .fn<AnalysisOperationPort["execute"]>()
+ .mockResolvedValue(ok(createAnalysisExecution([], provider)));
+
+ const result = await new EnhancedTools({ execute }).execute(
+ "get_objc_protocols",
+ input,
+ );
+
+ expect(execute).not.toHaveBeenCalled();
+ expect(result).toMatchObject({
+ ok: false,
+ error: { _tag: "AnalysisInputError", operation: "get_objc_protocols" },
+ });
+ });
+
+ it.each([
+ { label: "empty", names: [], protocols: [] },
+ {
+ label: "populated",
+ names: [{ address: "0x1000", value: "__OBJC_PROTOCOL_$_Delegate" }],
+ protocols: [{ address: "0x1000", name: "__OBJC_PROTOCOL_$_Delegate" }],
+ },
+ ])(
+ "accepts an empty object with $label inventory",
+ async ({ names, protocols }) => {
+ const execute = vi
+ .fn<AnalysisOperationPort["execute"]>()
+ .mockResolvedValue(ok(createAnalysisExecution(names, provider)));
+
+ const result = await new EnhancedTools({ execute }).execute(
+ "get_objc_protocols",
+ {},
+ );
+
+ expect(execute).toHaveBeenCalledTimes(1);
+ expect(execute.mock.calls[0]?.[0]).toBe("list_names");
+ expect(result).toEqual({
+ ok: true,
+ value: { count: protocols.length, protocols },
+ });
+ },
+ );
+});
diff --git a/src/application/EnhancedTools.ts b/src/application/EnhancedTools.ts
index 8f0208e2b..7a22fd2cd 100644
--- a/src/application/EnhancedTools.ts
+++ b/src/application/EnhancedTools.ts
@@ -151,8 +151,12 @@ export class EnhancedTools {
? this.executeValidated({ name, input: parsed.data }, signal)
: invalidEnhancedInput(name, parsed.error);
}
- case "get_objc_protocols":
- return this.executeValidated({ name, input: {} }, signal);
+ case "get_objc_protocols": {
+ const parsed = enhancedInputSchemas.get_objc_protocols.safeParse(input);
+ return parsed.success
+ ? this.executeValidated({ name, input: parsed.data }, signal)
+ : invalidEnhancedInput(name, parsed.error);
+ }
case "batch_decompile": {
const parsed = enhancedInputSchemas.batch_decompile.safeParse(input);
return parsed.success