Пример #1
0
		private bool DoMatch(CodeBlock lhs, CodeBlock rhs, int count)
		{
			Log.DebugLine(this, "   lhs: {0} at {1:X2}", lhs.Method, lhs.Instructions[lhs.Index].Untyped.Offset);
			Log.DebugLine(this, "   rhs: {0} at {1:X2}", rhs.Method, rhs.Instructions[rhs.Index].Untyped.Offset);
			Log.DebugLine(this, "   count: {0}", count);
			
			for (int i = 0; i < count; ++i)
			{
				TypedInstruction left = lhs.Instructions[lhs.Index + i];
				TypedInstruction right = rhs.Instructions[rhs.Index + i];
				
				LoadLocal load1 = left as LoadLocal;
				LoadLocal load2 = right as LoadLocal;
				LoadLocalAddress load1b = left as LoadLocalAddress;
				LoadLocalAddress load2b = right as LoadLocalAddress;
				StoreLocal store1 = left as StoreLocal;
				StoreLocal store2 = right as StoreLocal;

				if (load1 != null && load2 != null)
				{
					// If we have real names for the local variables (from the mdb file) then
					// life is good and we can compare the names. If not we're stuck: we can't
					// simply use the variable index because we'll get false positives.
					if (!load1.RealName)
					{												
						Log.DebugLine(this, "   can't match local name");
						return false;
					}
					// This should be a temporary in which case we can't use the variable index.
					else if (load1.Name.StartsWith("V_") && load1.Type.FullName != load2.Type.FullName)
					{
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, load1.Type.FullName, load2.Type.FullName);
						return false;
					}
					else if (!load1.Name.StartsWith("V_") && load1.Name != load2.Name)
					{												
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, load1.Name, load2.Name);
						return false;
					}
				}	
				else if (load1b != null && load2b != null)
				{
					if (!load1b.RealName)
					{												
						Log.DebugLine(this, "   can't match local name");
						return false;
					}
					else if (load1b.Name.StartsWith("V_") && load1b.Type.FullName != load2b.Type.FullName)
					{
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, load1b.Type.FullName, load2b.Type.FullName);
						return false;
					}
					else if (!load1b.Name.StartsWith("V_") && load1b.Name != load2b.Name)	
					{												
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, load1b.Name, load2b.Name);
						return false;
					}
				}	
				else if (store1 != null && store2 != null)
				{
					if (!store1.RealName)
					{												
						Log.DebugLine(this, "   can't match local name");
						return false;
					}
					else if (store1.Name.StartsWith("V_") && store1.Type.FullName != store2.Type.FullName)
					{
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, store1.Type.FullName, store2.Type.FullName);
						return false;
					}
					else if (!store1.Name.StartsWith("V_") && store1.Name != store2.Name)
					{
						Log.DebugLine(this, "   {0} != {1} ({2} and {3})", left, right, store1.Name, store2.Name);
						return false;
					}
				}
				else if (!left.Untyped.Matches(right.Untyped))
				{
					Log.DebugLine(this, "   {0} != {1}", left, right);
					return false;
				}
			}
						
			return true;
		}