Пример #1
0
        private static TypeWrapper LoadTypeWrapper(string clazz, [email protected] callerId)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                TypeWrapper           context = TypeWrapper.FromClass(callerId.getCallerClass());
                TypeWrapper           wrapper = ClassLoaderWrapper.FromCallerID(callerId).LoadClassByDottedName(clazz);
                java.lang.ClassLoader loader  = callerId.getCallerClassLoader();
                if (loader != null)
                {
                    loader.checkPackageAccess(wrapper.ClassObject, callerId.getCallerClass().pd);
                }
                if (!wrapper.IsAccessibleFrom(context))
                {
                    throw new java.lang.IllegalAccessError("Try to access class " + wrapper.Name + " from class " + context.Name);
                }
                wrapper.Finish();
                return(wrapper);
            }
            catch (RetargetableJavaException x)
            {
                throw x.ToJava();
            }
#endif
        }
Пример #2
0
        private static FieldWrapper GetFieldWrapper(object thisObj, string clazz, string name, string sig, bool isStatic, [email protected] callerId)
        {
            TypeWrapper  caller  = TypeWrapper.FromClass(callerId.getCallerClass());
            TypeWrapper  wrapper = LoadTypeWrapper(clazz, callerId);
            FieldWrapper field   = wrapper.GetFieldWrapper(name, sig);

            if (field == null)
            {
                throw new java.lang.NoSuchFieldError(clazz + "." + name);
            }
            // TODO check loader constraints
            if (field.IsStatic != isStatic)
            {
                throw new java.lang.IncompatibleClassChangeError(clazz + "." + name);
            }
            TypeWrapper objType = null;

            if (thisObj != null)
            {
                objType = ClassLoaderWrapper.GetWrapperFromType(thisObj.GetType());
            }
            if (field.IsAccessibleFrom(wrapper, caller, objType))
            {
                return(field);
            }
            throw new java.lang.IllegalAccessError(field.DeclaringType.Name + "." + name);
        }
Пример #3
0
    private static bool GetProtectionDomains(List <java.security.ProtectionDomain> array, [email protected] callerID, StackTrace stack)
    {
        java.security.ProtectionDomain previous_protection_domain = null;
        for (int i = 0; i < stack.FrameCount; i++)
        {
            bool is_privileged = false;
            java.security.ProtectionDomain protection_domain;
            MethodBase method = stack.GetFrame(i).GetMethod();
            if (method.DeclaringType == typeof(java.security.AccessController) &&
                method.Name == "doPrivileged")
            {
                is_privileged = true;
                java.lang.Class caller = callerID.getCallerClass();
                protection_domain = caller == null ? null : Java_java_lang_Class.getProtectionDomain0(caller);
            }
            else
            {
                protection_domain = GetProtectionDomainFromType(method.DeclaringType);
            }

            if (previous_protection_domain != protection_domain && protection_domain != null)
            {
                previous_protection_domain = protection_domain;
                array.Add(protection_domain);
            }

            if (is_privileged)
            {
                return(true);
            }
        }
        return(false);
    }
Пример #4
0
        private static TypeWrapper LoadTypeWrapper(string clazz, [email protected] callerId)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                TypeWrapper context = TypeWrapper.FromClass(callerId.getCallerClass());
#if WINRT
                RuntimeReflectionHelper.Instance.Mark(clazz);
#endif
                System.Diagnostics.Debug.WriteLine("Trying to load " + clazz);
                TypeWrapper wrapper = null;
                try {
                    wrapper = ClassLoaderWrapper.FromCallerID(callerId).LoadClassByDottedName(clazz);
                } catch (NotImplementedException nie)
                {
#if WINRT
                    RuntimeReflectionHelper.Instance.Mark(clazz);
#endif
                    System.Diagnostics.Debug.WriteLine("Not implemented " + clazz);
                    throw nie;
                }

                java.lang.ClassLoader loader = callerId.getCallerClassLoader();
                if (loader != null)
                {
                    loader.checkPackageAccess(wrapper.ClassObject, callerId.getCallerClass().pd);
                }
                if (!wrapper.IsAccessibleFrom(context))
                {
                    throw new java.lang.IllegalAccessError("Try to access class " + wrapper.Name + " from class " + context.Name);
                }
                wrapper.Finish();
                return(wrapper);
            }
            catch (RetargetableJavaException x)
            {
                throw x.ToJava();
            }
#endif
        }
Пример #5
0
		private static java.lang.invoke.MethodHandle DynamicLoadMethodHandleImpl(int kind, string clazz, string name, string sig, [email protected] callerID)
		{
#if FIRST_PASS
			return null;
#else
			java.lang.Class refc = LoadTypeWrapper(clazz, callerID).ClassObject;
			try
			{
				switch ((ClassFile.RefKind)kind)
				{
					case ClassFile.RefKind.getStatic:
					case ClassFile.RefKind.putStatic:
					case ClassFile.RefKind.getField:
					case ClassFile.RefKind.putField:
						java.lang.Class type = ClassLoaderWrapper.FromCallerID(callerID).FieldTypeWrapperFromSig(sig, LoadMode.LoadOrThrow).ClassObject;
						return java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(callerID.getCallerClass(), kind, refc, name, type);
					default:
						java.lang.invoke.MethodType mt = null;
						DynamicLoadMethodType(ref mt, sig, callerID);
						// HACK linkMethodHandleConstant is broken for MethodHandle.invoke[Exact]
						if (kind == (int)ClassFile.RefKind.invokeVirtual && refc == CoreClasses.java.lang.invoke.MethodHandle.Wrapper.ClassObject)
						{
							switch (name)
							{
								case "invokeExact":
									return java.lang.invoke.MethodHandles.exactInvoker(mt);
								case "invoke":
									return java.lang.invoke.MethodHandles.invoker(mt);
							}
						}
						return java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(callerID.getCallerClass(), kind, refc, name, mt);
				}
			}
			catch (RetargetableJavaException x)
			{
				throw x.ToJava();
			}
#endif
		}
Пример #6
0
    private static bool GetProtectionDomains(List <java.security.ProtectionDomain> array, [email protected] callerID, StackTrace stack)
    {
        // first we have to skip all AccessController related frames, because we can be called from a doPrivileged implementation (not the privileged action)
        // in which case we should ignore the doPrivileged frame
        int skip = 0;

        for (; skip < stack.FrameCount; skip++)
        {
            Type type = stack.GetFrame(skip).GetMethod().DeclaringType;
            if (type != typeof(Java_java_security_AccessController) && type != typeof(java.security.AccessController))
            {
                break;
            }
        }
        java.security.ProtectionDomain previous_protection_domain = null;
        for (int i = skip; i < stack.FrameCount; i++)
        {
            bool is_privileged = false;
            java.security.ProtectionDomain protection_domain;
            MethodBase method = stack.GetFrame(i).GetMethod();
            if (method.DeclaringType == typeof(java.security.AccessController) &&
                method.Name == "doPrivileged")
            {
                is_privileged = true;
                java.lang.Class caller = callerID.getCallerClass();
                protection_domain = caller == null ? null : Java_java_lang_Class.getProtectionDomain0(caller);
            }
            else if (Java_sun_reflect_Reflection.IsHideFromStackWalk(method))
            {
                continue;
            }
            else
            {
                protection_domain = GetProtectionDomainFromType(method.DeclaringType);
            }

            if (previous_protection_domain != protection_domain && protection_domain != null)
            {
                previous_protection_domain = protection_domain;
                array.Add(protection_domain);
            }

            if (is_privileged)
            {
                return(true);
            }
        }
        return(false);
    }
Пример #7
0
    public static java.lang.Class defineClass(object thisUnsafe, string name, byte[] buf, int offset, int length, [email protected] callerID)
    {
#if FIRST_PASS
        return(null);
#else
        return(defineClass(thisUnsafe, name, buf, offset, length, callerID.getCallerClassLoader(), callerID.getCallerClass().pd));
#endif
    }
Пример #8
0
        private static java.lang.invoke.MethodHandle DynamicLoadMethodHandleImpl(int kind, string clazz, string name, string sig, [email protected] callerID)
        {
#if FIRST_PASS
            return(null);
#else
            java.lang.invoke.MethodHandles.Lookup lookup = new java.lang.invoke.MethodHandles.Lookup(callerID.getCallerClass(),
                                                                                                     java.lang.invoke.MethodHandles.Lookup.PUBLIC |
                                                                                                     java.lang.invoke.MethodHandles.Lookup.PRIVATE |
                                                                                                     java.lang.invoke.MethodHandles.Lookup.PROTECTED |
                                                                                                     java.lang.invoke.MethodHandles.Lookup.PACKAGE,
                                                                                                     true);
            java.lang.Class refc = LoadTypeWrapper(clazz, callerID).ClassObject;
            try
            {
                switch ((ClassFile.RefKind)kind)
                {
                case ClassFile.RefKind.getStatic:
                case ClassFile.RefKind.putStatic:
                case ClassFile.RefKind.getField:
                case ClassFile.RefKind.putField:
                    java.lang.Class type = ClassLoaderWrapper.FromCallerID(callerID).FieldTypeWrapperFromSig(sig).ClassObject;
                    switch ((ClassFile.RefKind)kind)
                    {
                    case ClassFile.RefKind.getStatic:
                        return(lookup.findStaticGetter(refc, name, type));

                    case ClassFile.RefKind.putStatic:
                        return(lookup.findStaticSetter(refc, name, type));

                    case ClassFile.RefKind.getField:
                        return(lookup.findGetter(refc, name, type));

                    case ClassFile.RefKind.putField:
                        return(lookup.findSetter(refc, name, type));

                    default:
                        throw new InvalidOperationException();
                    }

                default:
                    java.lang.invoke.MethodType mt = null;
                    DynamicLoadMethodType(ref mt, sig, callerID);
                    switch ((ClassFile.RefKind)kind)
                    {
                    case ClassFile.RefKind.invokeInterface:
                        return(lookup.findVirtual(refc, name, mt));

                    case ClassFile.RefKind.invokeSpecial:
                        return(lookup.findSpecial(refc, name, mt, callerID.getCallerClass()));

                    case ClassFile.RefKind.invokeStatic:
                        return(lookup.findStatic(refc, name, mt));

                    case ClassFile.RefKind.invokeVirtual:
                        return(lookup.findVirtual(refc, name, mt));

                    case ClassFile.RefKind.newInvokeSpecial:
                        return(lookup.findConstructor(refc, mt));

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }
            catch (RetargetableJavaException x)
            {
                throw x.ToJava();
            }
            catch (java.lang.ReflectiveOperationException x)
            {
                throw new java.lang.IncompatibleClassChangeError().initCause(x);
            }
#endif
        }