mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
d9e623cd37
commit
7cee9414ae
@ -25,11 +25,9 @@
|
|||||||
package com.script.rhino
|
package com.script.rhino
|
||||||
|
|
||||||
import org.mozilla.javascript.Context
|
import org.mozilla.javascript.Context
|
||||||
import org.mozilla.javascript.NativeJavaObject
|
|
||||||
import org.mozilla.javascript.Scriptable
|
import org.mozilla.javascript.Scriptable
|
||||||
import org.mozilla.javascript.WrapFactory
|
import org.mozilla.javascript.WrapFactory
|
||||||
import java.lang.reflect.Member
|
import java.lang.reflect.Member
|
||||||
import java.lang.reflect.Modifier
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wrap factory is used for security reasons. JSR 223 script
|
* This wrap factory is used for security reasons. JSR 223 script
|
||||||
@ -52,66 +50,17 @@ object RhinoWrapFactory : WrapFactory() {
|
|||||||
javaObject: Any,
|
javaObject: Any,
|
||||||
staticType: Class<*>?
|
staticType: Class<*>?
|
||||||
): Scriptable? {
|
): Scriptable? {
|
||||||
scope?.delete("Packages")
|
|
||||||
val sm = System.getSecurityManager()
|
|
||||||
val classShutter = RhinoClassShutter
|
val classShutter = RhinoClassShutter
|
||||||
return if (javaObject is ClassLoader) {
|
return when (javaObject) {
|
||||||
sm?.checkPermission(RuntimePermission("getClassLoader"))
|
is ClassLoader, is Class<*>, is Member, is android.content.Context -> null
|
||||||
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
else -> {
|
||||||
} else {
|
val name = javaObject.javaClass.name
|
||||||
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
|
|
||||||
if (classShutter.visibleToScripts(name)) {
|
if (classShutter.visibleToScripts(name)) {
|
||||||
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
||||||
} else {
|
} else {
|
||||||
var type: Class<*>? = null
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user