Files
reverse-engineering-anything/src/domain/native/nativeInventory.ts
T
Kaoru0822andClaude Opus 5.5 44b6384009 fix(native): find procedures by the secondary names exact lookup accepts (#8520)
* fix(native): find procedures by the secondary names exact lookup accepts

search_procedures matched only each procedure's primary name, while exact
lookup also accepts Kuna inventory aliases (versioned-symbol and generated
sub_ names) and Ghidra symbols at an exact function entry. A search for a
name procedure_address resolves returned nothing, and trace_feature
silently missed the procedure.

Both providers now match the same names their exact lookup accepts. A
procedure still appears once under its primary name; the optional
matched_aliases field lists the secondary names that matched, so aliases
never become procedures of their own and list_procedures is unchanged.
The shared domain helper owns that row rule for Kuna and for the Ghidra
host-side Unicode folding pass. The Ghidra analysis profile records the
new search semantics so older snapshots cannot replay alias-blind results.

Fixes #8330

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ghidra): match leaf spellings of procedure names in search

procedure_address accepts each entry symbol's leaf or namespace-qualified
spelling, but procedure search tested only qualified names, so a regex
such as ^audit_alias$ missed a secondary symbol ns::audit_alias (and ^same$
missed a primary alpha::same) that exact lookup selects.

Lookup and search now share one bridge definition of the names that select
a procedure, so they cannot drift. Matching secondary symbols are still
reported by their qualified names; because a leaf ends its qualified
spelling, the host's Unicode literal pass stays exact over those names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 08:53:29 -08:00

89 lines
2.8 KiB
TypeScript

import { z } from "zod";
import { nativeSymbolMetadataSchema } from "./nativeSymbol.js";
import { analysisStringSchema } from "./nativeString.js";
import { ok, type Result } from "../result.js";
import { AnalysisOutputError } from "../analysisErrorCore.js";
import type { JsonValue } from "../jsonValue.js";
import { invalidNativeOutput } from "./nativeProviderOutput.js";
/** Canonical named native observations; same-address alternatives stay separate. */
export const addressedValueSchema = z.object({
address: z.string(),
value: z.string(),
symbol: nativeSymbolMetadataSchema.exactOptional(),
objc_class_label: z.literal("hopper_legacy_class_object").exactOptional(),
procedure: z
.object({
external: z.boolean(),
thunk: z.boolean(),
thunk_target: z.string().nullable(),
})
.exactOptional(),
string: z
.object({
encoding: z.string(),
termination: z.enum(["missing", "present_or_not_required"]),
byte_length: z.number().int().min(0),
})
.exactOptional(),
matched_aliases: z
.array(z.string())
.min(1)
.exactOptional()
.describe(
"Procedure search only: the procedure's secondary names that matched. value stays its primary name.",
),
});
/** Canonical row arrays shared by complete delivery and retained source validation. */
export const nativeInventoryRowsSchemas = {
names: z.array(addressedValueSchema),
strings: z.array(analysisStringSchema),
};
export const NATIVE_INVENTORY_OPERATIONS = [
"list_procedures",
"search_procedures",
"list_strings",
"search_strings",
"list_names",
] as const;
export const nativeInventoryOperationSchema = z.enum(
NATIVE_INVENTORY_OPERATIONS,
);
export type NativeInventoryOperation = z.infer<
typeof nativeInventoryOperationSchema
>;
export const isNativeInventoryOperation = (
operation: string,
): operation is NativeInventoryOperation =>
NATIVE_INVENTORY_OPERATIONS.some((supported) => supported === operation);
export interface AddressedName {
readonly address: string;
readonly name: string;
readonly objc_class_label?: "hopper_legacy_class_object";
}
/** An analyzed bookmark retains a missing provider label as null. */
export const analysisBookmarkSchema = z.strictObject({
address: z.string(),
name: z.string().nullable(),
});
/** Count only complete canonical inventories, using the advertised row contracts. */
export const parseNativeInventoryCount = (
value: JsonValue,
operation: "list_procedures" | "list_strings",
): Result<number, AnalysisOutputError> => {
const schema =
operation === "list_procedures"
? nativeInventoryRowsSchemas.names
: nativeInventoryRowsSchemas.strings;
const parsed = schema.safeParse(value);
return parsed.success
? ok(parsed.data.length)
: invalidNativeOutput(operation, "inventory rows", parsed.error);
};