Rogue Entries in TypeSpec Metadata Table

I have a .NET library and am trying to understand more about the internal workings of .NET. Therefore, I move on to the ECMA-335 specification and use CFF Explorer VII.

My question is that in a TypeSpec table, the signature is an index into the Blob heap and should be a TypeSpec signature, as described in section 23.2.14. This means that it can be PTR, FNPTR, ARRAY, SZARRAY, GENERICINSTANCE (ELEMENT_TYPE_ removed for short).

However, I have two entries in this TypeSpec table that apparently do not refer to any other table in the metadata and are of type VAR 0x13 and MVAR 0x1e.

This assembly was compiled in VS2010 against .NET 4.

ECMA-335 will make me believe that this is a bug, but it was compiled using the MS C # compiler.

Does anyone know what it is and what they mean?

Update:

After repeatedly involving this code, these two records are created in the TypeSpec table.

public class AllOutputTypesClass<T> {
    public void GenericMethod<N>(N anItem) {
        string s = anItem.ToString();
    }

    public string GenericMethod<N>(T anItem, N secondItem) {
        return anItem.ToString();
    }
}
+5
source share
2 answers

If you use ILDasm, you can get a good analysis of the methods, go to View -> Meta Info -> select More Hex. Then go to the menu "View" - "Meta-info" → Show!

Here is a breakdown for the second method:

    Method #2 (06000002) 
-------------------------------------------------------
    MethodName: GenericMethod (06000002)
    Flags     : [Public] [HideBySig] [ReuseSlot]  (00000086)
    RVA       : 0x0000206c
    ImplFlags : [IL] [Managed]  (00000000)
    CallCnvntn: [DEFAULT]
    hasThis 
    generic 
    Type Arity:1 
    ReturnType: String
    2 Arguments
        Argument #1:  Var!0
        Argument #2:  MVar!!0
    Signature : 30 01 02 0e 13 00 1e 00 
    1 Generic Parameters
        (0) GenericParamToken : (2a000003) Name : N flags: 00000000 Owner: 06000002
    2 Parameters
        (1) ParamToken : (08000002) Name : anItem flags: [none] (00000000)
        (2) ParamToken : (08000003) Name : secondItem flags: [none] (00000000)

If you scroll down the page, you will also see TypeSpec table entries.

TypeSpe # 1 (1b000001)

TypeSpec : MVar!!0
Signature: 1e 00 

TypeSpe # 2 (1b000002)

TypeSpec : Var!0
Signature: 13 00 

ILDasm, VAR (13 00) T, ( ), MVAR (1e 00) - N, ( ).

... , - TypeSpec IL. , - . ILdasm, :

    .method /*06000001*/ public hidebysig instance void 
        'GenericMethod'<'N'>(!!'N' 'anItem') cil managed
// SIG: 30 01 01 01 1E 00
{
  // Method begins at RVA 0x2050
  // Code size       16 (0x10)
  .maxstack  1
  .locals /*11000001*/ init ([0] string 's')
  IL_0000:  /* 00   |                  */ nop
  IL_0001:  /* 0F   | 01               */ ldarga.s   'anItem'
  IL_0003:  /* FE16 | (1B)000001       */ constrained. !!'N'/*1B000001*/
  IL_0009:  /* 6F   | (0A)000011       */ callvirt   instance string ['mscorlib'/*23000001*/]'System'.'Object'/*01000001*/::'ToString'() /* 0A000011 */
  IL_000e:  /* 0A   |                  */ stloc.0
  IL_000f:  /* 2A   |                  */ ret
} // end of method 'AllOutputTypesClass`1'::'GenericMethod'

.method /*06000002*/ public hidebysig instance string 
        'GenericMethod'<'N'>(!'T' 'anItem',
                             !!'N' 'secondItem') cil managed
// SIG: 30 01 02 0E 13 00 1E 00
{
  // Method begins at RVA 0x206c
  // Code size       19 (0x13)
  .maxstack  1
  .locals /*11000001*/ init ([0] string 'CS$1$0000')
  IL_0000:  /* 00   |                  */ nop
  IL_0001:  /* 0F   | 01               */ ldarga.s   'anItem'
  IL_0003:  /* FE16 | (1B)000002       */ constrained. !'T'/*1B000002*/
  IL_0009:  /* 6F   | (0A)000011       */ callvirt   instance string ['mscorlib'/*23000001*/]'System'.'Object'/*01000001*/::'ToString'() /* 0A000011 */
  IL_000e:  /* 0A   |                  */ stloc.0
  IL_000f:  /* 2B   | 00               */ br.s       IL_0011
  IL_0011:  /* 06   |                  */ ldloc.0
  IL_0012:  /* 2A   |                  */ ret
} // end of method 'AllOutputTypesClass`1'::'GenericMethod'

0x1b - TypeSpec, , :

  IL_0003:  /* FE16 | (1B)000001       */ constrained. !!'N'/*1B000001*/

IL_0003:  /* FE16 | (1B)000002       */ constrained. !'T'/*1B000002*/
+2

TypeSpec IL , . , IL :

.method public hidebysig instance string 
        GenericMethod<N>(!T anItem,
                         !!N secondItem) cil managed
{
  // Code size       19 (0x13)
  .maxstack  1
  .locals init (string V_0)
  IL_0000:  nop
  IL_0001:  ldarga.s   anItem
  IL_0003:  constrained. !T
  IL_0009:  callvirt   instance string [mscorlib]System.Object::ToString()
  IL_000e:  stloc.0
  IL_000f:  br.s       IL_0011
  IL_0011:  ldloc.0
  IL_0012:  ret
} // end of method AllOutputTypesClass`1::GenericMethod

TypeSpec "! T" . TypeSpec .

+4

All Articles