feat(ghidra): integrate optional NativeAOT metadata recovery (#748)
* feat(ghidra): integrate optional NativeAOT metadata recovery * fix(ghidra): bind extension snapshots to configured artifacts * test(ghidra): verify lazy NativeAOT startup failures * fix(ghidra): preserve NativeAOT failure reasons and coverage * fix(ghidra): preserve NativeAOT x64 calling conventions * test(ghidra): guard recovered NativeAOT method conventions * fix(ghidra): reject blocking extension file inputs * fix(ghidra): diagnose incompatible NativeAOT extension classes * test(ghidra): verify real extension initialization failures * fix(ghidra): keep extension descriptor fields optional
This commit is contained in:
@@ -199,7 +199,14 @@ describe("analysis error projection: caller contract", () => {
|
||||
"capability_unavailable",
|
||||
"target_unavailable",
|
||||
]);
|
||||
expect(projected[1]).toMatchObject({ category: "unsupported_provider" });
|
||||
expect(projected[1]).toMatchObject({
|
||||
category: "unsupported_provider",
|
||||
details: {
|
||||
provider_id: "fixture",
|
||||
operation: "overview",
|
||||
reason: "absent",
|
||||
},
|
||||
});
|
||||
expect(projected[2]).toMatchObject({
|
||||
details: { path: "/local/targets/app" },
|
||||
});
|
||||
|
||||
@@ -227,7 +227,11 @@ const providerErrorDetails = (
|
||||
error: AnalysisError,
|
||||
): Readonly<Record<string, JsonValue>> | undefined => {
|
||||
if (error instanceof AnalysisCapabilityUnavailableError)
|
||||
return { provider_id: error.providerId, operation: error.operation };
|
||||
return {
|
||||
provider_id: error.providerId,
|
||||
operation: error.operation,
|
||||
reason: error.reason,
|
||||
};
|
||||
if (error instanceof ProviderSelectionError)
|
||||
return {
|
||||
operation: error.operation,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { nativeMetadataRecoverySchema } from "./nativeMetadataRecovery.js";
|
||||
|
||||
/** Select a database type by exact category path or a defined typed data address. */
|
||||
export const nativeDataTypeInputSchema = z
|
||||
@@ -54,4 +55,5 @@ export const nativeDataTypeSchema = z.strictObject({
|
||||
total_fields: z.number().int().nonnegative(),
|
||||
truncated: z.boolean(),
|
||||
limitations: z.array(z.string()),
|
||||
metadata_recovery: nativeMetadataRecoverySchema.optional(),
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { nativeMetadataRecoverySummarySchema } from "./nativeMetadataRecovery.js";
|
||||
import { jsonValueSchema } from "./jsonValue.js";
|
||||
|
||||
const integer = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
||||
@@ -8,6 +9,7 @@ const address = z.string().min(1);
|
||||
|
||||
/** Measured provider image, without exporting the complete executable bytes. */
|
||||
export const nativeLoadImageObservationSchema = z.strictObject({
|
||||
metadata_recovery: z.array(nativeMetadataRecoverySummarySchema).optional(),
|
||||
executable_format: z.string().min(1),
|
||||
language_id: z.string().min(1),
|
||||
compiler_spec_id: z.string().min(1),
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
nativeMetadataRecoverySchema,
|
||||
nativeMetadataRecoverySummarySchema,
|
||||
} from "./nativeMetadataRecovery.js";
|
||||
import { jsonValueSchema } from "./jsonValue.js";
|
||||
|
||||
const metadata = {
|
||||
format: "dotnet-nativeaot",
|
||||
status: "partial",
|
||||
header_address: "0x401000",
|
||||
format_major: 9,
|
||||
format_minor: 1,
|
||||
method_table_address: "0x402000",
|
||||
name_origin: "generated",
|
||||
original_name: null,
|
||||
base_size_bytes: 24,
|
||||
related_type: { address: "0x403000", type: null },
|
||||
interfaces: [],
|
||||
virtual_slots: [
|
||||
{
|
||||
slot: 0,
|
||||
slot_address: "0x402018",
|
||||
target_address: null,
|
||||
procedure_name: null,
|
||||
basis: "method-table-pointer",
|
||||
},
|
||||
],
|
||||
derived_memory: {
|
||||
address: "0x402000",
|
||||
size_bytes: 128,
|
||||
sha256: "a".repeat(64),
|
||||
file_offset: null,
|
||||
},
|
||||
diagnostics: ["candidate annotation missing"],
|
||||
limitations: ["Names are generated; original fields unknown"],
|
||||
};
|
||||
describe("NativeAOT recovery evidence", () => {
|
||||
it("preserves generated identities, unresolved relationships and null virtual targets", () => {
|
||||
expect(
|
||||
jsonValueSchema.parse(nativeMetadataRecoverySchema.parse(metadata)),
|
||||
).toEqual(metadata);
|
||||
});
|
||||
it("rejects invented source authority and original file offsets for derived memory", () => {
|
||||
expect(
|
||||
nativeMetadataRecoverySchema.safeParse({
|
||||
...metadata,
|
||||
original_name: "InventedClass",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
nativeMetadataRecoverySchema.safeParse({
|
||||
...metadata,
|
||||
derived_memory: { ...metadata.derived_memory, file_offset: 128 },
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
it("keeps a negative discovery explicit without fabricating a header", () => {
|
||||
const summary = {
|
||||
format: "dotnet-nativeaot",
|
||||
status: "not_applicable",
|
||||
reason: "No supported row layout found",
|
||||
analysis_artifact_sha256: "b".repeat(64),
|
||||
header_address: null,
|
||||
discovery: null,
|
||||
format_major: null,
|
||||
format_minor: null,
|
||||
method_tables: 0,
|
||||
types: [],
|
||||
derived_memory: null,
|
||||
coverage: null,
|
||||
diagnostics: [],
|
||||
limitations: [],
|
||||
};
|
||||
expect(nativeMetadataRecoverySummarySchema.parse(summary)).toEqual(summary);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const address = z.string().regex(/^0x[0-9a-f]+$/u);
|
||||
const relatedType = z.strictObject({ address, type: z.string().nullable() });
|
||||
|
||||
/** Runtime-format metadata recovered in an analysis image, with explicit inference boundaries. */
|
||||
export const nativeMetadataRecoverySchema = z.strictObject({
|
||||
format: z.literal("dotnet-nativeaot"),
|
||||
status: z.enum(["complete", "partial"]),
|
||||
header_address: address,
|
||||
format_major: z.number().int().nonnegative(),
|
||||
format_minor: z.number().int().nonnegative(),
|
||||
method_table_address: address,
|
||||
name_origin: z.enum(["generated", "inferred"]),
|
||||
original_name: z.null(),
|
||||
base_size_bytes: z.number().int().nonnegative(),
|
||||
related_type: relatedType.nullable(),
|
||||
interfaces: z.array(relatedType),
|
||||
virtual_slots: z.array(
|
||||
z.strictObject({
|
||||
slot: z.number().int().nonnegative(),
|
||||
slot_address: address,
|
||||
target_address: address.nullable(),
|
||||
procedure_name: z.string().nullable(),
|
||||
basis: z.literal("method-table-pointer"),
|
||||
}),
|
||||
),
|
||||
derived_memory: z.strictObject({
|
||||
address,
|
||||
size_bytes: z.number().int().nonnegative(),
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
file_offset: z.null(),
|
||||
}),
|
||||
diagnostics: z.array(z.string()),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
/** Discover a recovered runtime format and reusable type identities from the loaded image. */
|
||||
export const nativeMetadataRecoverySummarySchema = z.strictObject({
|
||||
format: z.literal("dotnet-nativeaot"),
|
||||
status: z.enum(["complete", "partial", "not_applicable"]),
|
||||
reason: z.string().nullable(),
|
||||
analysis_artifact_sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
header_address: address.nullable(),
|
||||
discovery: z.enum(["symbol", "signature-heuristic"]).nullable(),
|
||||
format_major: z.number().int().nonnegative().nullable(),
|
||||
format_minor: z.number().int().nonnegative().nullable(),
|
||||
method_tables: z.number().int().nonnegative(),
|
||||
types: z.array(relatedType),
|
||||
derived_memory: nativeMetadataRecoverySchema.shape.derived_memory.nullable(),
|
||||
coverage: z
|
||||
.strictObject({
|
||||
frozen_object_candidates: z.number().int().nonnegative(),
|
||||
frozen_objects_annotated: z.number().int().nonnegative(),
|
||||
basis: z.literal(
|
||||
"rehydrated-pointer-candidates-and-committed-instance-types",
|
||||
),
|
||||
})
|
||||
.nullable(),
|
||||
diagnostics: z.array(z.string()),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
Reference in New Issue
Block a user