mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.script.rhino
|
||||
|
||||
import org.mozilla.javascript.NativeJavaClass
|
||||
import org.mozilla.javascript.Scriptable
|
||||
|
||||
class ProtectedNativeJavaClass(
|
||||
scope: Scriptable,
|
||||
javaClass: Class<*>,
|
||||
private val protectedName: HashSet<String>
|
||||
) : NativeJavaClass(scope, javaClass) {
|
||||
|
||||
override fun has(
|
||||
name: String,
|
||||
start: Scriptable?
|
||||
): Boolean {
|
||||
if (protectedName.contains(name)) {
|
||||
return false
|
||||
}
|
||||
return super.has(name, start)
|
||||
}
|
||||
|
||||
override fun get(name: String, start: Scriptable?): Any? {
|
||||
if (protectedName.contains(name)) {
|
||||
return NOT_FOUND
|
||||
}
|
||||
return super.get(name, start)
|
||||
}
|
||||
|
||||
override fun put(
|
||||
name: String,
|
||||
start: Scriptable?,
|
||||
value: Any?
|
||||
) {
|
||||
if (protectedName.contains(name)) {
|
||||
return
|
||||
}
|
||||
super.put(name, start, value)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,8 @@ package com.script.rhino
|
||||
import android.os.Build
|
||||
import org.mozilla.javascript.ClassShutter
|
||||
import org.mozilla.javascript.Context
|
||||
import org.mozilla.javascript.NativeJavaClass
|
||||
import org.mozilla.javascript.Scriptable
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.lang.reflect.Member
|
||||
@@ -51,6 +53,8 @@ object RhinoClassShutter : ClassShutter {
|
||||
"cn.hutool.core.lang.JarClassLoader",
|
||||
"cn.hutool.core.util.RuntimeUtil",
|
||||
"cn.hutool.core.util.ClassLoaderUtil",
|
||||
"cn.hutool.core.util.ReflectUtil",
|
||||
"cn.hutool.core.util.SerializeUtil",
|
||||
"org.mozilla.javascript.DefiningClassLoader",
|
||||
"java.lang.Runtime",
|
||||
"java.lang.ProcessBuilder",
|
||||
@@ -69,6 +73,7 @@ object RhinoClassShutter : ClassShutter {
|
||||
"java.nio.file.Files",
|
||||
"java.nio.file.FileSystems",
|
||||
"io.legado.app.data.AppDatabase",
|
||||
"io.legado.app.data.AppDatabase_Impl",
|
||||
"io.legado.app.data.AppDatabaseKt",
|
||||
"io.legado.app.utils.ContextExtensionsKt",
|
||||
"android.content.Intent",
|
||||
@@ -77,6 +82,7 @@ object RhinoClassShutter : ClassShutter {
|
||||
"splitties.init.AppCtxKt",
|
||||
"android.app.ActivityThread",
|
||||
"android.app.AppGlobals",
|
||||
"android.os.Looper",
|
||||
"okio.JvmSystemFileSystem",
|
||||
"okio.JvmFileHandle",
|
||||
"okio.NioSystemFileSystem",
|
||||
@@ -86,12 +92,18 @@ object RhinoClassShutter : ClassShutter {
|
||||
"android.system",
|
||||
"android.database",
|
||||
"androidx.sqlite.db",
|
||||
"androidx.room",
|
||||
"cn.hutool.core.io",
|
||||
"dalvik.system",
|
||||
"java.nio.file",
|
||||
"io.legado.app.data.dao",
|
||||
)
|
||||
}
|
||||
|
||||
private val systemClassProtectedName by lazy {
|
||||
hashSetOf("load", "loadLibrary", "exit")
|
||||
}
|
||||
|
||||
fun visibleToScripts(obj: Any): Boolean {
|
||||
when (obj) {
|
||||
is ClassLoader,
|
||||
@@ -114,6 +126,16 @@ object RhinoClassShutter : ClassShutter {
|
||||
return visibleToScripts(obj.javaClass.name)
|
||||
}
|
||||
|
||||
fun wrapJavaClass(scope: Scriptable, javaClass: Class<*>): Scriptable {
|
||||
return when (javaClass) {
|
||||
System::class.java -> {
|
||||
ProtectedNativeJavaClass(scope, javaClass, systemClassProtectedName)
|
||||
}
|
||||
|
||||
else -> NativeJavaClass(scope, javaClass)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visibleToScripts(fullClassName: String): Boolean {
|
||||
if (!protectedClasses.contains(fullClassName)) {
|
||||
var className = fullClassName
|
||||
|
||||
@@ -55,4 +55,12 @@ object RhinoWrapFactory : WrapFactory() {
|
||||
return super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
||||
}
|
||||
|
||||
override fun wrapJavaClass(
|
||||
cx: Context?,
|
||||
scope: Scriptable,
|
||||
javaClass: Class<*>
|
||||
): Scriptable? {
|
||||
return RhinoClassShutter.wrapJavaClass(scope, javaClass)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user