Add support for generating PDBs from NativeAOT libraries

Aperta
#3,649 5 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
28/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp

Direzione di ricerca

Inizia dalle sorgenti NativeFormat di .NET runtime, in particolare NativeMetadataReader.cs, MetadataBlob.cs e la voce ReflectionMapBlob.EmbeddedMetadata del ReadyToRun header. Determina come ILSpy possa individuare e leggere i metadati di reflection di NativeAOT nelle versioni di .NET supportate, quindi definisci test o librerie di esempio che dimostrino che tali metadati possono essere scaricati o utilizzati per generare un PDB. Il lavoro è completato quando le librerie NativeAOT vengono gestite con limiti di versione documentati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Enhancement

Is your feature request related to a problem? Please describe.
Currently, ILSpy cannot do anything with NativeAOT libraries. NativeAOT libraries have all the functions compiled to native binary code, which means that adding support for decompiling them would be out-of-scope for this project, but the reflection metadata is still present in the library, so perhaps we could add support for generating a PDB for them, or at least dumping the metadata somehow.

Additional context
No reverse-engineering tool currently implements dumping the reflection metadata from NativeAOT libraries, so if we were to pursue this, we'd have to implement that. There is a ghidra plugin that implements mapping the method tables to the function locations, but has no support for reading the reflection metadata.

The main place to look at for starting to implement that is here: https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/Common/Internal/Metadata/NativeFormat

They store the reflection metadata in a blob that's referenced in the ReadyToRun header at ID 313 (ReadOnlyBlobStart + ReflectionMapBlob.EmbeddedMetadata)

Theorietically, if you have the correct dotnet version, all you'd need to do is instantiate a MetadataReader with a pointer to the EmbeddedMetadata blob that you'd get from the ReadyToRun header, but they don't expose that that class or constructor because it's in an internal namespace, so we'd probably have to make copies of the reflection library.

The biggest problem we'd face is that the reflection metadata format changes between dotnet versions (and they don't update the signature to reflect breaking changes). For example, I know that .net 10 is not compatible with .net 8 and 9.

More info on how the ReadyToRun header is constructed and its location in the NativeAOT binary can be located here: https://migeel.sk/blog/2023/09/15/reverse-engineering-natively-compiled-dotnet-apps/

I'm interested in pursuing this if y'all are interested and can provide some guidance, please let me know.

Lingua principale
C#
Stelle
27.1k
Fork
3.8k
Merge medio
1g 23h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/ILSpy

Tutte le issue di icsharpcode/ILSpy

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.