Example #1
0
		/// <summary>
		/// </summary>
		/// <remarks>
		/// </remarks>
		public static MDToken DecodeToken(CodedTokenId id, int data)
		{
			MDToken res = new MDToken();
			int tag;
			int rid;
			TokenType tok;

			switch (id) {

				case CodedTokenId.TypeDefOrRef :
					tag = data & 0x03;
					rid = (int) ((uint) data >> 2);
					switch (tag) {

						case 0 :
							tok = TokenType.TypeDef;
							break;

						case 1 :
							tok = TokenType.TypeRef;
							break;

						case 2 :
							tok = TokenType.TypeSpec;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for TypeDefOrRef, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.HasConstant :
					tag = data & 0x03;
					rid = (int) ((uint) data >> 2);
					switch (tag) {

						case 0 :
							tok = TokenType.FieldDef;
							break;

						case 1 :
							tok = TokenType.ParamDef;
							break;

						case 2 :
							tok = TokenType.Property;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for HasConstant, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.HasCustomAttribute :
					tag = data & 0x1F;
					rid = (int) ((uint) data >> 5);
					switch (tag) {

						case 0 :
							tok = TokenType.MethodDef;
							break;

						case 1 :
							tok = TokenType.FieldDef;
							break;

						case 2 :
							tok = TokenType.TypeRef;
							break;

						case 3 :
							tok = TokenType.TypeDef;
							break;

						case 4 :
							tok = TokenType.ParamDef;
							break;

						case 5 :
							tok = TokenType.InterfaceImpl;
							break;

						case 6 :
							tok = TokenType.MemberRef;
							break;

						case 7 :
							tok = TokenType.Module;
							break;

						case 8 :
							tok = TokenType.Permission;
							break;

						case 9 :
							tok = TokenType.Property;
							break;

						case 10 :
							tok = TokenType.Event;
							break;

						case 11 :
							tok = TokenType.Signature;
							break;

						case 12 :
							tok = TokenType.ModuleRef;
							break;

						case 13 :
							tok = TokenType.TypeSpec;
							break;

						case 14 :
							tok = TokenType.Assembly;
							break;

						case 15 :
							tok = TokenType.AssemblyRef;
							break;

						case 16 :
							tok = TokenType.File;
							break;

						case 17 :
							tok = TokenType.ExportedType;
							break;

						case 18 :
							tok = TokenType.ManifestResource;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for HasCustomAttribute, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.HasFieldMarshal :
					tag = data & 0x01;
					rid = (int) ((uint) data >> 1);
					switch (tag) {

						case 0 :
							tok = TokenType.FieldDef;
							break;

						case 1 :
							tok = TokenType.ParamDef;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for HasFieldMarshal, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.HasDeclSecurity :
					tag = data & 0x03;
					rid = (int) ((uint) data >> 2);
					switch (tag) {

						case 0 :
							tok = TokenType.TypeDef;
							break;

						case 1 :
							tok = TokenType.MethodDef;
							break;

						case 2 :
							tok = TokenType.Assembly;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for HasDeclSecurity, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.MemberRefParent :
					tag = data & 0x07;
					rid = (int) ((uint) data >> 3);
					switch (tag) {

						case 0 :
							tok = TokenType.TypeDef;
							break;

						case 1 :
							tok = TokenType.TypeRef;
							break;

						case 2 :
							tok = TokenType.ModuleRef;
							break;

						case 3 :
							tok = TokenType.MethodDef;
							break;

						case 4 :
							tok = TokenType.TypeSpec;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for MemberRefParent, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.HasSemantics :
					tag = data & 0x01;
					rid = (int) ((uint) data >> 1);
					switch (tag) {

						case 0 :
							tok = TokenType.Event;
							break;

						case 1 :
							tok = TokenType.Property;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for HasSemantics, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.MethodDefOrRef :
					tag = data & 0x01;
					rid = (int) ((uint) data >> 1);
					switch (tag) {

						case 0 :
							tok = TokenType.MethodDef;
							break;

						case 1 :
							tok = TokenType.MemberRef;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for MethodDefOrRef, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.MemberForwarded :
					tag = data & 0x01;
					rid = (int) ((uint) data >> 1);
					switch (tag) {

						case 0 :
							tok = TokenType.FieldDef;
							break;

						case 1 :
							tok = TokenType.MethodDef;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for MemberForwarded, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.Implementation :
					tag = data & 0x03;
					rid = (int) ((uint) data >> 2);
					switch (tag) {

						case 0 :
							tok = TokenType.File;
							break;

						case 1 :
							tok = TokenType.AssemblyRef;
							break;

						case 2 :
							tok = TokenType.ExportedType;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for Implementation, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.CustomAttributeType :
					tag = data & 0x07;
					rid = (int) ((uint) data >> 3);
					switch (tag) {

						case 0 :
							tok = TokenType.TypeRef;
							break;

						case 1 :
							tok = TokenType.TypeDef;
							break;

						case 2 :
							tok = TokenType.MethodDef;
							break;

						case 3 :
							tok = TokenType.MemberRef;
							break;

						case 4 :
							tok = TokenType.String;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for CustomAttributeType, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				case CodedTokenId.ResolutionScope :
					tag = data & 0x03;
					rid = (int) ((uint) data >> 2);
					switch (tag) {

						case 0 :
							tok = TokenType.Module;
							break;

						case 1 :
							tok = TokenType.ModuleRef;
							break;

						case 2 :
							tok = TokenType.AssemblyRef;
							break;

						case 3 :
							tok = TokenType.TypeRef;
							break;

						default :
							throw new BadMetaDataException("Invalid coded token for ResolutionScope, unknown table tag - " + tag);
					}
					res = new MDToken(tok, rid);
					break;

				default:
					break;
			}
			return res;
		}
Example #2
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Offset = LEBitConverter.ToInt32(buff, offs);
			offs += sizeof (int);
			this.Flags = (ManifestResourceAttributes) LEBitConverter.ToUInt32(buff, offs);
			offs += sizeof (uint);
			this.Name = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Implementation = TabsDecoder.DecodeToken(CodedTokenId.Implementation, LEBitConverter.ToInt32(buff, offs));
			
		}
Example #3
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Number = LEBitConverter.ToUInt16(buff, offs);
			offs += sizeof (ushort);
			this.Method = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Bound = TabsDecoder.DecodeToken(CodedTokenId.TypeDefOrRef, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Name = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #4
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.MappingFlags = (PInvokeAttributes) LEBitConverter.ToUInt16(buff, offs);
			offs += sizeof (ushort);
			this.MemberForwarded = TabsDecoder.DecodeToken(CodedTokenId.MemberForwarded, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.ImportName = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.ImportScope = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #5
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Flags = (System.Reflection.TypeAttributes) LEBitConverter.ToUInt32(buff, offs);
			offs += sizeof (uint);
			this.TypeDefId = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.TypeName = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.TypeNamespace = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Implementation = TabsDecoder.DecodeToken(CodedTokenId.Implementation, LEBitConverter.ToInt32(buff, offs));
			
		}
Example #6
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Semantics = (MethodSemanticsAttributes) LEBitConverter.ToUInt16(buff, offs);
			offs += sizeof (ushort);
			this.Method = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Association = TabsDecoder.DecodeToken(CodedTokenId.HasSemantics, LEBitConverter.ToInt32(buff, offs));
			
		}
Example #7
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Class = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.MethodBody = TabsDecoder.DecodeToken(CodedTokenId.MethodDefOrRef, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.MethodDeclaration = TabsDecoder.DecodeToken(CodedTokenId.MethodDefOrRef, LEBitConverter.ToInt32(buff, offs));
			
		}
Example #8
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.ResolutionScope = TabsDecoder.DecodeToken(CodedTokenId.ResolutionScope, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Name = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Namespace = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #9
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.EventFlags = (System.Reflection.EventAttributes) LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.Name = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.EventType = TabsDecoder.DecodeToken(CodedTokenId.TypeDefOrRef, LEBitConverter.ToInt32(buff, offs));
			
		}
Example #10
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Parent = TabsDecoder.DecodeToken(CodedTokenId.HasFieldMarshal, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.NativeType = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #11
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Action = LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.Parent = TabsDecoder.DecodeToken(CodedTokenId.HasDeclSecurity, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.PermissionSet = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #12
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Parent = TabsDecoder.DecodeToken(CodedTokenId.HasCustomAttribute, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Type = TabsDecoder.DecodeToken(CodedTokenId.CustomAttributeType, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Value = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #13
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Type = (ElementType) LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.Parent = TabsDecoder.DecodeToken(CodedTokenId.HasConstant, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Value = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #14
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.Class = TabsDecoder.DecodeToken(CodedTokenId.MemberRefParent, LEBitConverter.ToInt32(buff, offs));
			offs += 4;
			this.Name = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Signature = LEBitConverter.ToInt32(buff, offs);
			
		}
Example #15
0
 /// <summary>
 /// </summary>
 /// <param name="tok"></param>
 public MDToken(MDToken tok) : this(tok.Type, tok.RID)
 {
 }
Example #16
0
		/// <summary>
		/// </summary>
		/// <param name="tok"></param>
		public MDToken(MDToken tok) : this(tok.Type, tok.RID)
		{
		}