/** * Will be used by us to get the class loader for our * compiled class. It creates an anonymous class * extending the SecureClassLoader which uses the * byte code created by the compiler and stored in * the JavaClassObject, and returns the Class for it */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); URL url = null; try { url = new URL("file://" + DynaCompTest.PADDLES_CODESOURCE); } catch (MalformedURLException e) { throw new RuntimeException(e); } return super.defineClass(name, jclassObject.getBytes(), 0, b.length, new CodeSource(url, new Certificate[0])); } }; }
@Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] bytes = classObject.getBytes(); return super.defineClass(name, bytes, 0, bytes.length); } }; }
@Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject .getBytes(), 0, b.length); } }; }
/** * Will be used by us to get the class loader for our * compiled class. It creates an anonymous class * extending the SecureClassLoader which uses the * byte code created by the compiler and stored in * the RAMClassFile, and returns the Class for it */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = contents.get(name).getBytes(); return super.defineClass(name, b, 0, b.length); } }; }
@Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = objects.get(name).getBytes(); return super.defineClass(name, objects.get(name).getBytes(), 0, b.length); } }; }
public ClassLoader getClassLoader(final Location location) { return new SecureClassLoader() { protected Class<?> findClass(final String name) { final byte[] buffer = classObjectByNameMap.get(name).getBytes(); return super.defineClass(name, buffer, 0, buffer.length); } }; }
/** * Will be used by us to get the class loader for our compiled class. It * creates an anonymous class extending the SecureClassLoader which uses the * byte code created by the compiler and stored in the JavaClassObject, and * returns the Class for it * * @param location * @return */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject .getBytes(), 0, b.length); } }; }
/** * Will be used by us to get the class loader for our compiled class. It * creates an anonymous class extending the SecureClassLoader which uses the * byte code created by the compiler and stored in the JavaClassObject, and * returns the Class for it * * @param location the location * @return the class loader */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject.getBytes(), 0, b.length); } }; }
@Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject.getBytes(), 0, b.length); } }; }
/** * Will be used by us to get the class loader for our compiled class. It * creates an anonymous class extending the SecureClassLoader which uses * the byte code created by the compiler and stored in the * JavaClassObject, and returns the Class for it */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject.getBytes(), 0, b.length); } }; }
/** * Will be used by us to get the class loader for our * compiled class. It creates an anonymous class * extending the SecureClassLoader which uses the * byte code created by the compiler and stored in * the JavaClassObject, and returns the Class for it */ @Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = jclassObject.getBytes(); return super.defineClass(name, jclassObject.getBytes(), 0, b.length); } }; }
@Override public ClassLoader getClassLoader(Location location) { return new SecureClassLoader() { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { byte[] b = javaFileObject.getBytes(); if (b != null && b.length > 0) { return super.defineClass(name, javaFileObject.getBytes(), 0, b.length); } else { return super.findClass(name); } } }; }
private static MethodHandle createNoPermissionsInvoker() { final String className = "NoPermissionsInvoker"; final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null); final Type objectType = Type.getType(Object.class); final Type methodHandleType = Type.getType(MethodHandle.class); final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke", Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null)); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor( Type.VOID_TYPE, objectType), false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); cw.visitEnd(); final byte[] bytes = cw.toByteArray(); final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new SecureClassLoader(null) { @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { if(name.equals(className)) { return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain( new CodeSource(null, (CodeSigner[])null), new Permissions())); } throw new ClassNotFoundException(name); } }; } }); try { return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke", MethodType.methodType(void.class, MethodHandle.class, Object.class)); } catch(final ReflectiveOperationException e) { throw new AssertionError(e.getMessage(), e); } }
protected TestLoader() throws Exception { Constructor<?> ctor = SecureClassLoader.class.getDeclaredConstructor(); assertFalse(ctor.canAccess(null)); assertFalse(ctor.trySetAccessible()); }
private static MethodHandle createNoPermissionsInvoker() { final String className = "NoPermissionsInvoker"; final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null); final Type objectType = Type.getType(Object.class); final Type methodHandleType = Type.getType(MethodHandle.class); final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke", Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null)); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor( Type.VOID_TYPE, objectType), false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); cw.visitEnd(); final byte[] bytes = cw.toByteArray(); final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new SecureClassLoader(null) { @Override protected Class<?> findClass(final String name) throws ClassNotFoundException { if(name.equals(className)) { return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain( new CodeSource(null, (CodeSigner[])null), new Permissions())); } throw new ClassNotFoundException(name); } }; } }); try { return MethodHandles.publicLookup().findStatic(Class.forName(className, true, loader), "invoke", MethodType.methodType(void.class, MethodHandle.class, Object.class)); } catch(final ReflectiveOperationException e) { throw new AssertionError(e.getMessage(), e); } }
private static MethodHandle createNoPermissionsInvoker() { final String className = "NoPermissionsInvoker"; final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null); final Type objectType = Type.getType(Object.class); final Type methodHandleType = Type.getType(MethodHandle.class); final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke", Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null)); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor( Type.VOID_TYPE, objectType), false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); cw.visitEnd(); final byte[] bytes = cw.toByteArray(); final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return new SecureClassLoader(null) { @Override protected Class<?> findClass(String name) throws ClassNotFoundException { if(name.equals(className)) { return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain( new CodeSource(null, (CodeSigner[])null), new Permissions())); } throw new ClassNotFoundException(name); } }; } }); try { return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke", MethodType.methodType(void.class, MethodHandle.class, Object.class)); } catch(ReflectiveOperationException e) { throw new AssertionError(e.getMessage(), e); } }