| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Immutable; |
| | | 5 | | |
| | | 6 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Decodes custom attribute blobs. |
| | | 10 | | /// </summary> |
| | | 11 | | internal readonly struct CustomAttributeDecoder<TType> |
| | | 12 | | { |
| | | 13 | | private readonly ICustomAttributeTypeProvider<TType> _provider; |
| | | 14 | | private readonly MetadataReader _reader; |
| | | 15 | | |
| | | 16 | | public CustomAttributeDecoder(ICustomAttributeTypeProvider<TType> provider, MetadataReader reader) |
| | 0 | 17 | | { |
| | 0 | 18 | | _reader = reader; |
| | 0 | 19 | | _provider = provider; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public CustomAttributeValue<TType> DecodeValue(EntityHandle constructor, BlobHandle value) |
| | 0 | 23 | | { |
| | | 24 | | BlobHandle signature; |
| | 0 | 25 | | BlobHandle attributeOwningTypeSpec = default; |
| | 0 | 26 | | switch (constructor.Kind) |
| | | 27 | | { |
| | | 28 | | case HandleKind.MethodDefinition: |
| | 0 | 29 | | MethodDefinition definition = _reader.GetMethodDefinition((MethodDefinitionHandle)constructor); |
| | 0 | 30 | | signature = definition.Signature; |
| | 0 | 31 | | break; |
| | | 32 | | |
| | | 33 | | case HandleKind.MemberReference: |
| | 0 | 34 | | MemberReference reference = _reader.GetMemberReference((MemberReferenceHandle)constructor); |
| | 0 | 35 | | signature = reference.Signature; |
| | | 36 | | |
| | | 37 | | // If this is a generic attribute, we'll need its instantiation to decode the signatures |
| | 0 | 38 | | if (reference.Parent.Kind == HandleKind.TypeSpecification) |
| | 0 | 39 | | { |
| | 0 | 40 | | TypeSpecification genericOwner = _reader.GetTypeSpecification((TypeSpecificationHandle)reference |
| | 0 | 41 | | attributeOwningTypeSpec = genericOwner.Signature; |
| | 0 | 42 | | } |
| | 0 | 43 | | break; |
| | | 44 | | |
| | | 45 | | default: |
| | 0 | 46 | | throw new BadImageFormatException(); |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | BlobReader signatureReader = _reader.GetBlobReader(signature); |
| | 0 | 50 | | BlobReader valueReader = _reader.GetBlobReader(value); |
| | | 51 | | |
| | 0 | 52 | | ushort prolog = valueReader.ReadUInt16(); |
| | 0 | 53 | | if (prolog != 1) |
| | 0 | 54 | | { |
| | 0 | 55 | | throw new BadImageFormatException(); |
| | | 56 | | } |
| | | 57 | | |
| | 0 | 58 | | SignatureHeader header = signatureReader.ReadSignatureHeader(); |
| | 0 | 59 | | if (header.Kind != SignatureKind.Method || header.IsGeneric) |
| | 0 | 60 | | { |
| | 0 | 61 | | throw new BadImageFormatException(); |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | int parameterCount = signatureReader.ReadCompressedInteger(); |
| | 0 | 65 | | SignatureTypeCode returnType = signatureReader.ReadSignatureTypeCode(); |
| | 0 | 66 | | if (returnType != SignatureTypeCode.Void) |
| | 0 | 67 | | { |
| | 0 | 68 | | throw new BadImageFormatException(); |
| | | 69 | | } |
| | | 70 | | |
| | 0 | 71 | | BlobReader genericContextReader = default; |
| | 0 | 72 | | if (!attributeOwningTypeSpec.IsNil) |
| | 0 | 73 | | { |
| | | 74 | | // If this is a generic attribute, grab the instantiation arguments so that we can |
| | | 75 | | // interpret the constructor signature, should it refer to the generic context. |
| | 0 | 76 | | genericContextReader = _reader.GetBlobReader(attributeOwningTypeSpec); |
| | 0 | 77 | | if (genericContextReader.ReadSignatureTypeCode() == SignatureTypeCode.GenericTypeInstance) |
| | 0 | 78 | | { |
| | 0 | 79 | | int kind = genericContextReader.ReadCompressedInteger(); |
| | 0 | 80 | | if (kind != (int)SignatureTypeKind.Class && kind != (int)SignatureTypeKind.ValueType) |
| | 0 | 81 | | { |
| | 0 | 82 | | throw new BadImageFormatException(); |
| | | 83 | | } |
| | | 84 | | |
| | 0 | 85 | | genericContextReader.ReadTypeHandle(); |
| | | 86 | | |
| | | 87 | | // At this point, the reader points to the "GenArgCount Type Type*" part of the signature. |
| | 0 | 88 | | } |
| | | 89 | | else |
| | 0 | 90 | | { |
| | | 91 | | // Some other invalid TypeSpec. Don't accidentally allow resolving generic parameters |
| | | 92 | | // from the constructor signature into a broken blob. |
| | 0 | 93 | | genericContextReader = default; |
| | 0 | 94 | | } |
| | 0 | 95 | | } |
| | | 96 | | |
| | 0 | 97 | | ImmutableArray<CustomAttributeTypedArgument<TType>> fixedArguments = DecodeFixedArguments(ref signatureReade |
| | 0 | 98 | | ImmutableArray<CustomAttributeNamedArgument<TType>> namedArguments = DecodeNamedArguments(ref valueReader); |
| | 0 | 99 | | return new CustomAttributeValue<TType>(fixedArguments, namedArguments); |
| | 0 | 100 | | } |
| | | 101 | | |
| | | 102 | | private ImmutableArray<CustomAttributeTypedArgument<TType>> DecodeFixedArguments(ref BlobReader signatureReader, |
| | 0 | 103 | | { |
| | 0 | 104 | | if (count == 0) |
| | 0 | 105 | | { |
| | 0 | 106 | | return ImmutableArray<CustomAttributeTypedArgument<TType>>.Empty; |
| | | 107 | | } |
| | | 108 | | |
| | 0 | 109 | | var arguments = ImmutableArray.CreateBuilder<CustomAttributeTypedArgument<TType>>(count); |
| | | 110 | | |
| | 0 | 111 | | for (int i = 0; i < count; i++) |
| | 0 | 112 | | { |
| | 0 | 113 | | ArgumentTypeInfo info = DecodeFixedArgumentType(ref signatureReader, genericContextReader); |
| | 0 | 114 | | arguments.Add(DecodeArgument(ref valueReader, info)); |
| | 0 | 115 | | } |
| | | 116 | | |
| | 0 | 117 | | return arguments.MoveToImmutable(); |
| | 0 | 118 | | } |
| | | 119 | | |
| | | 120 | | private ImmutableArray<CustomAttributeNamedArgument<TType>> DecodeNamedArguments(ref BlobReader valueReader) |
| | 0 | 121 | | { |
| | 0 | 122 | | int count = valueReader.ReadUInt16(); |
| | 0 | 123 | | if (count == 0) |
| | 0 | 124 | | { |
| | 0 | 125 | | return ImmutableArray<CustomAttributeNamedArgument<TType>>.Empty; |
| | | 126 | | } |
| | | 127 | | |
| | 0 | 128 | | var arguments = ImmutableArray.CreateBuilder<CustomAttributeNamedArgument<TType>>(count); |
| | 0 | 129 | | for (int i = 0; i < count; i++) |
| | 0 | 130 | | { |
| | 0 | 131 | | CustomAttributeNamedArgumentKind kind = (CustomAttributeNamedArgumentKind)valueReader.ReadSerializationT |
| | 0 | 132 | | if (kind != CustomAttributeNamedArgumentKind.Field && kind != CustomAttributeNamedArgumentKind.Property) |
| | 0 | 133 | | { |
| | 0 | 134 | | throw new BadImageFormatException(); |
| | | 135 | | } |
| | | 136 | | |
| | 0 | 137 | | ArgumentTypeInfo info = DecodeNamedArgumentType(ref valueReader); |
| | 0 | 138 | | string? name = valueReader.ReadSerializedString(); |
| | 0 | 139 | | CustomAttributeTypedArgument<TType> argument = DecodeArgument(ref valueReader, info); |
| | 0 | 140 | | arguments.Add(new CustomAttributeNamedArgument<TType>(name, kind, argument.Type, argument.Value)); |
| | 0 | 141 | | } |
| | | 142 | | |
| | 0 | 143 | | return arguments.MoveToImmutable(); |
| | 0 | 144 | | } |
| | | 145 | | |
| | | 146 | | private struct ArgumentTypeInfo |
| | | 147 | | { |
| | | 148 | | public TType Type; |
| | | 149 | | public TType ElementType; |
| | | 150 | | public SerializationTypeCode TypeCode; |
| | | 151 | | public SerializationTypeCode ElementTypeCode; |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | // Decodes a fixed argument type of a custom attribute from its constructor signature. |
| | | 155 | | // |
| | | 156 | | // Note that we do not decode the full constructor signature using DecodeMethodSignature |
| | | 157 | | // but instead decode one parameter at a time as we read the value blob. This is both |
| | | 158 | | // better perf-wise, but even more important is that we can't actually reason about |
| | | 159 | | // a method signature with opaque TType values without adding some unnecessary chatter |
| | | 160 | | // with the provider. |
| | | 161 | | private ArgumentTypeInfo DecodeFixedArgumentType(ref BlobReader signatureReader, BlobReader genericContextReader |
| | 0 | 162 | | { |
| | 0 | 163 | | SignatureTypeCode signatureTypeCode = signatureReader.ReadSignatureTypeCode(); |
| | | 164 | | |
| | 0 | 165 | | var info = new ArgumentTypeInfo |
| | 0 | 166 | | { |
| | 0 | 167 | | TypeCode = (SerializationTypeCode)signatureTypeCode, |
| | 0 | 168 | | }; |
| | | 169 | | |
| | 0 | 170 | | switch (signatureTypeCode) |
| | | 171 | | { |
| | | 172 | | case SignatureTypeCode.Boolean: |
| | | 173 | | case SignatureTypeCode.Byte: |
| | | 174 | | case SignatureTypeCode.Char: |
| | | 175 | | case SignatureTypeCode.Double: |
| | | 176 | | case SignatureTypeCode.Int16: |
| | | 177 | | case SignatureTypeCode.Int32: |
| | | 178 | | case SignatureTypeCode.Int64: |
| | | 179 | | case SignatureTypeCode.SByte: |
| | | 180 | | case SignatureTypeCode.Single: |
| | | 181 | | case SignatureTypeCode.String: |
| | | 182 | | case SignatureTypeCode.UInt16: |
| | | 183 | | case SignatureTypeCode.UInt32: |
| | | 184 | | case SignatureTypeCode.UInt64: |
| | 0 | 185 | | info.Type = _provider.GetPrimitiveType((PrimitiveTypeCode)signatureTypeCode); |
| | 0 | 186 | | break; |
| | | 187 | | |
| | | 188 | | case SignatureTypeCode.Object: |
| | 0 | 189 | | info.TypeCode = SerializationTypeCode.TaggedObject; |
| | 0 | 190 | | info.Type = _provider.GetPrimitiveType(PrimitiveTypeCode.Object); |
| | 0 | 191 | | break; |
| | | 192 | | |
| | | 193 | | case SignatureTypeCode.TypeHandle: |
| | | 194 | | // Parameter is type def or ref and is only allowed to be System.Type or Enum. |
| | 0 | 195 | | EntityHandle handle = signatureReader.ReadTypeHandle(); |
| | 0 | 196 | | info.Type = GetTypeFromHandle(handle); |
| | 0 | 197 | | info.TypeCode = _provider.IsSystemType(info.Type) ? SerializationTypeCode.Type : (SerializationTypeC |
| | 0 | 198 | | break; |
| | | 199 | | |
| | | 200 | | case SignatureTypeCode.SZArray: |
| | 0 | 201 | | if (isElementType) |
| | 0 | 202 | | { |
| | | 203 | | // jagged arrays are not allowed. |
| | 0 | 204 | | throw new BadImageFormatException(); |
| | | 205 | | } |
| | | 206 | | |
| | 0 | 207 | | var elementInfo = DecodeFixedArgumentType(ref signatureReader, genericContextReader, isElementType: |
| | 0 | 208 | | info.ElementType = elementInfo.Type; |
| | 0 | 209 | | info.ElementTypeCode = elementInfo.TypeCode; |
| | 0 | 210 | | info.Type = _provider.GetSZArrayType(info.ElementType); |
| | 0 | 211 | | break; |
| | | 212 | | |
| | | 213 | | case SignatureTypeCode.GenericTypeParameter: |
| | 0 | 214 | | if (genericContextReader.Length == 0) |
| | 0 | 215 | | { |
| | 0 | 216 | | throw new BadImageFormatException(); |
| | | 217 | | } |
| | | 218 | | |
| | 0 | 219 | | int parameterIndex = signatureReader.ReadCompressedInteger(); |
| | 0 | 220 | | int numGenericParameters = genericContextReader.ReadCompressedInteger(); |
| | 0 | 221 | | if (parameterIndex >= numGenericParameters) |
| | 0 | 222 | | { |
| | 0 | 223 | | throw new BadImageFormatException(); |
| | | 224 | | } |
| | | 225 | | |
| | 0 | 226 | | while (parameterIndex > 0) |
| | 0 | 227 | | { |
| | 0 | 228 | | SkipType(ref genericContextReader); |
| | 0 | 229 | | parameterIndex--; |
| | 0 | 230 | | } |
| | | 231 | | |
| | 0 | 232 | | return DecodeFixedArgumentType(ref genericContextReader, default, isElementType); |
| | | 233 | | |
| | | 234 | | default: |
| | 0 | 235 | | throw new BadImageFormatException(); |
| | | 236 | | } |
| | | 237 | | |
| | 0 | 238 | | return info; |
| | 0 | 239 | | } |
| | | 240 | | |
| | | 241 | | private ArgumentTypeInfo DecodeNamedArgumentType(ref BlobReader valueReader, bool isElementType = false) |
| | 0 | 242 | | { |
| | 0 | 243 | | var info = new ArgumentTypeInfo |
| | 0 | 244 | | { |
| | 0 | 245 | | TypeCode = valueReader.ReadSerializationTypeCode(), |
| | 0 | 246 | | }; |
| | | 247 | | |
| | 0 | 248 | | switch (info.TypeCode) |
| | | 249 | | { |
| | | 250 | | case SerializationTypeCode.Boolean: |
| | | 251 | | case SerializationTypeCode.Byte: |
| | | 252 | | case SerializationTypeCode.Char: |
| | | 253 | | case SerializationTypeCode.Double: |
| | | 254 | | case SerializationTypeCode.Int16: |
| | | 255 | | case SerializationTypeCode.Int32: |
| | | 256 | | case SerializationTypeCode.Int64: |
| | | 257 | | case SerializationTypeCode.SByte: |
| | | 258 | | case SerializationTypeCode.Single: |
| | | 259 | | case SerializationTypeCode.String: |
| | | 260 | | case SerializationTypeCode.UInt16: |
| | | 261 | | case SerializationTypeCode.UInt32: |
| | | 262 | | case SerializationTypeCode.UInt64: |
| | 0 | 263 | | info.Type = _provider.GetPrimitiveType((PrimitiveTypeCode)info.TypeCode); |
| | 0 | 264 | | break; |
| | | 265 | | |
| | | 266 | | case SerializationTypeCode.Type: |
| | 0 | 267 | | info.Type = _provider.GetSystemType(); |
| | 0 | 268 | | break; |
| | | 269 | | |
| | | 270 | | case SerializationTypeCode.TaggedObject: |
| | 0 | 271 | | info.Type = _provider.GetPrimitiveType(PrimitiveTypeCode.Object); |
| | 0 | 272 | | break; |
| | | 273 | | |
| | | 274 | | case SerializationTypeCode.SZArray: |
| | 0 | 275 | | if (isElementType) |
| | 0 | 276 | | { |
| | | 277 | | // jagged arrays are not allowed. |
| | 0 | 278 | | throw new BadImageFormatException(); |
| | | 279 | | } |
| | | 280 | | |
| | 0 | 281 | | var elementInfo = DecodeNamedArgumentType(ref valueReader, isElementType: true); |
| | 0 | 282 | | info.ElementType = elementInfo.Type; |
| | 0 | 283 | | info.ElementTypeCode = elementInfo.TypeCode; |
| | 0 | 284 | | info.Type = _provider.GetSZArrayType(info.ElementType); |
| | 0 | 285 | | break; |
| | | 286 | | |
| | | 287 | | case SerializationTypeCode.Enum: |
| | 0 | 288 | | string? typeName = valueReader.ReadSerializedString(); |
| | 0 | 289 | | info.Type = _provider.GetTypeFromSerializedName(typeName!); |
| | 0 | 290 | | info.TypeCode = (SerializationTypeCode)_provider.GetUnderlyingEnumType(info.Type); |
| | 0 | 291 | | break; |
| | | 292 | | |
| | | 293 | | default: |
| | 0 | 294 | | throw new BadImageFormatException(); |
| | | 295 | | } |
| | | 296 | | |
| | 0 | 297 | | return info; |
| | 0 | 298 | | } |
| | | 299 | | |
| | | 300 | | private CustomAttributeTypedArgument<TType> DecodeArgument(ref BlobReader valueReader, ArgumentTypeInfo info) |
| | 0 | 301 | | { |
| | 0 | 302 | | if (info.TypeCode == SerializationTypeCode.TaggedObject) |
| | 0 | 303 | | { |
| | 0 | 304 | | info = DecodeNamedArgumentType(ref valueReader); |
| | 0 | 305 | | } |
| | | 306 | | |
| | | 307 | | // PERF_TODO: https://github.com/dotnet/runtime/issues/16551 |
| | | 308 | | // Cache /reuse common arguments to avoid boxing (small integers, true, false). |
| | | 309 | | object? value; |
| | 0 | 310 | | switch (info.TypeCode) |
| | | 311 | | { |
| | | 312 | | case SerializationTypeCode.Boolean: |
| | 0 | 313 | | value = valueReader.ReadBoolean(); |
| | 0 | 314 | | break; |
| | | 315 | | |
| | | 316 | | case SerializationTypeCode.Byte: |
| | 0 | 317 | | value = valueReader.ReadByte(); |
| | 0 | 318 | | break; |
| | | 319 | | |
| | | 320 | | case SerializationTypeCode.Char: |
| | 0 | 321 | | value = valueReader.ReadChar(); |
| | 0 | 322 | | break; |
| | | 323 | | |
| | | 324 | | case SerializationTypeCode.Double: |
| | 0 | 325 | | value = valueReader.ReadDouble(); |
| | 0 | 326 | | break; |
| | | 327 | | |
| | | 328 | | case SerializationTypeCode.Int16: |
| | 0 | 329 | | value = valueReader.ReadInt16(); |
| | 0 | 330 | | break; |
| | | 331 | | |
| | | 332 | | case SerializationTypeCode.Int32: |
| | 0 | 333 | | value = valueReader.ReadInt32(); |
| | 0 | 334 | | break; |
| | | 335 | | |
| | | 336 | | case SerializationTypeCode.Int64: |
| | 0 | 337 | | value = valueReader.ReadInt64(); |
| | 0 | 338 | | break; |
| | | 339 | | |
| | | 340 | | case SerializationTypeCode.SByte: |
| | 0 | 341 | | value = valueReader.ReadSByte(); |
| | 0 | 342 | | break; |
| | | 343 | | |
| | | 344 | | case SerializationTypeCode.Single: |
| | 0 | 345 | | value = valueReader.ReadSingle(); |
| | 0 | 346 | | break; |
| | | 347 | | |
| | | 348 | | case SerializationTypeCode.UInt16: |
| | 0 | 349 | | value = valueReader.ReadUInt16(); |
| | 0 | 350 | | break; |
| | | 351 | | |
| | | 352 | | case SerializationTypeCode.UInt32: |
| | 0 | 353 | | value = valueReader.ReadUInt32(); |
| | 0 | 354 | | break; |
| | | 355 | | |
| | | 356 | | case SerializationTypeCode.UInt64: |
| | 0 | 357 | | value = valueReader.ReadUInt64(); |
| | 0 | 358 | | break; |
| | | 359 | | |
| | | 360 | | case SerializationTypeCode.String: |
| | 0 | 361 | | value = valueReader.ReadSerializedString(); |
| | 0 | 362 | | break; |
| | | 363 | | |
| | | 364 | | case SerializationTypeCode.Type: |
| | 0 | 365 | | string? typeName = valueReader.ReadSerializedString(); |
| | 0 | 366 | | value = _provider.GetTypeFromSerializedName(typeName!); |
| | 0 | 367 | | break; |
| | | 368 | | |
| | | 369 | | case SerializationTypeCode.SZArray: |
| | 0 | 370 | | value = DecodeArrayArgument(ref valueReader, info); |
| | 0 | 371 | | break; |
| | | 372 | | |
| | | 373 | | default: |
| | 0 | 374 | | throw new BadImageFormatException(); |
| | | 375 | | } |
| | | 376 | | |
| | 0 | 377 | | return new CustomAttributeTypedArgument<TType>(info.Type, value); |
| | 0 | 378 | | } |
| | | 379 | | |
| | | 380 | | private ImmutableArray<CustomAttributeTypedArgument<TType>>? DecodeArrayArgument(ref BlobReader blobReader, Argu |
| | 0 | 381 | | { |
| | 0 | 382 | | int count = blobReader.ReadInt32(); |
| | 0 | 383 | | if (count == -1) |
| | 0 | 384 | | { |
| | 0 | 385 | | return null; |
| | | 386 | | } |
| | | 387 | | |
| | 0 | 388 | | if (count == 0) |
| | 0 | 389 | | { |
| | 0 | 390 | | return ImmutableArray<CustomAttributeTypedArgument<TType>>.Empty; |
| | | 391 | | } |
| | | 392 | | |
| | 0 | 393 | | if (count < 0) |
| | 0 | 394 | | { |
| | 0 | 395 | | throw new BadImageFormatException(); |
| | | 396 | | } |
| | | 397 | | |
| | 0 | 398 | | var elementInfo = new ArgumentTypeInfo |
| | 0 | 399 | | { |
| | 0 | 400 | | Type = info.ElementType, |
| | 0 | 401 | | TypeCode = info.ElementTypeCode, |
| | 0 | 402 | | }; |
| | | 403 | | |
| | 0 | 404 | | var array = ImmutableArray.CreateBuilder<CustomAttributeTypedArgument<TType>>(count); |
| | | 405 | | |
| | 0 | 406 | | for (int i = 0; i < count; i++) |
| | 0 | 407 | | { |
| | 0 | 408 | | array.Add(DecodeArgument(ref blobReader, elementInfo)); |
| | 0 | 409 | | } |
| | | 410 | | |
| | 0 | 411 | | return array.MoveToImmutable(); |
| | 0 | 412 | | } |
| | | 413 | | |
| | | 414 | | private TType GetTypeFromHandle(EntityHandle handle) => |
| | 0 | 415 | | handle.Kind switch |
| | 0 | 416 | | { |
| | 0 | 417 | | HandleKind.TypeDefinition => _provider.GetTypeFromDefinition(_reader, (TypeDefinitionHandle)handle, 0), |
| | 0 | 418 | | HandleKind.TypeReference => _provider.GetTypeFromReference(_reader, (TypeReferenceHandle)handle, 0), |
| | 0 | 419 | | _ => throw new BadImageFormatException(SR.NotTypeDefOrRefHandle), |
| | 0 | 420 | | }; |
| | | 421 | | |
| | | 422 | | private static void SkipType(ref BlobReader blobReader) |
| | 0 | 423 | | { |
| | 0 | 424 | | int typeCode = blobReader.ReadCompressedInteger(); |
| | | 425 | | |
| | 0 | 426 | | switch (typeCode) |
| | | 427 | | { |
| | | 428 | | case (int)SignatureTypeCode.Boolean: |
| | | 429 | | case (int)SignatureTypeCode.Char: |
| | | 430 | | case (int)SignatureTypeCode.SByte: |
| | | 431 | | case (int)SignatureTypeCode.Byte: |
| | | 432 | | case (int)SignatureTypeCode.Int16: |
| | | 433 | | case (int)SignatureTypeCode.UInt16: |
| | | 434 | | case (int)SignatureTypeCode.Int32: |
| | | 435 | | case (int)SignatureTypeCode.UInt32: |
| | | 436 | | case (int)SignatureTypeCode.Int64: |
| | | 437 | | case (int)SignatureTypeCode.UInt64: |
| | | 438 | | case (int)SignatureTypeCode.Single: |
| | | 439 | | case (int)SignatureTypeCode.Double: |
| | | 440 | | case (int)SignatureTypeCode.IntPtr: |
| | | 441 | | case (int)SignatureTypeCode.UIntPtr: |
| | | 442 | | case (int)SignatureTypeCode.Object: |
| | | 443 | | case (int)SignatureTypeCode.String: |
| | | 444 | | case (int)SignatureTypeCode.Void: |
| | | 445 | | case (int)SignatureTypeCode.TypedReference: |
| | 0 | 446 | | return; |
| | | 447 | | |
| | | 448 | | case (int)SignatureTypeCode.Pointer: |
| | | 449 | | case (int)SignatureTypeCode.ByReference: |
| | | 450 | | case (int)SignatureTypeCode.Pinned: |
| | | 451 | | case (int)SignatureTypeCode.SZArray: |
| | 0 | 452 | | SkipType(ref blobReader); |
| | 0 | 453 | | return; |
| | | 454 | | |
| | | 455 | | case (int)SignatureTypeCode.FunctionPointer: |
| | 0 | 456 | | SignatureHeader header = blobReader.ReadSignatureHeader(); |
| | 0 | 457 | | if (header.IsGeneric) |
| | 0 | 458 | | { |
| | 0 | 459 | | blobReader.ReadCompressedInteger(); // arity |
| | 0 | 460 | | } |
| | | 461 | | |
| | 0 | 462 | | int paramCount = blobReader.ReadCompressedInteger(); |
| | 0 | 463 | | SkipType(ref blobReader); |
| | 0 | 464 | | for (int i = 0; i < paramCount; i++) |
| | 0 | 465 | | SkipType(ref blobReader); |
| | 0 | 466 | | return; |
| | | 467 | | |
| | | 468 | | case (int)SignatureTypeCode.Array: |
| | 0 | 469 | | SkipType(ref blobReader); |
| | 0 | 470 | | blobReader.ReadCompressedInteger(); // rank |
| | 0 | 471 | | int boundsCount = blobReader.ReadCompressedInteger(); |
| | 0 | 472 | | for (int i = 0; i < boundsCount; i++) |
| | 0 | 473 | | { |
| | 0 | 474 | | blobReader.ReadCompressedInteger(); |
| | 0 | 475 | | } |
| | 0 | 476 | | int lowerBoundsCount = blobReader.ReadCompressedInteger(); |
| | 0 | 477 | | for (int i = 0; i < lowerBoundsCount; i++) |
| | 0 | 478 | | { |
| | 0 | 479 | | blobReader.ReadCompressedSignedInteger(); |
| | 0 | 480 | | } |
| | 0 | 481 | | return; |
| | | 482 | | |
| | | 483 | | case (int)SignatureTypeCode.RequiredModifier: |
| | | 484 | | case (int)SignatureTypeCode.OptionalModifier: |
| | 0 | 485 | | blobReader.ReadTypeHandle(); |
| | 0 | 486 | | SkipType(ref blobReader); |
| | 0 | 487 | | return; |
| | | 488 | | |
| | | 489 | | case (int)SignatureTypeCode.GenericTypeInstance: |
| | 0 | 490 | | SkipType(ref blobReader); |
| | 0 | 491 | | int count = blobReader.ReadCompressedInteger(); |
| | 0 | 492 | | for (int i = 0; i < count; i++) |
| | 0 | 493 | | { |
| | 0 | 494 | | SkipType(ref blobReader); |
| | 0 | 495 | | } |
| | 0 | 496 | | return; |
| | | 497 | | |
| | | 498 | | case (int)SignatureTypeCode.GenericTypeParameter: |
| | 0 | 499 | | blobReader.ReadCompressedInteger(); |
| | 0 | 500 | | return; |
| | | 501 | | |
| | | 502 | | case (int)SignatureTypeKind.Class: |
| | | 503 | | case (int)SignatureTypeKind.ValueType: |
| | 0 | 504 | | SkipType(ref blobReader); |
| | 0 | 505 | | break; |
| | | 506 | | |
| | | 507 | | default: |
| | 0 | 508 | | throw new BadImageFormatException(); |
| | | 509 | | } |
| | 0 | 510 | | } |
| | | 511 | | } |
| | | 512 | | } |
| | | 513 | | |