33// See the LICENSE file in the project root for more information.
44
55using System ;
6+ using System . Collections . Generic ;
7+ using System . Reflection . PortableExecutable ;
68using System . Text ;
79
810namespace R2RDump
911{
1012 struct R2RImportSection
1113 {
12- public enum ImportSectionType
14+ public enum CorCompileImportType
1315 {
14- READYTORUN_IMPORT_SECTION_TYPE_UNKNOWN = 0 ,
16+ CORCOMPILE_IMPORT_TYPE_UNKNOWN = 0 ,
17+ CORCOMPILE_IMPORT_TYPE_EXTERNAL_METHOD = 1 ,
18+ CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH = 2 ,
19+ CORCOMPILE_IMPORT_TYPE_STRING_HANDLE = 3 ,
20+ CORCOMPILE_IMPORT_TYPE_TYPE_HANDLE = 4 ,
21+ CORCOMPILE_IMPORT_TYPE_METHOD_HANDLE = 5 ,
22+ CORCOMPILE_IMPORT_TYPE_VIRTUAL_METHOD = 6 ,
1523 } ;
1624
17- public enum ImportSectionFlags
25+ public enum CorCompileImportFlags
1826 {
19- READYTORUN_IMPORT_SECTION_FLAGS_EAGER = 0x0001 ,
27+ CORCOMPILE_IMPORT_FLAGS_EAGER = 0x0001 , // Section at module load time.
28+ CORCOMPILE_IMPORT_FLAGS_CODE = 0x0002 , // Section contains code.
29+ CORCOMPILE_IMPORT_FLAGS_PCODE = 0x0004 , // Section contains pointers to code.
2030 } ;
2131
32+ public struct ImportSectionEntry
33+ {
34+ public long Section { get ; }
35+ public uint SignatureRVA { get ; }
36+ public uint Signature { get ; }
37+ public ImportSectionEntry ( long section , uint signatureRVA , uint signature )
38+ {
39+ Section = section ;
40+ SignatureRVA = signatureRVA ;
41+ Signature = signature ;
42+ }
43+
44+ public override string ToString ( )
45+ {
46+ StringBuilder sb = new StringBuilder ( ) ;
47+ sb . AppendLine ( $ "\t Section: 0x{ Section : X8} ({ Section } )") ;
48+ sb . AppendLine ( $ "\t SignatureRVA: 0x{ SignatureRVA : X8} ({ SignatureRVA } )") ;
49+ sb . AppendLine ( $ "\t Section: 0x{ Signature : X8} ({ Signature } )") ;
50+ return sb . ToString ( ) ;
51+ }
52+ }
53+
2254 /// <summary>
2355 /// Section containing values to be fixed up
2456 /// </summary>
@@ -28,12 +60,12 @@ public enum ImportSectionFlags
2860 /// <summary>
2961 /// One or more of ImportSectionFlags
3062 /// </summary>
31- public ushort Flags { get ; }
63+ public CorCompileImportFlags Flags { get ; }
3264
3365 /// <summary>
3466 /// One of ImportSectionType
3567 /// </summary>
36- public ImportSectionType Type { get ; }
68+ public CorCompileImportType Type { get ; }
3769
3870 /// <summary>
3971 ///
@@ -43,34 +75,49 @@ public enum ImportSectionFlags
4375 /// <summary>
4476 /// RVA of optional signature descriptors
4577 /// </summary>
46- public int Signatures { get ; }
78+ public int SignatureRVA { get ; }
79+ public List < ImportSectionEntry > Entries { get ; }
4780
4881 /// <summary>
4982 /// RVA of optional auxiliary data (typically GC info)
5083 /// </summary>
51- public int AuxiliaryData { get ; }
84+ public int AuxiliaryDataRVA { get ; }
85+ public GcInfo AuxiliaryData { get ; }
5286
53- public R2RImportSection ( int rva , int size , ushort flags , byte type , byte entrySize , int sig , int data )
87+ public R2RImportSection ( byte [ ] image , int rva , int size , CorCompileImportFlags flags , byte type , byte entrySize , int signatureRVA , List < ImportSectionEntry > entries , int auxDataRVA , int auxDataOffset , Machine machine , ushort majorVersion )
5488 {
5589 SectionRVA = rva ;
5690 SectionSize = size ;
5791 Flags = flags ;
58- Type = ( ImportSectionType ) type ;
92+ Type = ( CorCompileImportType ) type ;
5993 EntrySize = entrySize ;
60- Signatures = sig ;
61- AuxiliaryData = data ;
94+
95+ SignatureRVA = signatureRVA ;
96+ Entries = entries ;
97+
98+ AuxiliaryDataRVA = auxDataRVA ;
99+ AuxiliaryData = null ;
100+ if ( AuxiliaryDataRVA != 0 )
101+ {
102+ AuxiliaryData = new GcInfo ( image , auxDataOffset , machine , majorVersion ) ;
103+ }
62104 }
63105
64106 public override string ToString ( )
65107 {
66108 StringBuilder sb = new StringBuilder ( ) ;
67- sb . AppendLine ( $ "SectionRVA: 0x{ SectionRVA : X8} ") ;
109+ sb . AppendLine ( $ "SectionRVA: 0x{ SectionRVA : X8} ( { SectionRVA } ) ") ;
68110 sb . AppendLine ( $ "SectionSize: { SectionSize } bytes") ;
69- sb . AppendLine ( $ "Flags: { Enum . GetName ( typeof ( ImportSectionFlags ) , Flags ) } ( { Flags } ) ") ;
111+ sb . AppendLine ( $ "Flags: { Flags } ") ;
70112 sb . AppendLine ( $ "Type: { Type } ") ;
71113 sb . AppendLine ( $ "EntrySize: { EntrySize } ") ;
72- sb . AppendLine ( $ "Signatures: 0x{ Signatures : X8} ") ;
73- sb . AppendLine ( $ "AuxiliaryData: { AuxiliaryData } ") ;
114+ sb . AppendLine ( $ "SignatureRVA: 0x{ SignatureRVA : X8} ({ SignatureRVA } )") ;
115+ sb . AppendLine ( $ "AuxiliaryDataRVA: 0x{ AuxiliaryDataRVA : X8} ({ AuxiliaryDataRVA } )") ;
116+ if ( AuxiliaryDataRVA != 0 )
117+ {
118+ sb . AppendLine ( "AuxiliaryData:" ) ;
119+ sb . AppendLine ( AuxiliaryData . ToString ( ) ) ;
120+ }
74121 return sb . ToString ( ) ;
75122 }
76123 }
0 commit comments