From 7cee9414ae3f58ff2e17c3f4991f016b77767c3f Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 15 Jun 2023 23:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/script/rhino/RhinoWrapFactory.kt | 61 ++----------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoWrapFactory.kt b/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoWrapFactory.kt index f59f06629..7d81bc443 100644 --- a/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoWrapFactory.kt +++ b/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoWrapFactory.kt @@ -25,11 +25,9 @@ package com.script.rhino import org.mozilla.javascript.Context -import org.mozilla.javascript.NativeJavaObject import org.mozilla.javascript.Scriptable import org.mozilla.javascript.WrapFactory import java.lang.reflect.Member -import java.lang.reflect.Modifier /** * This wrap factory is used for security reasons. JSR 223 script @@ -52,67 +50,18 @@ object RhinoWrapFactory : WrapFactory() { javaObject: Any, staticType: Class<*>? ): Scriptable? { - scope?.delete("Packages") - val sm = System.getSecurityManager() val classShutter = RhinoClassShutter - return if (javaObject is ClassLoader) { - sm?.checkPermission(RuntimePermission("getClassLoader")) - super.wrapAsJavaObject(cx, scope, javaObject, staticType) - } else { - var name: String? = null - if (javaObject is Class<*>) { - name = javaObject.name - } else if (javaObject is Member) { - if (sm != null && !Modifier.isPublic(javaObject.modifiers)) { - return null - } - name = javaObject.declaringClass.name - } - if (name != null) { - if (!classShutter.visibleToScripts(name)) null else super.wrapAsJavaObject( - cx, - scope, - javaObject, - staticType - ) - } else { - var dynamicType: Class<*>? = javaObject.javaClass - name = dynamicType!!.name + return when (javaObject) { + is ClassLoader, is Class<*>, is Member, is android.content.Context -> null + else -> { + val name = javaObject.javaClass.name if (classShutter.visibleToScripts(name)) { super.wrapAsJavaObject(cx, scope, javaObject, staticType) } else { - var type: Class<*>? = null - if (staticType != null && staticType.isInterface) { - type = staticType - } else { - while (dynamicType != null) { - dynamicType = dynamicType.superclass - name = dynamicType.name - if (classShutter.visibleToScripts(name)) { - type = dynamicType - break - } - } - assert(type != null) { "java.lang.Object 不可访问" } - } - RhinoJavaObject(scope, javaObject, type) + null } } } } - private class RhinoJavaObject( - scope: Scriptable?, - obj: Any?, - type: Class<*>? - ) : NativeJavaObject(scope, null, type) { - init { - javaObject = obj - } - - override fun get(name: String, start: Scriptable): Any { - return if (name != "getClass" && name != "exec") super.get(name, start) else NOT_FOUND - } - } - } \ No newline at end of file