Example #1
0
		public MethodSpec CopyTo(MethodSpec ms) {
			ms.Method = this.Method;
			ms.Instantiation = this.Instantiation;
			ms.CustomAttributes.Clear();
			ms.CustomAttributes.AddRange(this.CustomAttributes);
			return ms;
		}
 protected override CallResult createCallResult(IMethod method, MethodSpec gim, Block block, int callInstrIndex)
 {
     int methodId;
     if (!methodTokenToId.TryGetValue(method.MDToken.ToInt32(), out methodId))
         return null;
     return new MyCallResult(block, callInstrIndex, methodId, gim);
 }
Example #3
0
		internal static bool ContainsGenericParameter(MethodSpec ms) {
			if (ms == null)
				return false;

			// A normal MethodSpec should always contain generic arguments and thus
			// its MethodDef is always a generic method with generic parameters.
			return true;
		}
Example #4
0
		public static TypeSig GetGenericArgument(GenericInstSig typeOwner, MethodSpec methodOwner, TypeSig type) {
			var typeArgs = typeOwner == null ? null : typeOwner.GenericArguments;
			var genMethodArgs = methodOwner == null || methodOwner.GenericInstMethodSig == null ?
						null : methodOwner.GenericInstMethodSig.GenericArguments;
			return GenericArgsSubstitutor.Create(type, typeArgs, genMethodArgs);
		}
Example #5
0
		public static IList<TypeSig> ReplaceGenericParameters(GenericInstSig typeOwner, MethodSpec methodOwner, IList<TypeSig> types) {
			if (typeOwner == null && methodOwner == null)
				return types;
			for (int i = 0; i < types.Count; i++)
				types[i] = GetGenericArgument(typeOwner, methodOwner, types[i]);
			return types;
		}
		// Returns null if method is not a method we should inline
		protected abstract CallResult CreateCallResult(IMethod method, MethodSpec gim, Block block, int callInstrIndex);
		public object DecryptDouble(MethodDef method, MethodSpec gim, uint magic1, ulong magic2) {
			if (!VerifyGenericArg(gim, ElementType.R8))
				return null;
			var info = decrypters.Find(method);
			return info.DecryptDouble(magic1, magic2);
		}
		public string DecryptString(MethodDef method, MethodSpec gim, uint magic1, ulong magic2) {
			if (!VerifyGenericArg(gim, ElementType.String))
				return null;
			var info = decrypters.Find(method);
			return info.DecryptString(magic1, magic2);
		}
		static bool VerifyGenericArg(MethodSpec gim, ElementType etype) {
			if (gim == null)
				return false;
			var gims = gim.GenericInstMethodSig;
			if (gims == null || gims.GenericArguments.Count != 1)
				return false;
			return gims.GenericArguments[0].GetElementType() == etype;
		}
		/// <summary>
		/// Checks whether it can access a <see cref="MethodSpec"/>
		/// </summary>
		/// <param name="ms">The method spec</param>
		/// <returns><c>true</c> if it has access to it, <c>false</c> if not, and <c>null</c>
		/// if we can't determine it (eg. we couldn't resolve a type or input was <c>null</c>)</returns>
		public bool? CanAccess(MethodSpec ms) {
			if (ms == null)
				return null;

			var mdr = ms.Method;

			var md = mdr as MethodDef;
			if (md != null)
				return CanAccess(md);

			var mr = mdr as MemberRef;
			if (mr != null)
				return CanAccess(mr);

			return null;
		}
 public MyCallResult(Block block, int callEndIndex, IMethod method, MethodSpec gim)
     : base(block, callEndIndex)
 {
     this.IMethod = method;
     this.gim = gim;
 }
 protected override CallResult createCallResult(IMethod method, MethodSpec gim, Block block, int callInstrIndex)
 {
     if (stringDecrypters.find(method) == null)
         return null;
     return new MyCallResult(block, callInstrIndex, method, gim);
 }
Example #13
0
 /// <summary>
 /// Imports a <see cref="MethodSpec"/>
 /// </summary>
 /// <param name="method">The method</param>
 /// <returns>The imported method or <c>null</c> if <paramref name="method"/> is invalid</returns>
 public MethodSpec Import(MethodSpec method)
 {
     return(new Importer(this).Import(method));
 }
Example #14
0
 void Add(MethodSpec ms)
 {
     if (ms == null || methodSpecs.ContainsKey(ms))
         return;
     if (ms.Method != null && ms.Method.DeclaringType != null && ms.Method.DeclaringType.Module != validModule)
         return;
     methodSpecs[ms] = true;
     Push(ms.Method);
     Add(ms.Instantiation);
     Add(ms.CustomAttributes);
 }
Example #15
0
 public MethodSpecOptions(MethodSpec ms)
 {
     this.Method = ms.Method;
     this.Instantiation = ms.Instantiation;
     this.CustomAttributes.AddRange(ms.CustomAttributes);
 }
		public static MethodSpec Create(MethodSpec method, GenericInstSig git) {
			if (method == null || git == null)
				return method;
			var newMethod = Create(method.Method, git);
			var newInst = Create(method.GenericInstMethodSig, git);
			bool updated = newMethod != method.Method || newInst != method.GenericInstMethodSig;
			return updated ? new MethodSpecUser(newMethod, newInst) : method;
		}