Disassembling .Net Notes: Field Signatures Part 4

by Jason Haley 12. October 2008 07:16

These notes cover 2 more generic fields and several simple types.  There is quite a bit here, but mostly it is just for reference, the generic types are very similar to the one in Example 3 and the simple types are really simple since the Element Type is what signifies the field's type.  I included them all for completeness only.

Example 4: Decoding a field signature of a generic type that is a struct (value type)

C# code:

private GenericValType<int> _genericValueType;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x15 = ELEMENT_TYPE_GENERICINST

The definition for decoding a GENERICINST is: GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type Type*

0x11 = ELEMENT_TYPE_VALUETYPE

0x10 TypeDefOrRefEncoded token

image

0x10 is a compressed integer of 16 (0x10) - which is the same compressed or uncompressed

image

The TypeDefOrRefEncoded token is a TypeDef and a RID of  4, which is the record for SignatureUtility.GenericValueType`1 in the TypeDef table.

image

0x01 = GenArg Count (compressed/uncompressed value the same)

0x08 = ELEMENT_TYPE_I4 which is a .Net type of System.Int32 or int is C#

 

Example 5: Decoding a field signature of a generic type with 2 generic arguments

C# Code:

private Dictionary<int, string> _genericInstClass2Args;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x15 = ELEMENT_TYPE_GENERICINST

The definition for decoding a GENERICINST is: GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type Type*

0x12 = ELEMENT_TYPE_CLASS

0x19 TypeDefOrRefEncoded Token

image

0x10 is a compressed integer of 25 (0x19) - which is the same compressed or uncompressed

image

The TypeDefOrRefEncoded token is a TypeRef and a RID of 6, which is the record System.Collections.Generic.Dictionary`2 record in the TypeRef table.

image

0x02 = GenArg Count (compressed/uncompressed value the same)

0x08 = ELEMENT_TYPE_I4 which is a .Net type of System.Int32 or int is C#

0x0e = ELEMENT_TYPE_STRING which is a .Net type of System.String or string in C#

 

Example 6: Decoding a field signature of a boolean type

C# Code:

private bool _bool;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x02 = ELEMENT_TYPE_BOOLEAN (System.Boolean)

 

Example 7: Decoding a field signature of a char type

C# Code:

private char _char;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x03 = ELEMENT_TYPE_CHAR (System.Char)

 

Example 8: Decoding a field signature of a SByte type

C# Code:

private SByte _int8;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x04 = ELEMENT_TYPE_I1 (System.SByte)

 

Example 9: Decoding a field signature of a Byte type

C# Code:

private Byte _uint8;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x05 = ELEMENT_TYPE_U1 (System.Byte)

 

Example 10: Decoding a field signature of a Int16 type

C# Code:

private Int16 _int16;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x06 = ELEMENT_TYPE_I2 (System.Int16)

 

Example 11: Decoding a field signature of a UInt16 type

C# Code:

private UInt16 _uint16;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x07 = ELEMENT_TYPE_U2 (System.UInt16)

 

Example 12: Decoding a field signature of a Int32 type

C# Code:

private Int32 _int32;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x08 = ELEMENT_TYPE_I4 (System.Int32)

 

Example 13: Decoding a field signature of a UInt32 type

C# Code:

private UInt32 _uint32;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x09 = ELEMENT_TYPE_U4 (System.UInt32)

 

Example 14: Decoding a field signature of a Int64 type

C# Code:

private Int64 _int64;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x0a = ELEMENT_TYPE_I8 (System.Int64)

 

Example 15: Decoding a field signature of a UInt64 type

C# Code:

private UInt64 _uint64;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x0b = ELEMENT_TYPE_U8 (System.UInt64)

 

Example 16: Decoding a field signature of a Single type

C# Code:

private Single _float32;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x0c = ELEMENT_TYPE_R4 (System.Single)

 

Example 17: Decoding a field signature of a Double type

C# Code:

private Double _float64;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x0d = ELEMENT_TYPE_R8 (System.Double)

 

Example 18: Decoding a field signature of a IntPtr type

C# Code:

private IntPtr _nativeInt;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x18 = ELEMENT_TYPE_I (System.IntPtr)

 

Example 19: Decoding a field signature of a UIntPtr type

C# Code:

private UIntPtr _nativeUInt;

Field Information from ILDasm:

 image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x19 = ELEMENT_TYPE_U (System.UIntPtr)

 

Example 20: Decoding a field signature of a Object type

C# Code:

private Object _object;

Field Information from ILDasm:

image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x1c = ELEMENT_TYPE_OBJECT (System.Object)

 

Example 21: Decoding a field signature of a String type

C# Code:

private String _string;

Field Information from ILDasm:

  image

0x06 = IMAGE_CEE_CS_CALLCONV_FIELD

0x0e = ELEMENT_TYPE_STRING (System.String)

Next Notes will provide:

  1. Decoding vectors (0 based, single dimensional arrays)
  2. Decoding arrays

After arrays I think I'll go onto the next signature type instead of diving into the 6 remaining types of type that fields can be (various pointers and variants) ... I'll get back to these types after I get the managed scenarios working first.

Comments (0) | Post RSSRSS comment feed |

Categories:
Tags:

Comments are closed