void DetectHandlers(List <TypeDef> handlerTypes, CsvmInfo csvmInfo)
        {
            opCodeHandlers = new List <OpCodeHandler>();
            var detected = new List <OpCodeHandler>();

            foreach (var handlersList in OpCodeHandlers.Handlers)
            {
                opCodeHandlers.Clear();

                foreach (var handlerType in handlerTypes)
                {
                    var info = new UnknownHandlerInfo(handlerType, csvmInfo);
                    detected.Clear();
                    foreach (var opCodeHandler in handlersList)
                    {
                        if (opCodeHandler.Detect(info))
                        {
                            detected.Add(opCodeHandler);
                        }
                    }
                    if (detected.Count != 1)
                    {
                        goto next;
                    }
                    opCodeHandlers.Add(detected[0]);
                }
                if (new List <OpCodeHandler>(Utils.Unique(opCodeHandlers)).Count == opCodeHandlers.Count)
                {
                    return;
                }
                next :;
            }
            throw new ApplicationException("Could not detect all VM opcode handlers");
        }
        public bool Detect(UnknownHandlerInfo info)
        {
            var sigInfo = OpCodeHandlerSigInfo;

            if (!Compare(sigInfo.NumStaticMethods, info.NumStaticMethods))
            {
                return(false);
            }
            if (!Compare(sigInfo.NumInstanceMethods, info.NumInstanceMethods))
            {
                return(false);
            }
            if (!Compare(sigInfo.NumVirtualMethods, info.NumVirtualMethods))
            {
                return(false);
            }
            if (!Compare(sigInfo.NumCtors, info.NumCtors))
            {
                return(false);
            }
            if (!Compare(sigInfo.ExecuteMethodThrows, info.ExecuteMethodThrows))
            {
                return(false);
            }
            if (!Compare(sigInfo.ExecuteMethodPops, info.ExecuteMethodPops))
            {
                return(false);
            }
            if (!info.HasSameFieldTypes(sigInfo.RequiredFieldTypes))
            {
                return(false);
            }
            if (sigInfo.ExecuteMethodLocals != null && !new LocalTypes(info.ExecuteMethod).All(sigInfo.ExecuteMethodLocals))
            {
                return(false);
            }

            if (Check != null)
            {
                return(Check(info));
            }
            return(true);
        }
示例#3
0
		public bool Detect(UnknownHandlerInfo info) {
			var sigInfo = OpCodeHandlerSigInfo;

			if (!Compare(sigInfo.NumStaticMethods, info.NumStaticMethods))
				return false;
			if (!Compare(sigInfo.NumInstanceMethods, info.NumInstanceMethods))
				return false;
			if (!Compare(sigInfo.NumVirtualMethods, info.NumVirtualMethods))
				return false;
			if (!Compare(sigInfo.NumCtors, info.NumCtors))
				return false;
			if (!Compare(sigInfo.ExecuteMethodThrows, info.ExecuteMethodThrows))
				return false;
			if (!Compare(sigInfo.ExecuteMethodPops, info.ExecuteMethodPops))
				return false;
			if (!info.HasSameFieldTypes(sigInfo.RequiredFieldTypes))
				return false;
			if (sigInfo.ExecuteMethodLocals != null && !new LocalTypes(info.ExecuteMethod).All(sigInfo.ExecuteMethodLocals))
				return false;

			if (Check != null)
				return Check(info);
			return true;
		}
示例#4
0
		static bool rethrow_check(UnknownHandlerInfo info) {
			return info.ExecuteMethod.Body.Variables.Count == 0;
		}
示例#5
0
		static bool nop_check(UnknownHandlerInfo info) {
			return IsEmptyMethod(info.ReadMethod) && IsEmptyMethod(info.ExecuteMethod);
		}
示例#6
0
		static bool leave_check(UnknownHandlerInfo info) {
			return !DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodBase System.Reflection.Module::ResolveMethod(System.Int32)") &&
				!DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Type System.Reflection.Module::ResolveType(System.Int32)") &&
				!DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MemberInfo System.Reflection.Module::ResolveMember(System.Int32)");
		}
示例#7
0
		static bool ldtoken_check(UnknownHandlerInfo info) {
			return DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MemberInfo System.Reflection.Module::ResolveMember(System.Int32)");
		}
示例#8
0
 static bool newarr_check(UnknownHandlerInfo info) =>
 DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Type System.Reflection.Module::ResolveType(System.Int32)");
 static bool rethrow_check(UnknownHandlerInfo info)
 {
     return(info.ExecuteMethod.Body.Variables.Count == 0);
 }
 static bool ret_check(UnknownHandlerInfo info)
 {
     return(DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodBase System.Reflection.Module::ResolveMethod(System.Int32)"));
 }
 static bool nop_check(UnknownHandlerInfo info)
 {
     return(IsEmptyMethod(info.ReadMethod) && IsEmptyMethod(info.ExecuteMethod));
 }
 static bool leave_check(UnknownHandlerInfo info)
 {
     return(!DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodBase System.Reflection.Module::ResolveMethod(System.Int32)") &&
            !DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Type System.Reflection.Module::ResolveType(System.Int32)") &&
            !DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MemberInfo System.Reflection.Module::ResolveMember(System.Int32)"));
 }
示例#13
0
 static bool ldtoken_check(UnknownHandlerInfo info) =>
 DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MemberInfo System.Reflection.Module::ResolveMember(System.Int32)");
示例#14
0
 static bool endfinally_check(UnknownHandlerInfo info) =>
 DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodInfo System.Type::GetMethod(System.String,System.Reflection.BindingFlags)");
示例#15
0
		static bool throw_check(UnknownHandlerInfo info) {
			return !DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodInfo System.Type::GetMethod(System.String,System.Reflection.BindingFlags)");
		}
 static bool throw_check(UnknownHandlerInfo info)
 {
     return(!DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Reflection.MethodInfo System.Type::GetMethod(System.String,System.Reflection.BindingFlags)"));
 }
示例#17
0
		static bool newarr_check(UnknownHandlerInfo info) {
			return DotNetUtils.CallsMethod(info.ExecuteMethod, "System.Type System.Reflection.Module::ResolveType(System.Int32)");
		}
		void DetectHandlers(List<TypeDef> handlerTypes, CsvmInfo csvmInfo) {
			opCodeHandlers = new List<OpCodeHandler>();
			var detected = new List<OpCodeHandler>();

			foreach (var handlersList in OpCodeHandlers.Handlers) {
				opCodeHandlers.Clear();

				foreach (var handlerType in handlerTypes) {
					var info = new UnknownHandlerInfo(handlerType, csvmInfo);
					detected.Clear();
					foreach (var opCodeHandler in handlersList) {
						if (opCodeHandler.Detect(info))
							detected.Add(opCodeHandler);
					}
					if (detected.Count != 1)
						goto next;
					opCodeHandlers.Add(detected[0]);
				}
				if (new List<OpCodeHandler>(Utils.Unique(opCodeHandlers)).Count == opCodeHandlers.Count)
					return;
next: ;
			}
			throw new ApplicationException("Could not detect all VM opcode handlers");
		}