2 // MetadataRowReader.cs
5 // Jb Evain (jbevain@gmail.com)
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Sat Feb 16 23:24:17 +0100 2008
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace Mono
.Cecil
.Metadata
{
35 using System
.Collections
;
38 using Mono
.Cecil
.Binary
;
40 sealed class MetadataRowReader
: BaseMetadataRowVisitor
{
42 MetadataTableReader m_mtrv
;
43 BinaryReader m_binaryReader
;
44 MetadataRoot m_metadataRoot
;
46 Utilities
.TableRowCounter m_counter
;
50 int m_stringsHeapIdxSz
;
53 public MetadataRowReader (MetadataTableReader mtrv
)
56 m_binaryReader
= mtrv
.GetReader ();
57 m_metadataRoot
= mtrv
.GetMetadataRoot ();
58 m_ciCache
= new int [13];
59 m_counter
= new Utilities
.TableRowCounter (m_mtrv
.GetNumberOfRows
);
62 int GetIndexSize (int rid
)
64 return m_mtrv
.GetNumberOfRows (rid
) < (1 << 16) ? 2 : 4;
67 int GetCodedIndexSize (CodedIndex ci
)
69 return Utilities
.GetCodedIndexSize (ci
, m_counter
, m_ciCache
);
72 uint ReadByIndexSize (int size
)
75 return (uint) m_binaryReader
.ReadUInt16 ();
76 } else if (size
== 4) {
77 return m_binaryReader
.ReadUInt32 ();
79 throw new MetadataFormatException ("Non valid size for indexing");
83 public override void VisitRowCollection (RowCollection coll
)
85 m_blobHeapIdxSz
= m_metadataRoot
.Streams
.BlobHeap
!= null ?
86 m_metadataRoot
.Streams
.BlobHeap
.IndexSize
: 2;
87 m_stringsHeapIdxSz
= m_metadataRoot
.Streams
.StringsHeap
!= null ?
88 m_metadataRoot
.Streams
.StringsHeap
.IndexSize
: 2;
89 m_guidHeapIdxSz
= m_metadataRoot
.Streams
.GuidHeap
!= null ?
90 m_metadataRoot
.Streams
.GuidHeap
.IndexSize
: 2;
93 public override void VisitAssemblyRow (AssemblyRow row
)
95 row
.HashAlgId
= (Mono
.Cecil
.AssemblyHashAlgorithm
) m_binaryReader
.ReadUInt32 ();
96 row
.MajorVersion
= m_binaryReader
.ReadUInt16 ();
97 row
.MinorVersion
= m_binaryReader
.ReadUInt16 ();
98 row
.BuildNumber
= m_binaryReader
.ReadUInt16 ();
99 row
.RevisionNumber
= m_binaryReader
.ReadUInt16 ();
100 row
.Flags
= (Mono
.Cecil
.AssemblyFlags
) m_binaryReader
.ReadUInt32 ();
101 row
.PublicKey
= ReadByIndexSize (m_blobHeapIdxSz
);
102 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
103 row
.Culture
= ReadByIndexSize (m_stringsHeapIdxSz
);
105 public override void VisitAssemblyOSRow (AssemblyOSRow row
)
107 row
.OSPlatformID
= m_binaryReader
.ReadUInt32 ();
108 row
.OSMajorVersion
= m_binaryReader
.ReadUInt32 ();
109 row
.OSMinorVersion
= m_binaryReader
.ReadUInt32 ();
111 public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row
)
113 row
.Processor
= m_binaryReader
.ReadUInt32 ();
115 public override void VisitAssemblyRefRow (AssemblyRefRow row
)
117 row
.MajorVersion
= m_binaryReader
.ReadUInt16 ();
118 row
.MinorVersion
= m_binaryReader
.ReadUInt16 ();
119 row
.BuildNumber
= m_binaryReader
.ReadUInt16 ();
120 row
.RevisionNumber
= m_binaryReader
.ReadUInt16 ();
121 row
.Flags
= (Mono
.Cecil
.AssemblyFlags
) m_binaryReader
.ReadUInt32 ();
122 row
.PublicKeyOrToken
= ReadByIndexSize (m_blobHeapIdxSz
);
123 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
124 row
.Culture
= ReadByIndexSize (m_stringsHeapIdxSz
);
125 row
.HashValue
= ReadByIndexSize (m_blobHeapIdxSz
);
127 public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row
)
129 row
.OSPlatformID
= m_binaryReader
.ReadUInt32 ();
130 row
.OSMajorVersion
= m_binaryReader
.ReadUInt32 ();
131 row
.OSMinorVersion
= m_binaryReader
.ReadUInt32 ();
132 row
.AssemblyRef
= ReadByIndexSize (GetIndexSize (AssemblyRefTable
.RId
));
134 public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row
)
136 row
.Processor
= m_binaryReader
.ReadUInt32 ();
137 row
.AssemblyRef
= ReadByIndexSize (GetIndexSize (AssemblyRefTable
.RId
));
139 public override void VisitClassLayoutRow (ClassLayoutRow row
)
141 row
.PackingSize
= m_binaryReader
.ReadUInt16 ();
142 row
.ClassSize
= m_binaryReader
.ReadUInt32 ();
143 row
.Parent
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
145 public override void VisitConstantRow (ConstantRow row
)
147 row
.Type
= (Mono
.Cecil
.Metadata
.ElementType
) m_binaryReader
.ReadUInt16 ();
148 row
.Parent
= Utilities
.GetMetadataToken (CodedIndex
.HasConstant
,
149 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.HasConstant
)));
150 row
.Value
= ReadByIndexSize (m_blobHeapIdxSz
);
152 public override void VisitCustomAttributeRow (CustomAttributeRow row
)
154 row
.Parent
= Utilities
.GetMetadataToken (CodedIndex
.HasCustomAttribute
,
155 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.HasCustomAttribute
)));
156 row
.Type
= Utilities
.GetMetadataToken (CodedIndex
.CustomAttributeType
,
157 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.CustomAttributeType
)));
158 row
.Value
= ReadByIndexSize (m_blobHeapIdxSz
);
160 public override void VisitDeclSecurityRow (DeclSecurityRow row
)
162 row
.Action
= (Mono
.Cecil
.SecurityAction
) m_binaryReader
.ReadInt16 ();
163 row
.Parent
= Utilities
.GetMetadataToken (CodedIndex
.HasDeclSecurity
,
164 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.HasDeclSecurity
)));
165 row
.PermissionSet
= ReadByIndexSize (m_blobHeapIdxSz
);
167 public override void VisitEventRow (EventRow row
)
169 row
.EventFlags
= (Mono
.Cecil
.EventAttributes
) m_binaryReader
.ReadUInt16 ();
170 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
171 row
.EventType
= Utilities
.GetMetadataToken (CodedIndex
.TypeDefOrRef
,
172 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.TypeDefOrRef
)));
174 public override void VisitEventMapRow (EventMapRow row
)
176 row
.Parent
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
177 row
.EventList
= ReadByIndexSize (GetIndexSize (EventTable
.RId
));
179 public override void VisitEventPtrRow (EventPtrRow row
)
181 row
.Event
= ReadByIndexSize (GetIndexSize (EventTable
.RId
));
183 public override void VisitExportedTypeRow (ExportedTypeRow row
)
185 row
.Flags
= (Mono
.Cecil
.TypeAttributes
) m_binaryReader
.ReadUInt32 ();
186 row
.TypeDefId
= m_binaryReader
.ReadUInt32 ();
187 row
.TypeName
= ReadByIndexSize (m_stringsHeapIdxSz
);
188 row
.TypeNamespace
= ReadByIndexSize (m_stringsHeapIdxSz
);
189 row
.Implementation
= Utilities
.GetMetadataToken (CodedIndex
.Implementation
,
190 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.Implementation
)));
192 public override void VisitFieldRow (FieldRow row
)
194 row
.Flags
= (Mono
.Cecil
.FieldAttributes
) m_binaryReader
.ReadUInt16 ();
195 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
196 row
.Signature
= ReadByIndexSize (m_blobHeapIdxSz
);
198 public override void VisitFieldLayoutRow (FieldLayoutRow row
)
200 row
.Offset
= m_binaryReader
.ReadUInt32 ();
201 row
.Field
= ReadByIndexSize (GetIndexSize (FieldTable
.RId
));
203 public override void VisitFieldMarshalRow (FieldMarshalRow row
)
205 row
.Parent
= Utilities
.GetMetadataToken (CodedIndex
.HasFieldMarshal
,
206 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.HasFieldMarshal
)));
207 row
.NativeType
= ReadByIndexSize (m_blobHeapIdxSz
);
209 public override void VisitFieldPtrRow (FieldPtrRow row
)
211 row
.Field
= ReadByIndexSize (GetIndexSize (FieldTable
.RId
));
213 public override void VisitFieldRVARow (FieldRVARow row
)
215 row
.RVA
= new RVA (m_binaryReader
.ReadUInt32 ());
216 row
.Field
= ReadByIndexSize (GetIndexSize (FieldTable
.RId
));
218 public override void VisitFileRow (FileRow row
)
220 row
.Flags
= (Mono
.Cecil
.FileAttributes
) m_binaryReader
.ReadUInt32 ();
221 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
222 row
.HashValue
= ReadByIndexSize (m_blobHeapIdxSz
);
224 public override void VisitGenericParamRow (GenericParamRow row
)
226 row
.Number
= m_binaryReader
.ReadUInt16 ();
227 row
.Flags
= (Mono
.Cecil
.GenericParameterAttributes
) m_binaryReader
.ReadUInt16 ();
228 row
.Owner
= Utilities
.GetMetadataToken (CodedIndex
.TypeOrMethodDef
,
229 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.TypeOrMethodDef
)));
230 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
232 public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row
)
234 row
.Owner
= ReadByIndexSize (GetIndexSize (GenericParamTable
.RId
));
235 row
.Constraint
= Utilities
.GetMetadataToken (CodedIndex
.TypeDefOrRef
,
236 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.TypeDefOrRef
)));
238 public override void VisitImplMapRow (ImplMapRow row
)
240 row
.MappingFlags
= (Mono
.Cecil
.PInvokeAttributes
) m_binaryReader
.ReadUInt16 ();
241 row
.MemberForwarded
= Utilities
.GetMetadataToken (CodedIndex
.MemberForwarded
,
242 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.MemberForwarded
)));
243 row
.ImportName
= ReadByIndexSize (m_stringsHeapIdxSz
);
244 row
.ImportScope
= ReadByIndexSize (GetIndexSize (ModuleRefTable
.RId
));
246 public override void VisitInterfaceImplRow (InterfaceImplRow row
)
248 row
.Class
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
249 row
.Interface
= Utilities
.GetMetadataToken (CodedIndex
.TypeDefOrRef
,
250 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.TypeDefOrRef
)));
252 public override void VisitManifestResourceRow (ManifestResourceRow row
)
254 row
.Offset
= m_binaryReader
.ReadUInt32 ();
255 row
.Flags
= (Mono
.Cecil
.ManifestResourceAttributes
) m_binaryReader
.ReadUInt32 ();
256 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
257 row
.Implementation
= Utilities
.GetMetadataToken (CodedIndex
.Implementation
,
258 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.Implementation
)));
260 public override void VisitMemberRefRow (MemberRefRow row
)
262 row
.Class
= Utilities
.GetMetadataToken (CodedIndex
.MemberRefParent
,
263 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.MemberRefParent
)));
264 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
265 row
.Signature
= ReadByIndexSize (m_blobHeapIdxSz
);
267 public override void VisitMethodRow (MethodRow row
)
269 row
.RVA
= new RVA (m_binaryReader
.ReadUInt32 ());
270 row
.ImplFlags
= (Mono
.Cecil
.MethodImplAttributes
) m_binaryReader
.ReadUInt16 ();
271 row
.Flags
= (Mono
.Cecil
.MethodAttributes
) m_binaryReader
.ReadUInt16 ();
272 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
273 row
.Signature
= ReadByIndexSize (m_blobHeapIdxSz
);
274 row
.ParamList
= ReadByIndexSize (GetIndexSize (ParamTable
.RId
));
276 public override void VisitMethodImplRow (MethodImplRow row
)
278 row
.Class
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
279 row
.MethodBody
= Utilities
.GetMetadataToken (CodedIndex
.MethodDefOrRef
,
280 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.MethodDefOrRef
)));
281 row
.MethodDeclaration
= Utilities
.GetMetadataToken (CodedIndex
.MethodDefOrRef
,
282 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.MethodDefOrRef
)));
284 public override void VisitMethodPtrRow (MethodPtrRow row
)
286 row
.Method
= ReadByIndexSize (GetIndexSize (MethodTable
.RId
));
288 public override void VisitMethodSemanticsRow (MethodSemanticsRow row
)
290 row
.Semantics
= (Mono
.Cecil
.MethodSemanticsAttributes
) m_binaryReader
.ReadUInt16 ();
291 row
.Method
= ReadByIndexSize (GetIndexSize (MethodTable
.RId
));
292 row
.Association
= Utilities
.GetMetadataToken (CodedIndex
.HasSemantics
,
293 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.HasSemantics
)));
295 public override void VisitMethodSpecRow (MethodSpecRow row
)
297 row
.Method
= Utilities
.GetMetadataToken (CodedIndex
.MethodDefOrRef
,
298 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.MethodDefOrRef
)));
299 row
.Instantiation
= ReadByIndexSize (m_blobHeapIdxSz
);
301 public override void VisitModuleRow (ModuleRow row
)
303 row
.Generation
= m_binaryReader
.ReadUInt16 ();
304 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
305 row
.Mvid
= ReadByIndexSize (m_guidHeapIdxSz
);
306 row
.EncId
= ReadByIndexSize (m_guidHeapIdxSz
);
307 row
.EncBaseId
= ReadByIndexSize (m_guidHeapIdxSz
);
309 public override void VisitModuleRefRow (ModuleRefRow row
)
311 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
313 public override void VisitNestedClassRow (NestedClassRow row
)
315 row
.NestedClass
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
316 row
.EnclosingClass
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
318 public override void VisitParamRow (ParamRow row
)
320 row
.Flags
= (Mono
.Cecil
.ParameterAttributes
) m_binaryReader
.ReadUInt16 ();
321 row
.Sequence
= m_binaryReader
.ReadUInt16 ();
322 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
324 public override void VisitParamPtrRow (ParamPtrRow row
)
326 row
.Param
= ReadByIndexSize (GetIndexSize (ParamTable
.RId
));
328 public override void VisitPropertyRow (PropertyRow row
)
330 row
.Flags
= (Mono
.Cecil
.PropertyAttributes
) m_binaryReader
.ReadUInt16 ();
331 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
332 row
.Type
= ReadByIndexSize (m_blobHeapIdxSz
);
334 public override void VisitPropertyMapRow (PropertyMapRow row
)
336 row
.Parent
= ReadByIndexSize (GetIndexSize (TypeDefTable
.RId
));
337 row
.PropertyList
= ReadByIndexSize (GetIndexSize (PropertyTable
.RId
));
339 public override void VisitPropertyPtrRow (PropertyPtrRow row
)
341 row
.Property
= ReadByIndexSize (GetIndexSize (PropertyTable
.RId
));
343 public override void VisitStandAloneSigRow (StandAloneSigRow row
)
345 row
.Signature
= ReadByIndexSize (m_blobHeapIdxSz
);
347 public override void VisitTypeDefRow (TypeDefRow row
)
349 row
.Flags
= (Mono
.Cecil
.TypeAttributes
) m_binaryReader
.ReadUInt32 ();
350 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
351 row
.Namespace
= ReadByIndexSize (m_stringsHeapIdxSz
);
352 row
.Extends
= Utilities
.GetMetadataToken (CodedIndex
.TypeDefOrRef
,
353 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.TypeDefOrRef
)));
354 row
.FieldList
= ReadByIndexSize (GetIndexSize (FieldTable
.RId
));
355 row
.MethodList
= ReadByIndexSize (GetIndexSize (MethodTable
.RId
));
357 public override void VisitTypeRefRow (TypeRefRow row
)
359 row
.ResolutionScope
= Utilities
.GetMetadataToken (CodedIndex
.ResolutionScope
,
360 ReadByIndexSize (GetCodedIndexSize (CodedIndex
.ResolutionScope
)));
361 row
.Name
= ReadByIndexSize (m_stringsHeapIdxSz
);
362 row
.Namespace
= ReadByIndexSize (m_stringsHeapIdxSz
);
364 public override void VisitTypeSpecRow (TypeSpecRow row
)
366 row
.Signature
= ReadByIndexSize (m_blobHeapIdxSz
);