diff --git a/bridge/nativeaot/NativeAotExtension.java b/bridge/nativeaot/NativeAotExtension.java index 69d7c38ece..bae2414da9 100644 --- a/bridge/nativeaot/NativeAotExtension.java +++ b/bridge/nativeaot/NativeAotExtension.java @@ -11,17 +11,21 @@ import ghidra.program.model.listing.Program; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; import nativeaot.objectmodel.FrozenObjectAnnotator; +import nativeaot.objectmodel.MethodTable; import nativeaot.objectmodel.MethodTableCrawler; import nativeaot.objectmodel.MethodTableManager; import nativeaot.rehydration.MetadataRehydratorNet80; import nativeaot.rtr.ReadyToRunSection; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.security.MessageDigest; /** Optional headless facade over the unchanged upstream analysis primitives. */ public final class NativeAotExtension { private MethodTableManager manager; + private Map tablesByTypePath = Map.of(); private NativeAotDirectory.Located located; private JsonObject report; private final List diagnostics = new ArrayList<>(); @@ -82,13 +86,20 @@ public final class NativeAotExtension { if (coverage.get("frozen_objects_annotated").getAsInt() != coverage.get("frozen_object_candidates").getAsInt()) diagnostics.add("Some frozen-object candidates lack committed instance annotations; inspect coverage counts and Ghidra diagnostics."); JsonArray tables = new JsonArray(); + Map typeIndex = new HashMap<>(); for (var mt : manager.getMethodTables()) { monitor.checkCancelled(); + String mtPath = mt.getMTType().getPathName(); + typeIndex.putIfAbsent(mtPath, mt); + if (mt.getInstanceType() != null) { + typeIndex.putIfAbsent(mt.getInstanceType().getPathName(), mt); + } JsonObject identity = new JsonObject(); identity.addProperty("address", address(mt.getAddress())); - identity.addProperty("type", mt.getMTType().getPathName()); + identity.addProperty("type", mtPath); tables.add(identity); } + tablesByTypePath = typeIndex; // Publish recovery facts only after every fallible recovery and audit step. // A failed transaction is rolled back, so it cannot report committed metadata. report.addProperty("method_tables", manager.getMethodTableCount()); @@ -101,9 +112,11 @@ public final class NativeAotExtension { return finish(log); } catch (CancelledException ex) { manager = null; + tablesByTypePath = Map.of(); throw ex; } catch (Exception ex) { manager = null; + tablesByTypePath = Map.of(); diagnostics.add(stage + ": " + ex.getClass().getSimpleName() + ": " + ex.getMessage()); report.addProperty("status", ex instanceof UnsupportedOperationException ? "unsupported" : "failed"); report.addProperty("reason", stage + ": " + ex.getMessage()); @@ -131,7 +144,7 @@ public final class NativeAotExtension { /** Read recovered relationships without restoring or mutating database state. */ public JsonObject inspectDataType(Program program, DataType type, Address selected, TaskMonitor monitor) throws Exception { if (manager == null) return null; - return NativeAotTypeMetadata.describe(program, manager, located, type, report, derivedRange, monitor); + return NativeAotTypeMetadata.describe(program, manager, tablesByTypePath, located, type, report, derivedRange, monitor); } private JsonObject auditFrozenObjects(Program program, Address[] pointerLocations, TaskMonitor monitor) throws Exception { diff --git a/bridge/nativeaot/NativeAotTypeMetadata.java b/bridge/nativeaot/NativeAotTypeMetadata.java index 8b029aca98..a7d7533e70 100644 --- a/bridge/nativeaot/NativeAotTypeMetadata.java +++ b/bridge/nativeaot/NativeAotTypeMetadata.java @@ -8,55 +8,53 @@ import ghidra.program.model.listing.Program; import ghidra.util.task.TaskMonitor; import nativeaot.objectmodel.MethodTable; import nativeaot.objectmodel.MethodTableManager; +import java.util.Map; /** Translate a selected recovered type into provider-neutral metadata evidence. */ final class NativeAotTypeMetadata { - static JsonObject describe(Program program, MethodTableManager manager, NativeAotDirectory.Located located, - DataType type, JsonObject report, JsonObject derivedRange, TaskMonitor monitor) throws Exception { - for (MethodTable table : manager.getMethodTables()) { + static JsonObject describe(Program program, MethodTableManager manager, Map tablesByTypePath, + NativeAotDirectory.Located located, DataType type, JsonObject report, JsonObject derivedRange, + TaskMonitor monitor) throws Exception { + monitor.checkCancelled(); + MethodTable table = tablesByTypePath.get(type.getPathName()); + if (table == null) return null; + JsonObject result = new JsonObject(); + result.addProperty("format", "dotnet-nativeaot"); + result.addProperty("status", report.get("status").getAsString()); + result.addProperty("header_address", NativeAotExtension.address(located.address())); + result.addProperty("format_major", located.directory().getMajorVersion()); + result.addProperty("format_minor", located.directory().getMinorVersion()); + result.addProperty("method_table_address", NativeAotExtension.address(table.getAddress())); + result.addProperty("name_origin", table == manager.getObjectMT() || table == manager.getStringMT() ? "inferred" : "generated"); + result.add("original_name", JsonNull.INSTANCE); + result.addProperty("base_size_bytes", table.getBaseSize()); + result.add("related_type", identity(manager, table.getRelatedTypeAddress())); + JsonArray interfaces = new JsonArray(); + for (long value : table.getInterfaceAddresses()) if (value != 0) interfaces.add(identity(manager, value)); + result.add("interfaces", interfaces); + JsonArray slots = new JsonArray(); + for (int slot = 0; slot < table.getVTableSlotCount(); slot++) { monitor.checkCancelled(); - boolean sameType = type.getPathName().equals(table.getMTType().getPathName()) || - (table.getInstanceType() != null && type.getPathName().equals(table.getInstanceType().getPathName())); - if (!sameType) continue; - JsonObject result = new JsonObject(); - result.addProperty("format", "dotnet-nativeaot"); - result.addProperty("status", report.get("status").getAsString()); - result.addProperty("header_address", NativeAotExtension.address(located.address())); - result.addProperty("format_major", located.directory().getMajorVersion()); - result.addProperty("format_minor", located.directory().getMinorVersion()); - result.addProperty("method_table_address", NativeAotExtension.address(table.getAddress())); - result.addProperty("name_origin", table == manager.getObjectMT() || table == manager.getStringMT() ? "inferred" : "generated"); - result.add("original_name", JsonNull.INSTANCE); - result.addProperty("base_size_bytes", table.getBaseSize()); - result.add("related_type", identity(manager, table.getRelatedTypeAddress())); - JsonArray interfaces = new JsonArray(); - for (long value : table.getInterfaceAddresses()) if (value != 0) interfaces.add(identity(manager, value)); - result.add("interfaces", interfaces); - JsonArray slots = new JsonArray(); - for (int slot = 0; slot < table.getVTableSlotCount(); slot++) { - monitor.checkCancelled(); - long value = table.getVTableSlot(slot); - JsonObject target = new JsonObject(); - target.addProperty("slot", slot); - target.addProperty("slot_address", NativeAotExtension.address(table.getAddress().add(24 + slot * 8L))); - target.add("target_address", value == 0 ? JsonNull.INSTANCE : new com.google.gson.JsonPrimitive("0x" + Long.toUnsignedString(value, 16))); - var function = value == 0 ? null : program.getFunctionManager().getFunctionAt(table.getAddress().getNewAddress(value)); - target.add("procedure_name", function == null ? JsonNull.INSTANCE : new com.google.gson.JsonPrimitive(function.getName(true))); - target.addProperty("basis", "method-table-pointer"); - slots.add(target); - } - result.add("virtual_slots", slots); - result.add("derived_memory", derivedRange.deepCopy()); - result.add("diagnostics", report.get("diagnostics").deepCopy()); - JsonArray limitations = new JsonArray(); - limitations.add("Type identities and relationships are recovered by upstream heuristics. Original source names and custom field layouts are not recovered."); - limitations.add("Method prototypes are inferred, not original signatures. REA preserves pre-recovery calling conventions and the loaded compiler default for new functions."); - limitations.add("Rehydrated metadata bytes are derived analysis-memory content; their original file offsets and runtime behavior remain unknown."); - limitations.add("Verified workflow: .NET 8.0.22 NativeAOT RTR 9.1, Linux x64 ELF / Windows x64 PE on Linux; other runtime layouts and hosts are unverified."); - result.add("limitations", limitations); - return result; + long value = table.getVTableSlot(slot); + JsonObject target = new JsonObject(); + target.addProperty("slot", slot); + target.addProperty("slot_address", NativeAotExtension.address(table.getAddress().add(24 + slot * 8L))); + target.add("target_address", value == 0 ? JsonNull.INSTANCE : new com.google.gson.JsonPrimitive("0x" + Long.toUnsignedString(value, 16))); + var function = value == 0 ? null : program.getFunctionManager().getFunctionAt(table.getAddress().getNewAddress(value)); + target.add("procedure_name", function == null ? JsonNull.INSTANCE : new com.google.gson.JsonPrimitive(function.getName(true))); + target.addProperty("basis", "method-table-pointer"); + slots.add(target); } - return null; + result.add("virtual_slots", slots); + result.add("derived_memory", derivedRange.deepCopy()); + result.add("diagnostics", report.get("diagnostics").deepCopy()); + JsonArray limitations = new JsonArray(); + limitations.add("Type identities and relationships are recovered by upstream heuristics. Original source names and custom field layouts are not recovered."); + limitations.add("Method prototypes are inferred, not original signatures. REA preserves pre-recovery calling conventions and the loaded compiler default for new functions."); + limitations.add("Rehydrated metadata bytes are derived analysis-memory content; their original file offsets and runtime behavior remain unknown."); + limitations.add("Verified workflow: .NET 8.0.22 NativeAOT RTR 9.1, Linux x64 ELF / Windows x64 PE on Linux; other runtime layouts and hosts are unverified."); + result.add("limitations", limitations); + return result; } private static com.google.gson.JsonElement identity(MethodTableManager manager, long value) throws Exception { diff --git a/src/apktool/ApktoolProvider.ts b/src/apktool/ApktoolProvider.ts index 8af35b7549..5533e76a1a 100644 --- a/src/apktool/ApktoolProvider.ts +++ b/src/apktool/ApktoolProvider.ts @@ -38,7 +38,6 @@ import { import { providerConfigurationRefusal } from "../domain/providerConfigurationRefusal.js"; import { createAnalysisExecutionEvidence } from "../domain/analysisObservation.js"; import { - apktoolResultSchemas, apktoolStringTablesRequested, DEFAULT_APKTOOL_DECODE_TIMEOUT_MS, type ApktoolRequest, @@ -704,14 +703,10 @@ export class ApktoolProvider { completedDecode.coverage = coverage; if (!projection.ok) throw projection.error.cause; result = ok( - createAnalysisExecution( - apktoolResultSchemas.decode_android_resources.parse(completedDecode), - provider, - { - subject: { path: input.path, sha256, format: "apk" }, - limitations, - }, - ), + createAnalysisExecution(completedDecode, provider, { + subject: { path: input.path, sha256, format: "apk" }, + limitations, + }), ); } catch (cause) { const { cause: physical, origin } = artifactFilePrimaryFacts(cause);