Beispiel #1
0
		public void VisitNewObj(NewObj newobj)
		{								
			if (newobj.Ctor.ToString().StartsWith("System.Void System.Threading.ThreadStart::.ctor("))
			{
				m_newOffsets.Add(newobj.Untyped.Offset);
				Log.DebugLine(this, "   found new at: {0:X2}", newobj.Untyped.Offset);
			}
		}
Beispiel #2
0
		public void VisitNew(NewObj obj)
		{
			if (m_offset < 0 && obj.Index + 1 < m_info.Instructions.Length)
			{
				TypedInstruction prev = m_info.Instructions[obj.Index + 1];
				if (prev.Untyped.OpCode.Code == Code.Pop)
				{
					m_offset = obj.Untyped.Offset;						
					Log.DebugLine(this, "Matched at {0:X2}", m_offset);				
				}
			}
		}
Beispiel #3
0
		public void VisitNew(NewObj obj)
		{
			string name = obj.Ctor.ToString();
			if (name == "System.Void System.Random::.ctor()")
			{
				Log.DebugLine(this, "found new at {0:X2}", obj.Untyped.Offset);
				++m_numNew;
	
				if (m_offset < 0)
					m_offset = obj.Untyped.Offset;
			}
		}
Beispiel #4
0
		public void VisitNew(NewObj obj)	
		{
			if (m_offset < 0)
			{
				if (obj.Ctor.ToString() == "System.Void System.Text.RegularExpressions.Regex::.ctor(System.String)")
				{
					LoadString prev = m_info.Instructions[obj.Index - 1] as LoadString;
					if (prev != null && !DoIsValidRegEx(prev.Value))
					{
						m_offset = obj.Untyped.Offset;
					}
				}
			}
		}
Beispiel #5
0
		public void VisitNew(NewObj newer)
		{				
			if (m_offset < 0)
			{
				if (newer.Ctor.ToString().StartsWith("System.Void System.Threading.Mutex::.ctor(") || newer.Ctor.ToString().StartsWith("System.Void System.Threading.Semaphore::.ctor("))
				{
					for (int i = 0; i < newer.Ctor.Parameters.Count && m_offset < 0; ++i)
					{
						if (newer.Ctor.Parameters[i].ParameterType.FullName == "System.String")
						{
							m_offset = newer.Untyped.Offset;
							Log.DebugLine(this, "found bad call at {0:X2}", m_offset);
						}
					}
				}
			}
		}
		public void VisitNew(NewObj obj)
		{
			if (m_needsCheck && m_offset < 0)
			{
				TypeReference tr = obj.Ctor.DeclaringType;
				if (tr.IsSameOrSubclassOf("System.Security.CodeAccessPermission", Cache))
				{
					m_offset = obj.Untyped.Offset;
					Log.DebugLine(this, "found CAS at {0:X2}", m_offset);
				}
				else if (tr.IsSameOrSubclassOf("System.Security.PermissionSet", Cache))
				{
					m_offset = obj.Untyped.Offset;
					Log.DebugLine(this, "found PS at {0:X2}", m_offset);
				}
			}
		}
		public void VisitNew(NewObj obj)
		{
			if (m_offset < 0 && m_args.Count > 0)
			{
				if (obj.Ctor.ToString() == "System.Void System.ArgumentNullException::.ctor(System.String)" || obj.Ctor.ToString() == "System.Void System.ArgumentOutOfRangeException::.ctor(System.String)")
				{
					LoadString load = m_info.Instructions[obj.Index - 1] as LoadString;
					if (load != null)
					{
						if (m_args.IndexOf(load.Value) < 0)
						{
							m_offset = obj.Untyped.Offset;						
							Log.DebugLine(this, "bad new at {0:X2}", m_offset);				
						}
					}
				}
			}
		}
Beispiel #8
0
		public void VisitNewObj(NewObj newobj)
		{
			if (!m_foundCtor)
			{
				Log.DebugLine(this, "newobj.Ctor.DeclaringType: {0}", newobj.Ctor.DeclaringType.FullName);
				
				if (newobj.Ctor.DeclaringType.IsSameOrSubclassOf("System.Data.DataSet", Cache))
					m_foundCtor = true;

				else if (newobj.Ctor.DeclaringType.IsSameOrSubclassOf("System.Data.DataTable", Cache))
					m_foundCtor = true;

				Log.DebugLine(this, "   m_foundCtor: {0}", m_foundCtor);

				if (m_foundCtor)
					m_offset = newobj.Untyped.Offset;											
			}
		}
		public void VisitNew(NewObj newer)
		{
			if (m_offset < 0 && newer.Ctor.ToString().StartsWith("System.Void System.ObjectDisposedException::.ctor("))
			{
				int numArgs = newer.Ctor.Parameters.Count;
				int index = m_info.Tracker.GetStackIndex(newer.Index, numArgs - 1);
				
				if (index >= 0)
				{
					LoadString arg = m_info.Instructions[index] as LoadString;
					if (arg != null)
					{
						m_offset = newer.Untyped.Offset;
						Log.DebugLine(this, "bad exception at {0:X2}", m_offset); 
					}
				}
			}
		}
		public void VisitNewObj(NewObj newobj)
		{
			if (m_needsCheck && m_offset < 0)
			{
				string name = newobj.Ctor.DeclaringType.FullName;
				Log.DebugLine(this, "newobj.Ctor.DeclaringType: {0}", name);
				
				if (name == "System.ArgumentException" || 
					name == "System.ArgumentNullException" || 
					name == "System.ArgumentOutOfRangeException" || 
					name == "System.DuplicateWaitObjectException")
				{
					if (newobj.Ctor.Parameters.Count == 0)
					{
						m_offset = newobj.Untyped.Offset;											
						Log.DebugLine(this, "   bad call at {0:X2}", m_offset);
					}
				}
			}
		}
		public void VisitNew(NewObj obj)
		{
			if (m_offset < 0)
			{
				if (obj.Ctor.ToString() == "System.Void System.ArgumentException::.ctor(System.String)")
				{
					LoadString load = m_info.Instructions[obj.Index - 1] as LoadString;
					if (load != null)
					{
						for (int i = 0; i < m_info.Method.Parameters.Count; ++i)
						{
							if (m_info.Method.Parameters[i].Name == load.Value)
							{
								m_offset = obj.Untyped.Offset;						
								Log.DebugLine(this, "bad new at {0:X2}", m_offset);				
							}
						}
					}
				}
			}
		}
Beispiel #12
0
		public void VisitNew(NewObj newer)
		{
			if (newer.Ctor.Parameters.Count == 0 && newer.Ctor.DeclaringType != m_method.DeclaringType)
			{
				Log.DebugLine(this, "default ctor call: {0}", newer.Ctor);	
				
				TypeDefinition type = Cache.FindType(newer.Ctor.DeclaringType);
				if (type != null)
				{
					FieldDefinition field = type.Fields.GetField("Empty");
					if (field != null && field.IsPublic)
					{
						string details = "Type: " + newer.Ctor.DeclaringType.FullName;
						Log.DebugLine(this, details);	
						Reporter.MethodFailed(m_method, CheckID, newer.Untyped.Offset, details);
					}
				}
				else
					Log.InfoLine(this, "couldn't find definition for {0}", newer.Ctor.DeclaringType.FullName);	
			}
		}
		public void VisitNew(NewObj obj)
		{
			if (m_offset < 0)
			{
				if (obj.Ctor.ToString().StartsWith("System.Void System.Security.NamedPermissionSet::.ctor(System.String"))
				{
					int numArgs = obj.Ctor.Parameters.Count;
					int entry = numArgs - 1;
					int index = m_info.Tracker.GetStackIndex(obj.Index, entry);
				
					if (index >= 0)
					{
						LoadString load = m_info.Instructions[index] as LoadString;
						if (load != null && Array.IndexOf(m_bad, load.Value) >= 0)
						{
							m_offset = load.Untyped.Offset;
							Log.DebugLine(this, "found bad code at {0:X2}", m_offset); 
						}
					}
				}
			}
		}
Beispiel #14
0
		public void VisitNew(NewObj newer)
		{
			if (m_offset < 0)
			{				
				if (DoMatchCtor(newer.Ctor))
				{
					MethodDefinition method = DoFindCtor(newer.Ctor);
					if (method != null)
					{
						Log.DebugLine(this, "found ctor at {0:X2}", newer.Untyped.Offset);				
						for (int i = 0; i < method.Parameters.Count && m_offset < 0; ++i)
						{
							ParameterDefinition p = method.Parameters[i];
							Log.DebugLine(this, "checking parameter{0}: {1}", i, p.Name);				
							if (DoIsValidArg(p))
							{
								Log.DebugLine(this, "found parameter at {0}", i);				
								int nth = method.Parameters.Count - i - 1;		
								DoCheck(newer, newer.Ctor, nth);
							}
						}
					}
				}
			}
		}
Beispiel #15
0
		public void VisitNew(NewObj obj)
		{	
			DoAdd(obj.Ctor.DeclaringType);
		}
Beispiel #16
0
        // ldftn    System.Void Smokey.Tests.StaticSetterTest/GoodCase::DoThread(System.Object)
        // newobj   System.Void System.Threading.ParameterizedThreadStart::.ctor(System.Object,System.IntPtr)
		//
        // ldftn    System.Void Smokey.Tests.StaticSetterTest/BadCase3::DoThread()
        // newobj   System.Void System.Threading.ThreadStart::.ctor(System.Object,System.IntPtr)
        //
        // ldftn    System.Void Smokey.Tests.StaticSetterTest/BadCase5::DoCallback(System.Object)
        // newobj   System.Void System.Threading.WaitCallback::.ctor(System.Object,System.IntPtr)
        //
        // ldftn    System.Void Smokey.Tests.StaticSetterTest/BadCase7::DoCallback(System.Object)
        // newobj   System.Void System.Threading.TimerCallback::.ctor(System.Object,System.IntPtr)
		public void VisitNewObj(NewObj newobj)
		{		
			if (newobj.Ctor.ToString().Contains("System.Threading"))	// optimize common case where it's not a threading call
			{
				if (newobj.Ctor.ToString().Contains("System.Threading.ParameterizedThreadStart::.ctor") ||
					newobj.Ctor.ToString().Contains("System.Threading.ThreadStart::.ctor") ||
					newobj.Ctor.ToString().Contains("System.Threading.WaitCallback::.ctor") ||
					newobj.Ctor.ToString().Contains("System.Threading.TimerCallback::.ctor"))
				{
					LoadFunctionAddress fptr = m_info.Instructions[newobj.Index - 1] as LoadFunctionAddress;
					if (fptr != null)
					{
						Log.DebugLine(this, "found thread function: {0}", fptr.Method);	
						m_threadRoots.Add(fptr.Method);
					}
				}
			}
		}
Beispiel #17
0
		public void VisitNewObj(NewObj newobj)
		{
			DBC.Assert(m_state == State.Calls, "state is {0}", m_state);

			if (m_types.Count > 0)
			{
				DoRemoveTypes(newobj.Ctor.DeclaringType);
			}
		}
Beispiel #18
0
		// newobj   System.Void System.ObjectDisposedException::.ctor(System.String)
		public void VisitNewObj(NewObj call)
		{
			if (m_disposable)
			{
				if (call.Ctor.ToString().Contains("ObjectDisposedException"))
					m_doesThrow = true;
			}
		}
Beispiel #19
0
        private TypedInstruction DoGetTyped(MethodDefinition method, Instruction untyped, int index)
        {
            TypedInstruction instruction = null;

            switch (untyped.OpCode.Code)
            {
            case Code.Add:
            case Code.Add_Ovf:
            case Code.Add_Ovf_Un:
            case Code.And:
            case Code.Div:
            case Code.Div_Un:
            case Code.Mul:
            case Code.Mul_Ovf:
            case Code.Mul_Ovf_Un:
            case Code.Or:
            case Code.Rem:
            case Code.Rem_Un:
            case Code.Shl:
            case Code.Shr:
            case Code.Shr_Un:
            case Code.Sub:
            case Code.Sub_Ovf:
            case Code.Sub_Ovf_Un:
            case Code.Xor:
                instruction = new BinaryOp(untyped, index);
                break;

            case Code.Beq:
            case Code.Beq_S:
            case Code.Bge:
            case Code.Bge_S:
            case Code.Bge_Un:
            case Code.Bge_Un_S:
            case Code.Bgt:
            case Code.Bgt_S:
            case Code.Bgt_Un:
            case Code.Bgt_Un_S:
            case Code.Ble:
            case Code.Ble_S:
            case Code.Ble_Un:
            case Code.Ble_Un_S:
            case Code.Blt:
            case Code.Blt_S:
            case Code.Blt_Un:
            case Code.Blt_Un_S:
            case Code.Bne_Un:
            case Code.Bne_Un_S:
            case Code.Brfalse:
            case Code.Brfalse_S:
            case Code.Brtrue:
            case Code.Brtrue_S:
                instruction = new ConditionalBranch(untyped, index);
                break;

            case Code.Box:
                instruction = new Box(untyped, index);
                break;

            case Code.Br:
            case Code.Br_S:
            case Code.Leave:
            case Code.Leave_S:
                instruction = new UnconditionalBranch(untyped, index);
                break;

            case Code.Call:
            case Code.Callvirt:
                instruction = new Call(untyped, index);
                break;

            case Code.Castclass:
            case Code.Isinst:
                instruction = new CastClass(untyped, index);
                break;

            case Code.Ceq:
                instruction = new Ceq(untyped, index);
                break;

            case Code.Cgt:
            case Code.Cgt_Un:
            case Code.Clt:
            case Code.Clt_Un:
                instruction = new Compare(untyped, index);
                break;

            case Code.Conv_I1:
            case Code.Conv_I2:
            case Code.Conv_I4:
            case Code.Conv_I8:
            case Code.Conv_R4:
            case Code.Conv_R8:
            case Code.Conv_U4:
            case Code.Conv_U8:
            case Code.Conv_R_Un:
            case Code.Conv_Ovf_I1_Un:
            case Code.Conv_Ovf_I2_Un:
            case Code.Conv_Ovf_I4_Un:
            case Code.Conv_Ovf_I8_Un:
            case Code.Conv_Ovf_U1_Un:
            case Code.Conv_Ovf_U2_Un:
            case Code.Conv_Ovf_U4_Un:
            case Code.Conv_Ovf_U8_Un:
            case Code.Conv_Ovf_I_Un:
            case Code.Conv_Ovf_U_Un:
            case Code.Conv_Ovf_I1:
            case Code.Conv_Ovf_U1:
            case Code.Conv_Ovf_I2:
            case Code.Conv_Ovf_U2:
            case Code.Conv_Ovf_I4:
            case Code.Conv_Ovf_U4:
            case Code.Conv_Ovf_I8:
            case Code.Conv_Ovf_U8:
            case Code.Conv_U2:
            case Code.Conv_U1:
            case Code.Conv_I:
            case Code.Conv_Ovf_I:
            case Code.Conv_Ovf_U:
            case Code.Conv_U:
                instruction = new Conv(untyped, index);
                break;

            case Code.Endfilter:
            case Code.Endfinally:
            case Code.Ret:
            case Code.Rethrow:
                instruction = new End(untyped, index);
                break;

            case Code.Initobj:
                instruction = new InitObj(untyped, index);
                break;

            case Code.Ldarg_0:
            case Code.Ldarg_1:
            case Code.Ldarg_2:
            case Code.Ldarg_3:
            case Code.Ldarg:
            case Code.Ldarg_S:
                instruction = new LoadArg(method, untyped, index);
                break;

            case Code.Ldarga:
            case Code.Ldarga_S:
                instruction = new LoadArgAddress(method, untyped, index);
                break;

            case Code.Ldc_I4_M1:
            case Code.Ldc_I4_0:
            case Code.Ldc_I4_1:
            case Code.Ldc_I4_2:
            case Code.Ldc_I4_3:
            case Code.Ldc_I4_4:
            case Code.Ldc_I4_5:
            case Code.Ldc_I4_6:
            case Code.Ldc_I4_7:
            case Code.Ldc_I4_8:
            case Code.Ldc_I4_S:
            case Code.Ldc_I4:
            case Code.Ldc_I8:
                instruction = new LoadConstantInt(untyped, index);
                break;

            case Code.Ldc_R4:
            case Code.Ldc_R8:
                instruction = new LoadConstantFloat(untyped, index);
                break;

            case Code.Ldelema:
            case Code.Ldtoken:
                instruction = new LoadPointer(untyped, index);
                break;

            case Code.Ldelem_I1:
            case Code.Ldelem_U1:
            case Code.Ldelem_I2:
            case Code.Ldelem_U2:
            case Code.Ldelem_I4:
            case Code.Ldelem_U4:
            case Code.Ldelem_I8:
            case Code.Ldelem_I:
            case Code.Ldelem_R4:
            case Code.Ldelem_R8:
            case Code.Ldelem_Ref:
            case Code.Ldelem_Any:
            case Code.Ldind_I1:
            case Code.Ldind_U1:
            case Code.Ldind_I2:
            case Code.Ldind_U2:
            case Code.Ldind_I4:
            case Code.Ldind_U4:
            case Code.Ldind_I8:
            case Code.Ldind_I:
            case Code.Ldind_R4:
            case Code.Ldind_R8:
            case Code.Ldind_Ref:
            case Code.Ldlen:
                instruction = new Load(untyped, index);
                break;

            case Code.Ldfld:
                instruction = new LoadField(untyped, index);
                break;

            case Code.Ldflda:
                instruction = new LoadFieldAddress(untyped, index);
                break;

            case Code.Ldftn:
            case Code.Ldvirtftn:
                instruction = new LoadFunctionAddress(untyped, index);
                break;

            case Code.Ldloc_0:
            case Code.Ldloc_1:
            case Code.Ldloc_2:
            case Code.Ldloc_3:
            case Code.Ldloc:
            case Code.Ldloc_S:
                instruction = new LoadLocal(m_symbols, method, untyped, index);
                break;

            case Code.Ldloca:
            case Code.Ldloca_S:
                instruction = new LoadLocalAddress(m_symbols, method, untyped, index);
                break;

            case Code.Ldnull:
                instruction = new LoadNull(untyped, index);
                break;

            case Code.Ldsfld:
                instruction = new LoadStaticField(untyped, index);
                break;

            case Code.Ldsflda:
                instruction = new LoadStaticFieldAddress(untyped, index);
                break;

            case Code.Ldstr:
                instruction = new LoadString(untyped, index);
                break;

            case Code.Newarr:
                instruction = new NewArr(untyped, index);
                break;

            case Code.Newobj:
                instruction = new NewObj(untyped, index);
                break;

            case Code.Starg:
            case Code.Starg_S:
                instruction = new StoreArg(method, untyped, index);
                break;

            case Code.Stelem_I:
            case Code.Stelem_I1:
            case Code.Stelem_I2:
            case Code.Stelem_I4:
            case Code.Stelem_I8:
            case Code.Stelem_R4:
            case Code.Stelem_R8:
            case Code.Stelem_Ref:
            case Code.Stelem_Any:
            case Code.Stind_I:
            case Code.Stind_I1:
            case Code.Stind_I2:
            case Code.Stind_I4:
            case Code.Stind_I8:
            case Code.Stind_R4:
            case Code.Stind_R8:
            case Code.Stobj:
                instruction = new Store(untyped, index);
                break;

            case Code.Stfld:
                instruction = new StoreField(untyped, index);
                break;

            case Code.Stloc_0:
            case Code.Stloc_1:
            case Code.Stloc_2:
            case Code.Stloc_3:
            case Code.Stloc:
            case Code.Stloc_S:
                instruction = new StoreLocal(m_symbols, method, untyped, index);
                break;

            case Code.Stsfld:
                instruction = new StoreStaticField(untyped, index);
                break;

            case Code.Switch:
                instruction = new Switch(untyped, index);
                break;

            case Code.Throw:
                instruction = new Throw(untyped, index);
                break;

            case Code.Unbox:
            case Code.Unbox_Any:
                instruction = new Unbox(untyped, index);
                break;

            default:
                instruction = new CatchAll(untyped, index);
                break;
            }

            return(instruction);
        }