Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(swift): retain uncertainty for unsupported nested identifiers

morluto90e433df06b3
diff --git a/src/domain/swiftSymbolClassification.ts b/src/domain/swiftSymbolClassification.ts
index 04910e5c5..b04c921bc 100644
--- a/src/domain/swiftSymbolClassification.ts
+++ b/src/domain/swiftSymbolClassification.ts
@@ -38,7 +38,13 @@ export const classifySwiftSymbol = (
let category: SwiftTypeCategory | null = null;
for (;;) {
const end = identifierEnd(mangling, offset);
- if (end === undefined) break;
+ if (end === undefined) {
+ // A zero-prefixed identifier uses word substitutions or Punycode. We
+ // cannot tell whether it continues a nested type or names a member, so
+ // retaining the outer category would be a guess.
+ if (mangling.charAt(offset) === "0") category = null;
+ break;
+ }
const kind = mangling.charAt(end);
const nominal = NOMINAL_CATEGORIES.get(kind);
if (nominal === undefined) {
diff --git a/src/domain/symbolAnalysis.test.ts b/src/domain/symbolAnalysis.test.ts
index 995b69987..6930a60bf 100644
--- a/src/domain/symbolAnalysis.test.ts
+++ b/src/domain/symbolAnalysis.test.ts
@@ -52,6 +52,56 @@ describe("modern Swift category evidence", () => {
).toMatchObject({ total: 0, unclassified: [] });
});
+ it("preserves unsupported zero-prefixed nested Unicode contexts as unresolved", () => {
+ const names = [
+ "_$s6Nested8EnvelopeV007IhuqBAbO8describeSSyF",
+ "_$s6Nested8EnvelopeV007jvrtDBlCAEycfC",
+ "_$s6Nested8EnvelopeV007jvrtDBlCMa",
+ ];
+ const procedures = names.map((name, index) => ({
+ address: `0x${String(index + 1)}`,
+ name,
+ }));
+ const unresolved = names.map((name) => ({
+ name,
+ mangled_names: [name],
+ reason: "category_not_decoded",
+ }));
+ expect(categorizeSwiftTypes(procedures)).toMatchObject({
+ total: 3,
+ categories: {
+ other: {
+ items: names.map((name) => ({ name, mangled_names: [name] })),
+ },
+ },
+ unclassified: unresolved,
+ });
+
+ for (const category of ["classes", "enums"] as const)
+ expect(categorizeSwiftTypes(procedures, { category })).toMatchObject({
+ total: 0,
+ categories: { [category]: { count: 0 }, other: { count: 0 } },
+ unclassified: unresolved,
+ });
+ });
+
+ it("keeps outer and ASCII nested nominal categories decoded", () => {
+ const names = [
+ ["_$s6Nested8EnvelopeVMa", "structs"],
+ ["_$s6Nested8EnvelopeV5InnerCMa", "classes"],
+ ["_$s6Nested8EnvelopeV5InnerC6methodyyF", "classes"],
+ ] as const;
+ for (const [name, category] of names) {
+ expect(
+ categorizeSwiftTypes([{ address: "0x1", name }], { category }),
+ ).toMatchObject({
+ total: 1,
+ categories: { [category]: { count: 1 } },
+ unclassified: [],
+ });
+ }
+ });
+
it("deduplicates display names after selecting a category", () => {
expect(
categorizeSwiftTypes(
diff --git a/tests/boundary/mcp/enhancedTools.swiftTypes.test.ts b/tests/boundary/mcp/enhancedTools.swiftTypes.test.ts
index 128b9c281..82fc8d494 100644
--- a/tests/boundary/mcp/enhancedTools.swiftTypes.test.ts
+++ b/tests/boundary/mcp/enhancedTools.swiftTypes.test.ts
@@ -158,3 +158,72 @@ describe("Swift classification through MCP", () => {
).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } });
});
});
+
+describe("Swift category uncertainty through MCP", () => {
+ it("keeps unsupported nested Unicode names unresolved through MCP filters", async () => {
+ const names = [
+ "_$s6Nested8EnvelopeV007IhuqBAbO8describeSSyF",
+ "_$s6Nested8EnvelopeV007jvrtDBlCAEycfC",
+ "_$s6Nested8EnvelopeV007jvrtDBlCMa",
+ ];
+ const procedures = [
+ ...names.map((name, index) => ({
+ address: `0x${String(index + 1)}`,
+ value: name,
+ })),
+ { address: "0x10", value: "_$s6Nested8EnvelopeVMa" },
+ { address: "0x11", value: "_$s6Nested8EnvelopeV5InnerCMa" },
+ { address: "0x12", value: "_$s6Nested8EnvelopeV5InnerC6methodyyF" },
+ ];
+ const client = await connect({
+ execute: async (operation) =>
+ ok(operation === "list_procedures" ? procedures : []),
+ });
+
+ const all = jsonResult(
+ await client.callTool({
+ name: "analyze_swift_types",
+ arguments: {},
+ }),
+ );
+ expect(all).toMatchObject({
+ total: 6,
+ categories: {
+ structs: {
+ items: [{ name: "_$s6Nested8EnvelopeVMa" }],
+ },
+ classes: {
+ items: [
+ { name: "_$s6Nested8EnvelopeV5InnerCMa" },
+ { name: "_$s6Nested8EnvelopeV5InnerC6methodyyF" },
+ ],
+ },
+ other: {
+ items: names.map((name) => ({ name, mangled_names: [name] })),
+ },
+ },
+ unclassified: names.map((name) => ({
+ name,
+ mangled_names: [name],
+ reason: "category_not_decoded",
+ })),
+ });
+
+ for (const category of ["classes", "enums"] as const) {
+ const filtered = jsonResult(
+ await client.callTool({
+ name: "analyze_swift_types",
+ arguments: { category },
+ }),
+ );
+ expect(filtered).toMatchObject({
+ categories: { [category]: { count: category === "classes" ? 2 : 0 } },
+ unclassified: names.map((name) => ({
+ name,
+ mangled_names: [name],
+ reason: "category_not_decoded",
+ })),
+ });
+ }
+ });
+});