Example #1
0
		DbgDotNetValueResult CallCore(DbgDotNetValue obj, bool isCallvirt, DmdMethodBase method, ILValue[] arguments) {
			var options = isCallvirt ? DotNetClassHookCallOptions.IsCallvirt : DotNetClassHookCallOptions.None;
			foreach (var anyHook in anyClassHooks) {
				var res = anyHook.Call(options, obj, method, arguments);
				if (res != null)
					return new DbgDotNetValueResult(res, valueIsException: false);
			}

			var type = method.DeclaringType;
			if (type.IsConstructedGenericType)
				type = type.GetGenericTypeDefinition();
			var typeName = DmdTypeName.Create(type);
			if (classHooks.TryGetValue(typeName, out var hook)) {
				if (DmdWellKnownTypeUtils.TryGetWellKnownType(typeName, out var wellKnownType)) {
					if (type != type.AppDomain.GetWellKnownType(wellKnownType, isOptional: true))
						hook = null;
				}
				if (hook != null) {
					var res = hook.Call(options, obj, method, arguments);
					if (res != null)
						return new DbgDotNetValueResult(res, valueIsException: false);
				}
			}

			if (!canFuncEval)
				throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.FuncEvalDisabled);
			return runtime.Call(context, frame, obj, method, Convert(arguments, method.GetMethodSignature().GetParameterTypes()), cancellationToken);
		}
Example #2
0
		DbgDotNetValueResult CreateInstanceCore(DmdConstructorInfo ctor, ILValue[] arguments) {
			if (ctor.IsStatic)
				return new DbgDotNetValueResult(PredefinedEvaluationErrorMessages.InternalDebuggerError);

			const DotNetClassHookCallOptions options = DotNetClassHookCallOptions.None;
			foreach (var anyHook in anyClassHooks) {
				var res = anyHook.CreateInstance(options, ctor, arguments);
				if (res != null)
					return new DbgDotNetValueResult(res, valueIsException: false);
			}

			var type = ctor.DeclaringType;
			if (type.IsConstructedGenericType)
				type = type.GetGenericTypeDefinition();
			var typeName = DmdTypeName.Create(type);
			if (classHooks.TryGetValue(typeName, out var hook)) {
				if (DmdWellKnownTypeUtils.TryGetWellKnownType(typeName, out var wellKnownType)) {
					if (type != type.AppDomain.GetWellKnownType(wellKnownType, isOptional: true))
						hook = null;
				}
				if (hook != null) {
					var res = hook.CreateInstance(options, ctor, arguments);
					if (res != null)
						return new DbgDotNetValueResult(res, valueIsException: false);
				}
			}

			if (!canFuncEval)
				throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.FuncEvalDisabled);
			return runtime.CreateInstance(context, frame, ctor, Convert(arguments, ctor.GetMethodSignature().GetParameterTypes()), cancellationToken);
		}