예제 #1
0
		public FieldDefOptions(FieldDef field) {
			this.Attributes = field.Attributes;
			this.Name = field.Name;
			this.FieldSig = field.FieldSig;
			this.FieldOffset = field.FieldOffset;
			this.MarshalType = field.MarshalType;
			this.RVA = field.RVA;
			this.InitialValue = field.InitialValue;
			this.ImplMap = field.ImplMap;
			this.Constant = field.Constant;
			this.CustomAttributes.AddRange(field.CustomAttributes);
		}
예제 #2
0
		public FieldDefOptions(FieldDef field) {
			Attributes = field.Attributes;
			Name = field.Name;
			FieldSig = field.FieldSig;
			FieldOffset = field.FieldOffset;
			MarshalType = field.MarshalType;
			RVA = field.RVA;
			InitialValue = field.InitialValue;
			ImplMap = field.ImplMap;
			Constant = field.Constant;
			CustomAttributes.AddRange(field.CustomAttributes);
		}
예제 #3
0
		public static FieldDefOptions Create(UTF8String name, FieldSig fieldSig) {
			return new FieldDefOptions {
				Attributes = FieldAttributes.Public,
				Name = name,
				FieldSig = fieldSig,
				FieldOffset = null,
				MarshalType = null,
				RVA = 0,
				InitialValue = null,
				ImplMap = null,
				Constant = null,
			};
		}
 public FieldDef create(byte[] data)
 {
     var arrayType = getArrayType(data.LongLength);
     var fieldSig = new FieldSig(new ValueTypeSig(arrayType));
     var attrs = FieldAttributes.Assembly | FieldAttributes.Static;
     var field = new FieldDefUser(string.Format("field_{0}", unique++), fieldSig, attrs);
     module.UpdateRowId(field);
     field.HasFieldRVA = true;
     ourType.Fields.Add(field);
     var iv = new byte[data.Length];
     Array.Copy(data, iv, data.Length);
     field.InitialValue = iv;
     return field;
 }
예제 #5
0
		bool ContainsGenericParameterInternal(FieldSig fs) {
			if (fs == null)
				return false;
			if (!recursionCounter.Increment())
				return false;

			bool res = ContainsGenericParameterInternal(fs.Type);

			recursionCounter.Decrement();
			return res;
		}
예제 #6
0
파일: FieldDef.cs 프로젝트: EmilZhou/dnlib
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="signature">Signature</param>
		/// <param name="attributes">Flags</param>
		public FieldDefUser(UTF8String name, FieldSig signature, FieldAttributes attributes) {
			this.name = name;
			this.signature = signature;
			this.attributes = (int)attributes;
		}
예제 #7
0
		void Hash(FieldSig sig) {
			if (sig == null)
				return;

			hasher.Hash((byte)sig.GetCallingConvention());
			Hash(sig.GetFieldType());
		}
		/// <summary>
		/// Returns the full name of a field
		/// </summary>
		/// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
		/// <param name="name">Name of field</param>
		/// <param name="fieldSig">Field signature</param>
		/// <param name="typeGenArgs">Type generic arguments or <c>null</c> if none</param>
		/// <returns>Field full name</returns>
		public static string FieldFullName(string declaringType, string name, FieldSig fieldSig, IList<TypeSig> typeGenArgs) {
			var fnc = new FullNameCreator(false, null);
			if (typeGenArgs != null) {
				fnc.genericArguments = new GenericArguments();
				fnc.genericArguments.PushTypeArgs(typeGenArgs);
			}

			fnc.CreateFieldFullName(declaringType, name, fieldSig);
			return fnc.Result;
		}
예제 #9
0
파일: FieldDef.cs 프로젝트: EmilZhou/dnlib
		/// <summary>
		/// Gets the size of this field in bytes or <c>0</c> if unknown.
		/// </summary>
		/// <param name="declaringType">The declaring type of <c>this</c></param>
		/// <param name="fieldSig">The field signature of <c>this</c></param>
		/// <param name="ptrSize">Size of a pointer</param>
		/// <param name="size">Updated with size</param>
		/// <returns><c>true</c> if <paramref name="size"/> is valid, <c>false</c> otherwise</returns>
		protected bool GetFieldSize(TypeDef declaringType, FieldSig fieldSig, int ptrSize, out uint size) {
			size = 0;
			if (fieldSig == null)
				return false;
			return GetClassSize(declaringType, fieldSig.Type, ptrSize, out size);
		}
예제 #10
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="module">Owner module</param>
		/// <param name="name">Name of field ref</param>
		/// <param name="sig">Field sig</param>
		public MemberRefUser(ModuleDef module, UTF8String name, FieldSig sig)
			: this(module, name, sig, null) {
		}
예제 #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="signature">Signature</param>
 /// <param name="flags">Flags</param>
 public FieldDefUser(UTF8String name, FieldSig signature, FieldAttributes flags)
 {
     this.name      = name;
     this.signature = signature;
     this.flags     = flags;
 }
예제 #12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="signature">Signature</param>
 public FieldDefUser(UTF8String name, FieldSig signature)
     : this(name, signature, 0)
 {
 }
예제 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Name</param>
 /// <param name="signature">Signature</param>
 /// <param name="attributes">Flags</param>
 public FieldDefUser(UTF8String name, FieldSig signature, FieldAttributes attributes)
 {
     this.name       = name;
     this.signature  = signature;
     this.attributes = (int)attributes;
 }
예제 #14
0
 FieldSig ResolveGenericArgs(FieldSig sig)
 {
     return(new FieldSig(ResolveGenericArgs(sig.Type)));
 }
예제 #15
0
 /// <summary>
 /// Gets the size of this field in bytes or <c>0</c> if unknown.
 /// </summary>
 /// <param name="declaringType">The declaring type of <c>this</c></param>
 /// <param name="fieldSig">The field signature of <c>this</c></param>
 /// <param name="size">Updated with size</param>
 /// <returns><c>true</c> if <paramref name="size"/> is valid, <c>false</c> otherwise</returns>
 protected bool GetFieldSize(TypeDef declaringType, FieldSig fieldSig, out uint size)
 {
     return(GetFieldSize(declaringType, fieldSig, GetPointerSize(declaringType), out size));
 }
		public static FieldSig Create(FieldSig sig, IList<TypeSig> genericArgs) {
			if (sig == null || genericArgs == null || genericArgs.Count == 0)
				return sig;
			return new GenericArgsSubstitutor(genericArgs).Create(sig);
		}
		public static FieldSig Create(FieldSig sig, GenericInstSig git) {
			if (git == null)
				return sig;
			return Create(sig, git.GenericArguments);
		}
		FieldSig Create(FieldSig sig) {
			var newSig = new FieldSig(Create2(sig.Type));
			return updated ? newSig : sig;
		}
예제 #19
0
		/// <summary>
		/// Checks whether <paramref name="fieldSig"/> contains a <see cref="GenericVar"/> or a
		/// <see cref="GenericMVar"/>.
		/// </summary>
		/// <param name="fieldSig">Field signature</param>
		/// <returns><c>true</c> if <paramref name="fieldSig"/> contains a <see cref="GenericVar"/>
		/// or a <see cref="GenericMVar"/>.</returns>
		public static bool ContainsGenericParameter(FieldSig fieldSig) {
			return new TypeHelper().ContainsGenericParameterInternal(fieldSig);
		}
		/// <summary>
		/// Returns the full name of a field
		/// </summary>
		/// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
		/// <param name="name">Name of field</param>
		/// <param name="fieldSig">Field signature</param>
		/// <returns>Field full name</returns>
		public static string FieldFullName(string declaringType, UTF8String name, FieldSig fieldSig) {
			return FieldFullName(declaringType, UTF8String.ToSystemString(name), fieldSig, null);
		}
예제 #21
0
 void Add(FieldSig sig)
 {
     if (sig == null)
         return;
     Add(sig.Type);
 }
		/// <summary>
		/// Returns the full name of a field
		/// </summary>
		/// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
		/// <param name="name">Name of field</param>
		/// <param name="fieldSig">Field signature</param>
		/// <returns>Field full name</returns>
		public static string FieldFullName(string declaringType, string name, FieldSig fieldSig) {
			return FieldFullName(declaringType, name, fieldSig, null);
		}
예제 #23
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="module">Owner module</param>
		/// <param name="name">Name of field ref</param>
		/// <param name="sig">Field sig</param>
		/// <param name="class">Owner of field</param>
		public MemberRefUser(ModuleDef module, UTF8String name, FieldSig sig, IMemberRefParent @class) {
			this.module = module;
			this.name = name;
			this.@class = @class;
			this.signature = sig;
		}
예제 #24
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="signature">Signature</param>
		/// <param name="flags">Flags</param>
		public FieldDefUser(UTF8String name, FieldSig signature, FieldAttributes flags) {
			this.name = name;
			this.signature = signature;
			this.flags = flags;
		}
		/// <summary>
		/// Returns the full name of a field
		/// </summary>
		/// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
		/// <param name="name">Name of field</param>
		/// <param name="fieldSig">Field signature</param>
		/// <param name="typeGenArgs">Type generic arguments or <c>null</c> if none</param>
		/// <returns>Field full name</returns>
		public static string FieldFullName(string declaringType, UTF8String name, FieldSig fieldSig, IList<TypeSig> typeGenArgs) {
			return FieldFullName(declaringType, UTF8String.ToSystemString(name), fieldSig, typeGenArgs);
		}
예제 #26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="name">Name of field ref</param>
 /// <param name="sig">Field sig</param>
 public MemberRefUser(ModuleDef module, UTF8String name, FieldSig sig)
     : this(module, name, sig, null)
 {
 }
		void CreateFieldFullName(string declaringType, string name, FieldSig fieldSig) {
			CreateFullName(fieldSig == null ? null : fieldSig.Type);
			sb.Append(' ');

			if (declaringType != null) {
				sb.Append(declaringType);
				sb.Append("::");
			}
			if (name != null)
				sb.Append(name);
		}
예제 #28
0
 /// <summary>
 /// Gets the field type
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>Field type or <c>null</c> if none</returns>
 public static TypeSig GetFieldType(this FieldSig sig)
 {
     return(sig == null ? null : sig.Type);
 }
예제 #29
0
파일: FieldDef.cs 프로젝트: EmilZhou/dnlib
		/// <summary>
		/// Gets the size of this field in bytes or <c>0</c> if unknown.
		/// </summary>
		/// <param name="declaringType">The declaring type of <c>this</c></param>
		/// <param name="fieldSig">The field signature of <c>this</c></param>
		/// <param name="size">Updated with size</param>
		/// <returns><c>true</c> if <paramref name="size"/> is valid, <c>false</c> otherwise</returns>
		protected bool GetFieldSize(TypeDef declaringType, FieldSig fieldSig, out uint size) {
			return GetFieldSize(declaringType, fieldSig, GetPointerSize(declaringType), out size);
		}
예제 #30
0
 /// <summary>
 ///     Checks whether <paramref name="fieldSig" /> contains a <see cref="GenericVar" /> or a
 ///     <see cref="GenericMVar" />.
 /// </summary>
 /// <param name="fieldSig">Field signature</param>
 /// <returns>
 ///     <c>true</c> if <paramref name="fieldSig" /> contains a <see cref="GenericVar" />
 ///     or a <see cref="GenericMVar" />.
 /// </returns>
 public static bool ContainsGenericParameter(FieldSig fieldSig)
 {
     return(new TypeHelper().ContainsGenericParameterInternal(fieldSig));
 }
예제 #31
0
파일: FieldDef.cs 프로젝트: EmilZhou/dnlib
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="signature">Signature</param>
		public FieldDefUser(UTF8String name, FieldSig signature)
			: this(name, signature, 0) {
		}
예제 #32
0
 /// <summary>
 /// Returns the full name of a field
 /// </summary>
 /// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
 /// <param name="name">Name of field</param>
 /// <param name="fieldSig">Field signature</param>
 /// <param name="typeGenArgs">Type generic arguments or <c>null</c> if none</param>
 /// <param name="sb">String builder to use or null</param>
 /// <returns>Field full name</returns>
 public static string FieldFullName(string declaringType, string name, FieldSig fieldSig, IList<TypeSig> typeGenArgs, StringBuilder sb)
 {
     return FieldFullNameSB(declaringType, name, fieldSig, typeGenArgs, sb).ToString();
 }
예제 #33
0
 private static void ReFieldSig(FieldSig sig, ModuleDef module)
 {
     var ts = ReferenceType(sig.Type, module);
     if (ts != null)
         sig.Type = ts;
 }
예제 #34
0
        /// <summary>
        /// Returns the full name of a field
        /// </summary>
        /// <param name="declaringType">Declaring type full name or <c>null</c> if none</param>
        /// <param name="name">Name of field</param>
        /// <param name="fieldSig">Field signature</param>
        /// <param name="typeGenArgs">Type generic arguments or <c>null</c> if none</param>
        /// <param name="sb">String builder to use or null</param>
        /// <returns>Field full name</returns>
        public static StringBuilder FieldFullNameSB(string declaringType, string name, FieldSig fieldSig, IList<TypeSig> typeGenArgs, StringBuilder sb)
        {
            var fnc = new FullNameCreator(false, null, sb);
            if (typeGenArgs != null) {
                fnc.genericArguments = new GenericArguments();
                fnc.genericArguments.PushTypeArgs(typeGenArgs);
            }

            fnc.CreateFieldFullName(declaringType, name, fieldSig);
            return fnc.sb ?? new StringBuilder();
        }