Exemplo n.º 1
1
		public BaseTypeNodeImpl(ITreeNodeGroup treeNodeGroup, ITypeDefOrRef typeDefOrRef, bool isBaseType) {
			TreeNodeGroup = treeNodeGroup;
			this.isBaseType = isBaseType;
			// Keep weak refs to them so we won't prevent removed modules from being GC'd.
			weakRefTypeDefOrRef = new WeakReference(typeDefOrRef);
			weakRefResolvedTypeDef = new WeakReference(null);
		}
Exemplo n.º 2
0
		static bool IsReferencedBy(TypeDef type, ITypeDefOrRef typeRef, int depth) {
			if (depth >= 30)
				return false;
			// TODO: move it to a better place after adding support for more cases.
			if (type == null)
				return false;
			if (typeRef == null)
				return false;

			if (type == typeRef)
				return true;
			if (type.Name != typeRef.Name)
				return false;
			if (type.Namespace != typeRef.Namespace)
				return false;

			if (type.DeclaringType != null || typeRef.DeclaringType != null) {
				if (type.DeclaringType == null || typeRef.DeclaringType == null)
					return false;
				if (!IsReferencedBy(type.DeclaringType, typeRef.DeclaringType, depth + 1))
					return false;
			}

			return true;
		}
Exemplo n.º 3
0
 public TypeDefOrRefSignature(ITypeDefOrRef type, bool isValueType)
 {
     if (type == null)
         throw new ArgumentNullException("type");
     Type = type;
     IsValueType = isValueType;
 }
Exemplo n.º 4
0
 TypeInstanceResolver getTypeInstance(ITypeDefOrRef typeRef)
 {
     TypeInstanceResolver instance;
     if (!typeRefToInstance.TryGetValue(typeRef, out instance))
         typeRefToInstance[typeRef] = instance = new TypeInstanceResolver(type, typeRef);
     return instance;
 }
Exemplo n.º 5
0
		public static EventDefOptions Create(UTF8String name, ITypeDefOrRef eventType) {
			return new EventDefOptions {
				Attributes = 0,
				Name = name,
				EventType = eventType,
			};
		}
Exemplo n.º 6
0
		bool IsGenericParam(ITypeDefOrRef tdr) {
			var ts = tdr as TypeSpec;
			if (ts == null)
				return false;
			var sig = ts.TypeSig.RemovePinnedAndModifiers();
			return sig is GenericSig;
		}
 public GenericInstanceTypeSignature(ITypeDefOrRef genericType)
 {
     if (genericType == null)
         throw new ArgumentNullException("genericType");
     GenericType = genericType;
     GenericArguments = new List<TypeSignature>();
 }
		public void AddInitializeArrayCode(Block block, int start, int numToRemove, ITypeDefOrRef elementType, byte[] data) {
			int index = start;
			block.Replace(index++, numToRemove, Instruction.CreateLdcI4(data.Length / elementType.ToTypeSig().ElementType.GetPrimitiveSize()));
			block.Insert(index++, OpCodes.Newarr.ToInstruction(elementType));
			block.Insert(index++, OpCodes.Dup.ToInstruction());
			block.Insert(index++, OpCodes.Ldtoken.ToInstruction((IField)Create(data)));
			block.Insert(index++, OpCodes.Call.ToInstruction((IMethod)InitializeArrayMethod));
		}
Exemplo n.º 9
0
		public GenericParamOptions(GenericParam gp) {
			this.Number = gp.Number;
			this.Flags = gp.Flags;
			this.Name = gp.Name;
			this.Kind = gp.Kind;
			this.GenericParamConstraints.AddRange(gp.GenericParamConstraints);
			this.CustomAttributes.AddRange(gp.CustomAttributes);
		}
Exemplo n.º 10
0
		public BaseTypesEntryNode(ITypeDefOrRef tr, bool isInterface) {
			if (tr == null)
				throw new ArgumentNullException("tr");
			this.tr = tr;
			this.def = tr.ResolveTypeDef();
			this.isInterface = isInterface;
			this.LazyLoading = true;
		}
Exemplo n.º 11
0
		public GenericParamOptions(GenericParam gp) {
			Number = gp.Number;
			Flags = gp.Flags;
			Name = gp.Name;
			Kind = gp.Kind;
			GenericParamConstraints.AddRange(gp.GenericParamConstraints);
			CustomAttributes.AddRange(gp.CustomAttributes);
		}
		public static ITypeDefOrRef Create(ITypeDefOrRef type, IList<TypeSig> genericArgs) {
			if (genericArgs == null || genericArgs.Count == 0)
				return type;
			var ts = type as TypeSpec;
			if (ts == null)
				return type;
			var newSig = Create(ts.TypeSig, genericArgs);
			return newSig == ts.TypeSig ? type : new TypeSpecUser(newSig);
		}
Exemplo n.º 13
0
		public ExceptionHandlerOptions(Dictionary<object, object> ops, ExceptionHandler eh) {
			this.TryStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryStart);
			this.TryEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.TryEnd);
			this.FilterStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.FilterStart);
			this.HandlerStart = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerStart);
			this.HandlerEnd = (InstructionVM)BodyUtils.TryGetVM(ops, eh.HandlerEnd);
			this.CatchType = eh.CatchType;
			this.HandlerType = eh.HandlerType;
		}
		static ITypeDefOrRef GetNonGenericTypeRef(ITypeDefOrRef typeRef) {
			var ts = typeRef as TypeSpec;
			if (ts == null)
				return typeRef;
			var gis = ts.TryGetGenericInstSig();
			if (gis == null || gis.GenericType == null)
				return typeRef;
			return gis.GenericType.TypeDefOrRef;
		}
Exemplo n.º 15
0
		public EventDefOptions(EventDef evt) {
			this.Attributes = evt.Attributes;
			this.Name = evt.Name;
			this.EventType = evt.EventType;
			this.AddMethod = evt.AddMethod;
			this.InvokeMethod = evt.InvokeMethod;
			this.RemoveMethod = evt.RemoveMethod;
			this.OtherMethods.AddRange(evt.OtherMethods);
			this.CustomAttributes.AddRange(evt.CustomAttributes);
		}
Exemplo n.º 16
0
 static bool IsMarkupExtensions(ITypeDefOrRef def)
 {
     while (def != null)
     {
         if (def.Namespace == "OmniXaml" && def.Name.String == "MarkupExtension")
             return true;
         def = def.GetBaseType();
     }
     return false;
 }
Exemplo n.º 17
0
		public EventDefOptions(EventDef evt) {
			Attributes = evt.Attributes;
			Name = evt.Name;
			EventType = evt.EventType;
			AddMethod = evt.AddMethod;
			InvokeMethod = evt.InvokeMethod;
			RemoveMethod = evt.RemoveMethod;
			OtherMethods.AddRange(evt.OtherMethods);
			CustomAttributes.AddRange(evt.CustomAttributes);
		}
Exemplo n.º 18
0
		public static TypeDefOptions Create(UTF8String ns, UTF8String name, ITypeDefOrRef baseType, bool isNestedType) {
			return new TypeDefOptions {
				Attributes = (isNestedType ? TypeAttributes.NestedPublic : TypeAttributes.Public) | TypeAttributes.AutoLayout | TypeAttributes.Class | TypeAttributes.AnsiClass,
				Namespace = ns ?? UTF8String.Empty,
				Name = name ?? UTF8String.Empty,
				PackingSize = null,
				ClassSize = null,
				BaseType = baseType,
			};
		}
Exemplo n.º 19
0
        public Type resolve(ITypeDefOrRef typeRef)
        {
            var resolver = getTypeResolver(typeRef);
            if (resolver != null)
                return resolver.type;

            var ts = typeRef as TypeSpec;
            if (ts != null && ts.TypeSig is GenericSig)
                return typeof(MGenericParameter);

            return null;
        }
Exemplo n.º 20
0
		static bool Compare(ITypeDefOrRef type, UTF8String expNs, UTF8String expName) {
			if (type == null)
				return false;

			var tr = type as TypeRef;
			if (tr != null)
				return tr.Namespace == expNs && tr.Name == expName;
			var td = type as TypeDef;
			if (td != null)
				return td.Namespace == expNs && td.Name == expName;

			return false;
		}
Exemplo n.º 21
0
		public static void RenderType(ITypeDefOrRef type, Graphics g, Rectangle bounds) {
			var typeDef = type as TypeDef;
			if (typeDef == null) {
				g.DrawImageUnscaledAndClipped(Resources.GetResource<Image>("Icons.ObjModel.type.png"), bounds);
				return;
			}

			Image icon, visibility;

			icon = Resources.GetResource<Image>("Icons.ObjModel.type.png");
			if (typeDef.IsInterface) {
				icon = Resources.GetResource<Image>("Icons.ObjModel.interface.png");
			}
			else if (typeDef.BaseType != null) {
				if (typeDef.IsEnum) {
					icon = Resources.GetResource<Image>("Icons.ObjModel.enum.png");
				}
				else if (typeDef.IsValueType && !typeDef.IsAbstract) {
					icon = Resources.GetResource<Image>("Icons.ObjModel.valuetype.png");
				}
				else if (typeDef.IsDelegate()) {
					icon = Resources.GetResource<Image>("Icons.ObjModel.delegate.png");
				}
			}

			switch (typeDef.Visibility) {
				case TypeAttributes.NotPublic:
				case TypeAttributes.NestedAssembly:
				case TypeAttributes.NestedFamANDAssem:
					visibility = Resources.GetResource<Image>("Icons.ObjModel.internal.png");
					break;
				case TypeAttributes.NestedPrivate:
					visibility = Resources.GetResource<Image>("Icons.ObjModel.private.png");
					break;
				case TypeAttributes.NestedFamily:
					visibility = Resources.GetResource<Image>("Icons.ObjModel.protected.png");
					break;
				case TypeAttributes.NestedFamORAssem:
					visibility = Resources.GetResource<Image>("Icons.ObjModel.famasm.png");
					break;
				case TypeAttributes.Public:
				case TypeAttributes.NestedPublic:
				default:
					visibility = null;
					break;
			}

			g.DrawImageUnscaledAndClipped(icon, bounds);
			if (visibility != null)
				g.DrawImageUnscaledAndClipped(visibility, bounds);
		}
Exemplo n.º 22
0
			public ExceptionInfo(int tryStart, int tryEnd, int filterStart,
				int handlerStart, int handlerEnd, ITypeDefOrRef catchType,
				ExceptionHandlerType handlerType) {
				if (tryStart > tryEnd || filterStart > handlerStart ||
					tryStart < 0 || tryEnd < 0 || filterStart < 0 || handlerStart < 0 || handlerEnd < 0)
					throw new ApplicationException("Invalid start/end/filter/handler indexes");
				this.tryStart = tryStart;
				this.tryEnd = tryEnd;
				this.filterStart = filterStart == handlerStart ? -1 : filterStart;
				this.handlerStart = handlerStart;
				this.handlerEnd = handlerEnd;
				this.catchType = catchType;
				this.handlerType = handlerType;
			}
		public TypeDef ResolveType(ITypeDefOrRef type) {
			if (type == null)
				return null;
			type = GetNonGenericTypeRef(type);

			var typeDef = type as TypeDef;
			if (typeDef != null)
				return typeDef;

			var tr = type as TypeRef;
			if (tr != null)
				return tr.Resolve();

			return null;
		}
Exemplo n.º 24
0
		/// <summary>
		/// Resolve an IField from its name and the resolved delcaring type.
		/// </summary>
		/// <param name="declaringType">Declaring type</param>
		/// <param name="fieldName">Field name</param>
		/// <returns>IField, or null if none found</returns>
		public IField ResolveField(ITypeDefOrRef declaringType, String fieldName)
		{
			if (declaringType is TypeSpec)
				return ResolveField(declaringType as TypeSpec, fieldName);

			TypeDef typeDef = null;
			if (declaringType is TypeDef)
				typeDef = declaringType as TypeDef;
			else if (declaringType is TypeRef)
				typeDef = (declaringType as TypeRef).ResolveTypeDef();

			if (typeDef != null)
				return this.Importer.Import(typeDef.FindField(fieldName));
			else
				return null;
		}
Exemplo n.º 25
0
		public TypeDefOptions(TypeDef type) {
			this.Attributes = type.Attributes;
			this.Namespace = type.Namespace;
			this.Name = type.Name;
			if (type.ClassLayout == null) {
				PackingSize = null;
				ClassSize = null;
			}
			else {
				PackingSize = type.ClassLayout.PackingSize;
				ClassSize = type.ClassLayout.ClassSize;
			}
			this.BaseType = type.BaseType;
			this.CustomAttributes.AddRange(type.CustomAttributes);
			this.DeclSecurities.AddRange(type.DeclSecurities);
			this.GenericParameters.AddRange(type.GenericParameters);
			this.Interfaces.AddRange(type.Interfaces);
		}
		TypeResolver GetTypeResolver(ITypeDefOrRef typeRef) {
			if (typeRef == null)
				return null;
			var scopeType = typeRef.ScopeType;
			var key = scopeType.Namespace + "." + scopeType.TypeName;
			List<TypeResolver> list;
			if (!types.TryGetValue(key, out list))
				return null;

			if (scopeType is TypeDef) {
				foreach (var resolver in list) {
					if (resolver.type.MetadataToken == scopeType.MDToken.Raw)
						return resolver;
				}
			}

			foreach (var resolver in list) {
				if (ResolverUtils.CompareTypes(resolver.type, scopeType))
					return resolver;
			}

			return null;
		}
Exemplo n.º 27
0
		static MethodDef GetMethod(ModuleDef module, IMethod method, ITypeDefOrRef declaringType) {
			if (method == null)
				return null;
			if (method is MethodDef)
				return (MethodDef)method;
			return GetMethod(GetType(module, declaringType), method);
		}
Exemplo n.º 28
0
		public static TypeDef GetType(ModuleDef module, ITypeDefOrRef type) {
			var td = type as TypeDef;
			if (td == null) {
				var tr = type as TypeRef;
				if (tr != null) {
					var trAsm = tr.DefinitionAssembly;
					var modAsm = module.Assembly;
					if (trAsm != null && modAsm != null && trAsm.Name == modAsm.Name)
						td = tr.Resolve();
				}
			}
			return td != null && td.Module == module ? td : null;
		}
Exemplo n.º 29
0
		static ConstantType GetConstantType(TypeSig type, out ITypeDefOrRef enumType) {
			enumType = null;
			var t = type.RemovePinnedAndModifiers();
			switch (t.GetElementType())
			{
			case ElementType.Boolean:	return ConstantType.Boolean;
			case ElementType.Char:		return ConstantType.Char;
			case ElementType.I1:		return ConstantType.SByte;
			case ElementType.U1:		return ConstantType.Byte;
			case ElementType.I2:		return ConstantType.Int16;
			case ElementType.U2:		return ConstantType.UInt16;
			case ElementType.I4:		return ConstantType.Int32;
			case ElementType.U4:		return ConstantType.UInt32;
			case ElementType.I8:		return ConstantType.Int64;
			case ElementType.U8:		return ConstantType.UInt64;
			case ElementType.R4:		return ConstantType.Single;
			case ElementType.R8:		return ConstantType.Double;
			case ElementType.String:	return ConstantType.String;
			case ElementType.Object:	return ConstantType.Object;

			case ElementType.ValueType:
			case ElementType.Class:
				var tdr = ((ClassOrValueTypeSig)t).TypeDefOrRef;
				if (tdr.IsSystemType())
					return ConstantType.Type;
				enumType = tdr;
				return ConstantType.Enum;

			case ElementType.SZArray:
				var elemType = t.Next.RemovePinnedAndModifiers();
				switch (elemType.GetElementType()) {
				case ElementType.Boolean:	return ConstantType.BooleanArray;
				case ElementType.Char:		return ConstantType.CharArray;
				case ElementType.I1:		return ConstantType.SByteArray;
				case ElementType.U1:		return ConstantType.ByteArray;
				case ElementType.I2:		return ConstantType.Int16Array;
				case ElementType.U2:		return ConstantType.UInt16Array;
				case ElementType.I4:		return ConstantType.Int32Array;
				case ElementType.U4:		return ConstantType.UInt32Array;
				case ElementType.I8:		return ConstantType.Int64Array;
				case ElementType.U8:		return ConstantType.UInt64Array;
				case ElementType.R4:		return ConstantType.SingleArray;
				case ElementType.R8:		return ConstantType.DoubleArray;
				case ElementType.String:	return ConstantType.StringArray;
				case ElementType.Object:	return ConstantType.ObjectArray;
				case ElementType.ValueType:
				case ElementType.Class:
					tdr = ((ClassOrValueTypeSig)elemType).TypeDefOrRef;
					if (tdr.IsSystemType())
						return ConstantType.TypeArray;
					enumType = tdr;
					return ConstantType.EnumArray;
				}
				break;
			}

			Debug.Fail(string.Format("Unsupported CA named type: {0}", type));
			return ConstantType.Object;
		}
Exemplo n.º 30
0
		void CreateAssemblyQualifiedName(ITypeDefOrRef typeDefOrRef) {
			if (typeDefOrRef is TypeRef)
				CreateAssemblyQualifiedName((TypeRef)typeDefOrRef);
			else if (typeDefOrRef is TypeDef)
				CreateAssemblyQualifiedName((TypeDef)typeDefOrRef);
			else if (typeDefOrRef is TypeSpec)
				CreateAssemblyQualifiedName((TypeSpec)typeDefOrRef);
			else
				sb.Append(NULLVALUE);
		}
Exemplo n.º 31
0
 protected override void TypeToString(IDecompilerOutput output, ITypeDefOrRef t, bool includeNamespace, IHasCustomAttribute attributeProvider = null) =>
 t.WriteTo(output, includeNamespace ? ILNameSyntax.TypeName : ILNameSyntax.ShortTypeName);
Exemplo n.º 32
0
 /// <summary>
 /// Returns the base type of <paramref name="tdr"/>
 /// </summary>
 /// <param name="tdr">The type</param>
 /// <returns>The base type or <c>null</c> if there's no base type, or if
 /// we couldn't resolve a <see cref="TypeRef"/></returns>
 public static ITypeDefOrRef GetBaseType(this ITypeDefOrRef tdr)
 {
     return(tdr.GetBaseType(false));
 }