fix(hopper): preserve partial native call and string evidence

This commit is contained in:
morluto
2026-10-09 05:12:36 +08:00
parent 0a49d5bfb9
commit 246170238e
11 changed files with 188 additions and 77 deletions
+2 -2
View File
@@ -174,7 +174,7 @@ export const OFFICIAL_TOOL_CONTRACTS = [
),
official(
"procedure_references",
"Return every raw incoming or outgoing reference edge for one procedure. Endpoint procedures are resolved only from provider containment; Ghidra preserves observed reference kinds while providers without kind authority mark them unavailable.",
"Return every raw incoming or outgoing reference edge for one procedure. Endpoint procedures are resolved only from provider containment. Ghidra preserves detailed reference flags. Hopper preserves native CallReference classifications and exact endpoints while leaving unavailable detailed flags explicit.",
z.object({
procedure,
direction: z.enum(["incoming", "outgoing"]).default("outgoing"),
@@ -198,7 +198,7 @@ export const OFFICIAL_TOOL_CONTRACTS = [
),
official(
"search_strings",
"Search every analyzed string object using literal matching by default or regex when requested. Results are deterministic and complete over the native inventory. Hopper searches complete typed bytes rather than shortened displays; adjacent fragments of a long literal are matched independently, with their termination and original display retained.",
"Search every analyzed string object using literal matching by default or regex when requested. Results are deterministic and complete over the native inventory. Hopper retains typed byte decoding, native display, and explicit decoding unknowns. Adjacent long-literal fragments match independently.",
z.object(analysisSearchInput),
),
official(
+7 -39
View File
@@ -20,7 +20,9 @@ import {
import {
analysisBookmarkSchema,
functionInstructionWindowSchema,
referenceKindSchema,
referenceEdgeSchema,
unresolvedCallSchema,
analysisStringSchema,
} from "../domain/hopperValues.js";
import { nativeApiInspectionResultSchema } from "../domain/native/nativeApiBoundary.js";
import {
@@ -94,30 +96,6 @@ const bookmarkFacetSchema = z.discriminatedUnion("state", [
}),
]);
const addressedString = z.object({
address: z.string(),
value: z.string(),
provider_value: z
.string()
.exactOptional()
.describe(
"Original provider display text, which may shorten the typed object.",
),
string: z
.object({
encoding: z.string().min(1),
encoding_status: z
.enum(["observed", "inferred"])
.exactOptional()
.describe(
"Whether the provider declares the encoding or REA infers it from the typed bytes and native display. This does not establish the original source's intended encoding.",
),
termination: z.enum(["missing", "present_or_not_required"]),
byte_length: z.number().int().min(0),
})
.optional(),
});
/** Exact structured-content schemas shared by direct analysis providers. */
export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
annotate_native_function: resultOf(nativeFunctionAnnotationsSchema),
@@ -137,7 +115,7 @@ export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
list_names: resultOf(z.array(addressedValue)),
list_procedures: resultOf(z.array(addressedValue)),
list_segments: segmentOutput,
list_strings: resultOf(z.array(addressedString)),
list_strings: resultOf(z.array(analysisStringSchema)),
next_address: resultOf(z.string()),
prev_address: resultOf(z.string()),
procedure_address: resultOf(z.string()),
@@ -190,18 +168,8 @@ export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
procedure: procedureIdentity,
direction: z.enum(["incoming", "outgoing"]),
reference_kinds_available: z.boolean().optional(),
unresolved_calls: z
.array(z.object({ address: z.string(), reason: z.string() }))
.default([]),
references: z.array(
z.object({
source_address: z.string(),
target_address: z.string(),
source_procedure: procedureIdentity.nullable(),
target_procedure: procedureIdentity.nullable(),
kind: referenceKindSchema,
}),
),
unresolved_calls: z.array(unresolvedCallSchema).default([]),
references: z.array(referenceEdgeSchema),
}),
),
procedure_pseudo_code: resultOf(nullableText),
@@ -209,7 +177,7 @@ export const officialOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
search_procedures: resultOf(
z.array(z.object({ address: z.string(), value: z.string() })),
),
search_strings: resultOf(z.array(addressedString)),
search_strings: resultOf(z.array(analysisStringSchema)),
set_address_name: resultOf(z.boolean()),
set_addresses_names: resultOf(z.record(z.string(), z.boolean())),
set_bookmark: resultOf(z.boolean()),
+47 -8
View File
@@ -62,6 +62,36 @@ const segmentSchema = z.object({
const unavailableAnalysisFactSchema = z
.object({ available: z.literal(false), reason: z.string() })
.strict();
/** Typed string evidence shared by inventories and referenced function literals. */
export const analysisStringSchema = z.object({
address: z.string(),
value: z.string(),
provider_value: z
.string()
.exactOptional()
.describe(
"Original provider display text, which may shorten the typed object.",
),
decoding: unavailableAnalysisFactSchema
.exactOptional()
.describe(
"When present, value retains native display text because typed bytes could not be decoded.",
),
string: z
.object({
encoding: z.string().min(1),
encoding_status: z
.enum(["observed", "inferred"])
.exactOptional()
.describe(
"Whether the provider declares the encoding or REA infers it from the typed bytes and native display. This does not establish the original source's intended encoding.",
),
termination: z.enum(["missing", "present_or_not_required"]),
byte_length: z.number().int().min(0),
})
.exactOptional(),
});
/** An analyzed bookmark retains a missing provider label as null. */
export const analysisBookmarkSchema = z.strictObject({
address: z.string(),
@@ -256,13 +286,27 @@ export const referenceKindSchema = z.discriminatedUnion("available", [
unavailableAnalysisFactSchema,
availableReferenceKindSchema,
]);
const referenceEdgeSchema = z
/** Reported call sites without resolved targets; unreported dispatch stays unknown. */
export const unresolvedCallSchema = z.strictObject({
address: z.string(),
reason: z.string(),
});
/** Observed endpoints with complete or partial reference classification evidence. */
export const referenceEdgeSchema = z
.object({
source_address: z.string(),
target_address: z.string(),
source_procedure: procedureIdentitySchema.nullable(),
target_procedure: procedureIdentitySchema.nullable(),
kind: referenceKindSchema,
call: z
.strictObject({
classification: z.enum(["none", "unknown", "direct", "objective_c"]),
provider_type: z.number().int(),
provenance: z.string().min(1),
})
.exactOptional(),
})
.strict();
export const functionDossierSchema = z
@@ -286,14 +330,9 @@ export const functionDossierSchema = z
callees: z.array(procedureIdentitySchema),
incoming_references: z.array(referenceEdgeSchema),
outgoing_references: z.array(referenceEdgeSchema),
unresolved_calls: z.array(unresolvedCallSchema).exactOptional(),
referenced_strings: z.array(
z
.object({
address: z.string(),
value: z.string(),
source_address: z.string(),
})
.strict(),
analysisStringSchema.extend({ source_address: z.string() }),
),
referenced_names: z.array(
z
+1 -1
View File
@@ -253,7 +253,7 @@ export class HopperProvider implements AnalysisProviderCandidate {
: []),
...(operation === "procedure_references"
? [
"Hopper's public Python API does not expose flow classification for calls without resolved targets; unresolved_calls is empty and its coverage is unknown.",
"Native CallReference classifications and unresolved targets are preserved. Detailed reference flags and coverage beyond reported CallReference objects remain unknown.",
]
: []),
],
+4 -1
View File
@@ -79,9 +79,12 @@ export const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
}),
limitations: Object.freeze([
"Results depend on Hopper's completed static analysis.",
...(operation === "list_strings" || operation === "search_strings"
...(operation === "list_strings" ||
operation === "search_strings" ||
operation === "analyze_function"
? [
"String values cover native typed objects. Hopper may split long literals into adjacent unterminated fragments; string searches match each object independently.",
"Undecodable typed objects retain native display text with an explicit decoding unknown; these values do not establish decoded source literals.",
"Reported string encodings are inferred from typed bytes and native display; the original source's intended encoding is unknown.",
]
: []),