Exemplo n.º 1
0
		public static StackTypes DoMergeStacks(StackTypes s,StackTypes t)
		{
			//assert(s!=null && t!=null)
			if (s.Count != t.Count)
				throw new VerifierException(); //different lengths
			StackTypes u = new StackTypes();
			for (int i = 0; i < s.Count; i++)
			{
				u.Push(TypeChecker.MergeTypes(s[i],t[i]));
			}
			return(u);
		}
Exemplo n.º 2
0
		public static void ProcessNot(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			if(!t.type.IsPrimitive || t.boxed || TypeFixer.IsFloatOrCompatible(t))
				throw new VerifierException();
			stack.Push(TypeFixer.FixType(t));
		}
Exemplo n.º 3
0
		public static void ProcessBinOp(OpType opType, StackTypes stack)
		{
			switch(opType)
			{
				case OpType.Shift:
				{
					TypeEx shift = stack.Pop();
					TypeEx t = stack.Pop();
					if(!(TypeFixer.IsInt32OrCompatible(shift) || TypeFixer.IsIntPtrOrCompatible(shift)))
						throw new VerifierException();
					if(!(TypeFixer.IsInt32OrCompatible(shift) || 
						   TypeFixer.IsIntPtrOrCompatible(shift) || 
						   TypeFixer.IsInt64OrCompatible(shift)))
						throw new VerifierException();
					stack.Push(t);
				} break;
				case OpType.FloatOrInt:
				case OpType.Int:
				{
					TypeEx t1 = stack.Pop();
					TypeEx t2 = stack.Pop();
					TypeEx t3 = Arithmetics.GetReturnType(t1,t2,opType == OpType.FloatOrInt);
					stack.Push(t3);
				} break;
				case OpType.Compare:
				{
					TypeEx t1 = stack.Pop();
					TypeEx t2 = stack.Pop();
					Arithmetics.CheckTypes(t1,t2);
					stack.Push(typeof(int));
				} break;
			}
		}
Exemplo n.º 4
0
		public static void ProcessEndFilter(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			if(!TypeFixer.IsInt32OrCompatible(t))
				throw new VerifierException();
			if(stack.Count != 0)
				throw new VerifierException();
		}
Exemplo n.º 5
0
		public static void ProcessBox(StackTypes stack, Type T)
		{
			TypeEx valueType = stack.Pop();
			if(! valueType.IsBoxable || valueType.boxed)
				throw new VerifierException();
			TypeChecker.CheckAssignment(new TypeEx(T), valueType);
			
			// Skor >> this code was wrong !
			//stack.Push(new TypeEx(valueType.type ,   true   ));
			stack.Push(new TypeEx(T, true));
		}
Exemplo n.º 6
0
		public static void ProcessStInd(Type T, StackTypes stack)
		{
			TypeEx val = stack.Pop();
			TypeEx addr = stack.Pop();
			if(!addr.type.IsByRef)
				throw new VerifierException();
			TypeEx targetType = new TypeEx(addr.type.GetElementType());
			TypeEx sourceType = new TypeEx(T);
			TypeChecker.CheckAssignment(targetType,val);
			CheckPrimitiveIndirectAssignment(targetType,sourceType);
		}
Exemplo n.º 7
0
		public static void ProcessStElem(StackTypes stack, TypeEx desiredArrayElem)
		{
			TypeEx elemValue = stack.Pop();
			TypeEx index = stack.Pop();
			TypeEx array = stack.Pop();
			TypeEx arrayElem = ProcessLdStElem(array,desiredArrayElem,index);
			TypeChecker.CheckAssignment(arrayElem,elemValue);       
		}
Exemplo n.º 8
0
		public static void ProcessSwitch(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			if(!TypeFixer.IsInt32OrCompatible(t))
				throw new VerifierException();
		}
Exemplo n.º 9
0
		public static void ProcessLeave(StackTypes stack)
		{
			if(stack.Count != 0)
				throw new VerifierException();
		}
Exemplo n.º 10
0
		public static void ProcessBrTrueFalse(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			TypeChecker.CheckBrTrueFalseType(t);
		}
Exemplo n.º 11
0
		private static void ProcessSwitch(int iNum,MethodEx method,StackTypes stack)
		{
			int[] INums = (int[])method[iNum].Param;
			for(int i = 0;i<INums.Length;i++)
			{
				CheckSameBlock(method.EHClauses, iNum, INums[i]);
				ProcessBranch(iNum,INums[i],method,stack);
			}
		}
Exemplo n.º 12
0
		private static void ProcessBr(int iNum,MethodEx method,StackTypes stack)
		{
			CheckSameBlock(method.EHClauses, iNum, (int)method[iNum].Param);
			ProcessBranch(iNum, (int)method[iNum].Param, method, stack);
		}
Exemplo n.º 13
0
		private static void ProcessBranch(int iNum,int INum,MethodEx method,StackTypes stack)
		{
			Instruction I = method[INum];
			if(INum > iNum)
				I.SetStack(MergeStacks(I.Stack,stack));
			else 
				CheckStacks(I.Stack,stack);
		}
Exemplo n.º 14
0
		private static StackTypes MergeStacks(StackTypes s,StackTypes t)
		{
			if(s == null)
				if(t == null)
					//both null
					return new StackTypes(); //Andrew: we assume the stack to be empty in this case 
				else 
					//t != null
					return(t);  
			else
				if(t == null) 
				//s != null
				return(s);
			else 
				//both != null
				return DoMergeStacks(s,t);
		}
Exemplo n.º 15
0
		public static void ProcessSt(TypeEx T, StackTypes stack)
		{
			TypeEx t = stack.Pop();
			TypeChecker.CheckAssignment(T,t);
		}
Exemplo n.º 16
0
		private static void ProcessLeave(int iNum,MethodEx method,StackTypes stack)
		{
			CheckCanLeave(method.EHClauses, iNum, (int)method[iNum].Param);
			ProcessLeave(stack);
			ProcessBranch(iNum,(int)method[iNum].Param,method,stack);
		}
Exemplo n.º 17
0
		public static void ProcessStFld(StackTypes stack, FieldInfo field)
		{
			TypeEx fldValue = stack.Pop(); 
			TypeEx obj = stack.Pop();
			if(obj.type.IsByRef)  //STFLD accepts both objects and managed pointers on value-types
			{
				if(! field.DeclaringType.Equals(obj.type.GetElementType()) || !field.DeclaringType.IsValueType )
					throw new VerifierException();
			}
			else
			  TypeChecker.CheckAssignment(new TypeEx(field.DeclaringType),obj);
			TypeChecker.CheckAssignment(new TypeEx(field.FieldType),fldValue);
		}
Exemplo n.º 18
0
		public static void ProcessRet(TypeEx returnType, StackTypes stack)
		{
			if(!returnType.type.Equals(typeof(void))) 
			{
				TypeEx t = stack.Pop();
				TypeChecker.CheckAssignment(returnType, t);
			}
			if(stack.Count != 0)
				throw new VerifierException();
		}
Exemplo n.º 19
0
		public static void ProcessLdElem(StackTypes stack,TypeEx desiredArrayElem,bool loadAddress)
		{
			TypeEx index = stack.Pop();
			TypeEx array = stack.Pop();
			TypeEx arrayElem = ProcessLdStElem(array,desiredArrayElem,index);
			if(loadAddress)
				arrayElem = arrayElem.BuildRefType();
			stack.Push(arrayElem);
		}
Exemplo n.º 20
0
		public static void ProcessThrow(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			TypeChecker.CheckAssignment(new TypeEx(typeof(Exception)), t);
		}
Exemplo n.º 21
0
		public static void ProcessLdLen(StackTypes stack)
		{
			TypeEx array = stack.Pop();
			if(!array.type.IsArray)
				throw new VerifierException();
			stack.Push(typeof(int));
		}
Exemplo n.º 22
0
		public static void ProcessCallOrNewobj(MethodInfoExtention method,StackTypes stack, bool isNewObj)
		{
			for(int i = method.ArgCount-1; i >= (isNewObj ? 1 : 0); i--) 
			{ //when we are creating a new object `this` is not on stack
				TypeEx sourceType = stack.Pop();
				TypeEx targetType = method.GetArgType(i);
				TypeChecker.CheckAssignment(targetType, sourceType);
			}
			TypeEx returnType = method.GetReturnType();
			if(isNewObj)
				stack.Push(method.DeclaringType);
				//Wow! Value-types can be created on stack with NEWOBJ instruction -- not boxed
			else if(!returnType.type.Equals(typeof(void)))
				stack.Push(returnType);
		}
Exemplo n.º 23
0
		public static void ProcessCastClass(StackTypes stack, TypeEx t)
		{
			TypeEx T = stack.Pop();
			if(T.IsBoxable && !T.boxed)
				throw new VerifierException();
			stack.Push(t);
		}
Exemplo n.º 24
0
		public static void ProcessNewArr(StackTypes stack, Type T)
		{
			TypeEx t = stack.Pop();
			if(!TypeFixer.IsInt32OrCompatible(t) && !TypeFixer.IsIntPtrOrCompatible(t))
				throw new VerifierException();
			stack.Push( TypeEx.BuildArrayType(T) );
		}
Exemplo n.º 25
0
		public static void ProcessUnBox(StackTypes stack, Type T)
		{
			TypeEx objType = stack.Pop();
			Type valueType = T;
			if(! ((objType.IsBoxable && objType.boxed) || !objType.IsBoxable) )
				throw new VerifierException();
			if(! valueType.IsValueType )
				throw new VerifierException();
			stack.Push( TypeEx.BuildRefType(valueType) );
		}
Exemplo n.º 26
0
		public static void ProcessLdFld(StackTypes stack, FieldInfo field, bool loadAddress)
		{
			TypeEx obj = stack.Pop();
			if(obj.type != null) //LDNULL LDFLD -- crazy!
			{
				if(obj.type.IsByRef)  //LDFLD to the structure accepts this structure address 
				{
					if(! field.DeclaringType.Equals(obj.type.GetElementType()) || !field.DeclaringType.IsValueType )
						throw new VerifierException();
				}
				else
					TypeChecker.CheckAssignment(new TypeEx(field.DeclaringType),obj);
			}
			Type fieldType = field.FieldType;
			if(loadAddress)
				fieldType = TypeEx.BuildRefType(fieldType);
			stack.Push(fieldType);
		}
Exemplo n.º 27
0
		public static void ProcessNeg(StackTypes stack)
		{
			TypeEx t = stack.Pop();
			if(!t.type.IsPrimitive || t.boxed)
				throw new VerifierException();
			stack.Push(TypeFixer.FixType(t));
		}
Exemplo n.º 28
0
		static public void ProcessLdInd(Type T, StackTypes stack)   
		{
			TypeEx addr = stack.Pop();
			if(!addr.type.IsByRef)
				throw new VerifierException();
			TypeEx sourceType = new TypeEx(addr.type.GetElementType());
			TypeEx targetType = new TypeEx(T);
			if(targetType.type.Equals(typeof(object))) //.ref suffix
				stack.Push(sourceType);
			else
			{
				TypeChecker.CheckAssignment(targetType,sourceType);
				stack.Push(targetType);
			}
		}
Exemplo n.º 29
0
 private static void SetNodeStack(Node node, StackTypes stack)
 {
     node.Options["StackTypes"] = stack;
 }
Exemplo n.º 30
0
		private static void CheckStacks(StackTypes s,StackTypes t)
		{
			if(! IsStackMoreGeneral(s,t))
				throw new VerifierException();
		}