2 // MetadataRowReader.cs
5 // Jb Evain (jbevain@gmail.com)
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Thu Feb 22 14:39:38 CET 2007
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 {
34 using System.Collections;
37 using Mono.Cecil.Binary;
39 class MetadataRowReader : BaseMetadataRowVisitor {
41 MetadataTableReader m_mtrv;
42 BinaryReader m_binaryReader;
43 MetadataRoot m_metadataRoot;
44 IDictionary m_ciCache;
47 int m_stringsHeapIdxSz;
50 public MetadataRowReader (MetadataTableReader mtrv)
53 m_binaryReader = mtrv.GetReader ();
54 m_metadataRoot = mtrv.GetMetadataRoot ();
55 m_ciCache = new Hashtable ();
58 int GetIndexSize (int rid)
60 return m_mtrv.GetNumberOfRows (rid) < (1 << 16) ? 2 : 4;
63 int GetCodedIndexSize (CodedIndex ci)
65 return Utilities.GetCodedIndexSize (ci,
66 new Utilities.TableRowCounter (m_mtrv.GetNumberOfRows), m_ciCache);
69 uint ReadByIndexSize (int size)
72 return (uint) m_binaryReader.ReadUInt16 ();
73 } else if (size == 4) {
74 return m_binaryReader.ReadUInt32 ();
76 throw new MetadataFormatException ("Non valid size for indexing");
80 public override void VisitRowCollection (RowCollection coll)
82 m_blobHeapIdxSz = m_metadataRoot.Streams.BlobHeap != null ?
83 m_metadataRoot.Streams.BlobHeap.IndexSize : 2;
84 m_stringsHeapIdxSz = m_metadataRoot.Streams.StringsHeap != null ?
85 m_metadataRoot.Streams.StringsHeap.IndexSize : 2;
86 m_guidHeapIdxSz = m_metadataRoot.Streams.GuidHeap != null ?
87 m_metadataRoot.Streams.GuidHeap.IndexSize : 2;
90 public override void VisitAssemblyRow (AssemblyRow row)
92 row.HashAlgId = (Mono.Cecil.AssemblyHashAlgorithm) m_binaryReader.ReadUInt32 ();
93 row.MajorVersion = m_binaryReader.ReadUInt16 ();
94 row.MinorVersion = m_binaryReader.ReadUInt16 ();
95 row.BuildNumber = m_binaryReader.ReadUInt16 ();
96 row.RevisionNumber = m_binaryReader.ReadUInt16 ();
97 row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 ();
98 row.PublicKey = ReadByIndexSize (m_blobHeapIdxSz);
99 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
100 row.Culture = ReadByIndexSize (m_stringsHeapIdxSz);
102 public override void VisitAssemblyOSRow (AssemblyOSRow row)
104 row.OSPlatformID = m_binaryReader.ReadUInt32 ();
105 row.OSMajorVersion = m_binaryReader.ReadUInt32 ();
106 row.OSMinorVersion = m_binaryReader.ReadUInt32 ();
108 public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row)
110 row.Processor = m_binaryReader.ReadUInt32 ();
112 public override void VisitAssemblyRefRow (AssemblyRefRow row)
114 row.MajorVersion = m_binaryReader.ReadUInt16 ();
115 row.MinorVersion = m_binaryReader.ReadUInt16 ();
116 row.BuildNumber = m_binaryReader.ReadUInt16 ();
117 row.RevisionNumber = m_binaryReader.ReadUInt16 ();
118 row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 ();
119 row.PublicKeyOrToken = ReadByIndexSize (m_blobHeapIdxSz);
120 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
121 row.Culture = ReadByIndexSize (m_stringsHeapIdxSz);
122 row.HashValue = ReadByIndexSize (m_blobHeapIdxSz);
124 public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row)
126 row.OSPlatformID = m_binaryReader.ReadUInt32 ();
127 row.OSMajorVersion = m_binaryReader.ReadUInt32 ();
128 row.OSMinorVersion = m_binaryReader.ReadUInt32 ();
129 row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId));
131 public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row)
133 row.Processor = m_binaryReader.ReadUInt32 ();
134 row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId));
136 public override void VisitClassLayoutRow (ClassLayoutRow row)
138 row.PackingSize = m_binaryReader.ReadUInt16 ();
139 row.ClassSize = m_binaryReader.ReadUInt32 ();
140 row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
142 public override void VisitConstantRow (ConstantRow row)
144 row.Type = (Mono.Cecil.Metadata.ElementType) m_binaryReader.ReadUInt16 ();
145 row.Parent = Utilities.GetMetadataToken (CodedIndex.HasConstant,
146 ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasConstant)));
147 row.Value = ReadByIndexSize (m_blobHeapIdxSz);
149 public override void VisitCustomAttributeRow (CustomAttributeRow row)
151 row.Parent = Utilities.GetMetadataToken (CodedIndex.HasCustomAttribute,
152 ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasCustomAttribute)));
153 row.Type = Utilities.GetMetadataToken (CodedIndex.CustomAttributeType,
154 ReadByIndexSize (GetCodedIndexSize (CodedIndex.CustomAttributeType)));
155 row.Value = ReadByIndexSize (m_blobHeapIdxSz);
157 public override void VisitDeclSecurityRow (DeclSecurityRow row)
159 row.Action = (Mono.Cecil.SecurityAction) m_binaryReader.ReadInt16 ();
160 row.Parent = Utilities.GetMetadataToken (CodedIndex.HasDeclSecurity,
161 ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasDeclSecurity)));
162 row.PermissionSet = ReadByIndexSize (m_blobHeapIdxSz);
164 public override void VisitEventRow (EventRow row)
166 row.EventFlags = (Mono.Cecil.EventAttributes) m_binaryReader.ReadUInt16 ();
167 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
168 row.EventType = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
169 ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
171 public override void VisitEventMapRow (EventMapRow row)
173 row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
174 row.EventList = ReadByIndexSize (GetIndexSize (EventTable.RId));
176 public override void VisitEventPtrRow (EventPtrRow row)
178 row.Event = ReadByIndexSize (GetIndexSize (EventTable.RId));
180 public override void VisitExportedTypeRow (ExportedTypeRow row)
182 row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 ();
183 row.TypeDefId = m_binaryReader.ReadUInt32 ();
184 row.TypeName = ReadByIndexSize (m_stringsHeapIdxSz);
185 row.TypeNamespace = ReadByIndexSize (m_stringsHeapIdxSz);
186 row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation,
187 ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation)));
189 public override void VisitFieldRow (FieldRow row)
191 row.Flags = (Mono.Cecil.FieldAttributes) m_binaryReader.ReadUInt16 ();
192 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
193 row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
195 public override void VisitFieldLayoutRow (FieldLayoutRow row)
197 row.Offset = m_binaryReader.ReadUInt32 ();
198 row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
200 public override void VisitFieldMarshalRow (FieldMarshalRow row)
202 row.Parent = Utilities.GetMetadataToken (CodedIndex.HasFieldMarshal,
203 ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasFieldMarshal)));
204 row.NativeType = ReadByIndexSize (m_blobHeapIdxSz);
206 public override void VisitFieldPtrRow (FieldPtrRow row)
208 row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
210 public override void VisitFieldRVARow (FieldRVARow row)
212 row.RVA = new RVA (m_binaryReader.ReadUInt32 ());
213 row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
215 public override void VisitFileRow (FileRow row)
217 row.Flags = (Mono.Cecil.FileAttributes) m_binaryReader.ReadUInt32 ();
218 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
219 row.HashValue = ReadByIndexSize (m_blobHeapIdxSz);
221 public override void VisitGenericParamRow (GenericParamRow row)
223 row.Number = m_binaryReader.ReadUInt16 ();
224 row.Flags = (Mono.Cecil.GenericParameterAttributes) m_binaryReader.ReadUInt16 ();
225 row.Owner = Utilities.GetMetadataToken (CodedIndex.TypeOrMethodDef,
226 ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeOrMethodDef)));
227 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
229 public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row)
231 row.Owner = ReadByIndexSize (GetIndexSize (GenericParamTable.RId));
232 row.Constraint = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
233 ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
235 public override void VisitImplMapRow (ImplMapRow row)
237 row.MappingFlags = (Mono.Cecil.PInvokeAttributes) m_binaryReader.ReadUInt16 ();
238 row.MemberForwarded = Utilities.GetMetadataToken (CodedIndex.MemberForwarded,
239 ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberForwarded)));
240 row.ImportName = ReadByIndexSize (m_stringsHeapIdxSz);
241 row.ImportScope = ReadByIndexSize (GetIndexSize (ModuleRefTable.RId));
243 public override void VisitInterfaceImplRow (InterfaceImplRow row)
245 row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
246 row.Interface = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
247 ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
249 public override void VisitManifestResourceRow (ManifestResourceRow row)
251 row.Offset = m_binaryReader.ReadUInt32 ();
252 row.Flags = (Mono.Cecil.ManifestResourceAttributes) m_binaryReader.ReadUInt32 ();
253 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
254 row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation,
255 ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation)));
257 public override void VisitMemberRefRow (MemberRefRow row)
259 row.Class = Utilities.GetMetadataToken (CodedIndex.MemberRefParent,
260 ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberRefParent)));
261 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
262 row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
264 public override void VisitMethodRow (MethodRow row)
266 row.RVA = new RVA (m_binaryReader.ReadUInt32 ());
267 row.ImplFlags = (Mono.Cecil.MethodImplAttributes) m_binaryReader.ReadUInt16 ();
268 row.Flags = (Mono.Cecil.MethodAttributes) m_binaryReader.ReadUInt16 ();
269 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
270 row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
271 row.ParamList = ReadByIndexSize (GetIndexSize (ParamTable.RId));
273 public override void VisitMethodImplRow (MethodImplRow row)
275 row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
276 row.MethodBody = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
277 ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
278 row.MethodDeclaration = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
279 ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
281 public override void VisitMethodPtrRow (MethodPtrRow row)
283 row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId));
285 public override void VisitMethodSemanticsRow (MethodSemanticsRow row)
287 row.Semantics = (Mono.Cecil.MethodSemanticsAttributes) m_binaryReader.ReadUInt16 ();
288 row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId));
289 row.Association = Utilities.GetMetadataToken (CodedIndex.HasSemantics,
290 ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasSemantics)));
292 public override void VisitMethodSpecRow (MethodSpecRow row)
294 row.Method = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
295 ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
296 row.Instantiation = ReadByIndexSize (m_blobHeapIdxSz);
298 public override void VisitModuleRow (ModuleRow row)
300 row.Generation = m_binaryReader.ReadUInt16 ();
301 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
302 row.Mvid = ReadByIndexSize (m_guidHeapIdxSz);
303 row.EncId = ReadByIndexSize (m_guidHeapIdxSz);
304 row.EncBaseId = ReadByIndexSize (m_guidHeapIdxSz);
306 public override void VisitModuleRefRow (ModuleRefRow row)
308 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
310 public override void VisitNestedClassRow (NestedClassRow row)
312 row.NestedClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
313 row.EnclosingClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
315 public override void VisitParamRow (ParamRow row)
317 row.Flags = (Mono.Cecil.ParameterAttributes) m_binaryReader.ReadUInt16 ();
318 row.Sequence = m_binaryReader.ReadUInt16 ();
319 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
321 public override void VisitParamPtrRow (ParamPtrRow row)
323 row.Param = ReadByIndexSize (GetIndexSize (ParamTable.RId));
325 public override void VisitPropertyRow (PropertyRow row)
327 row.Flags = (Mono.Cecil.PropertyAttributes) m_binaryReader.ReadUInt16 ();
328 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
329 row.Type = ReadByIndexSize (m_blobHeapIdxSz);
331 public override void VisitPropertyMapRow (PropertyMapRow row)
333 row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
334 row.PropertyList = ReadByIndexSize (GetIndexSize (PropertyTable.RId));
336 public override void VisitPropertyPtrRow (PropertyPtrRow row)
338 row.Property = ReadByIndexSize (GetIndexSize (PropertyTable.RId));
340 public override void VisitStandAloneSigRow (StandAloneSigRow row)
342 row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
344 public override void VisitTypeDefRow (TypeDefRow row)
346 row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 ();
347 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
348 row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz);
349 row.Extends = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
350 ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
351 row.FieldList = ReadByIndexSize (GetIndexSize (FieldTable.RId));
352 row.MethodList = ReadByIndexSize (GetIndexSize (MethodTable.RId));
354 public override void VisitTypeRefRow (TypeRefRow row)
356 row.ResolutionScope = Utilities.GetMetadataToken (CodedIndex.ResolutionScope,
357 ReadByIndexSize (GetCodedIndexSize (CodedIndex.ResolutionScope)));
358 row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
359 row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz);
361 public override void VisitTypeSpecRow (TypeSpecRow row)
363 row.Signature = ReadByIndexSize (m_blobHeapIdxSz);