优化
This commit is contained in:
@@ -216,4 +216,12 @@ class App : Application() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
System.setProperty("kotlinx.coroutines.debug", "on")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
mCallback?.loadFail(errorMsg)
|
mCallback?.loadFail(errorMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (content.isEmpty()) {
|
if (content.isEmpty() && !chapter.isVolume) {
|
||||||
mCallback?.loadFail("正文内容为空")
|
mCallback?.loadFail("正文内容为空")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ dependencies {
|
|||||||
api libs.mozilla.rhino
|
api libs.mozilla.rhino
|
||||||
|
|
||||||
implementation(libs.kotlinx.coroutines.core)
|
implementation(libs.kotlinx.coroutines.core)
|
||||||
|
implementation(libs.okhttp)
|
||||||
|
|
||||||
// def coroutines_version = '1.7.3'
|
// def coroutines_version = '1.7.3'
|
||||||
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
|
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
|
||||||
|
|||||||
@@ -24,7 +24,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.script.rhino
|
package com.script.rhino
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import org.mozilla.javascript.ClassShutter
|
import org.mozilla.javascript.ClassShutter
|
||||||
|
import org.mozilla.javascript.Context
|
||||||
|
import java.io.ObjectInputStream
|
||||||
|
import java.io.ObjectOutputStream
|
||||||
|
import java.lang.reflect.Member
|
||||||
|
import java.nio.file.FileSystem
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class prevents script access to certain sensitive classes.
|
* This class prevents script access to certain sensitive classes.
|
||||||
@@ -38,30 +45,75 @@ object RhinoClassShutter : ClassShutter {
|
|||||||
|
|
||||||
private val protectedClasses by lazy {
|
private val protectedClasses by lazy {
|
||||||
hashSetOf(
|
hashSetOf(
|
||||||
"dalvik.system",
|
|
||||||
"java.lang.Class",
|
"java.lang.Class",
|
||||||
"java.lang.ClassLoader",
|
"java.lang.ClassLoader",
|
||||||
"java.net.URLClassLoader",
|
"java.net.URLClassLoader",
|
||||||
"cn.hutool.core.lang.JarClassLoader",
|
"cn.hutool.core.lang.JarClassLoader",
|
||||||
|
"cn.hutool.core.util.RuntimeUtil",
|
||||||
|
"cn.hutool.core.util.ClassLoaderUtil",
|
||||||
"org.mozilla.javascript.DefiningClassLoader",
|
"org.mozilla.javascript.DefiningClassLoader",
|
||||||
"java.lang.Runtime",
|
"java.lang.Runtime",
|
||||||
|
"java.lang.ProcessBuilder",
|
||||||
|
"java.lang.ProcessImpl",
|
||||||
|
"java.lang.UNIXProcess",
|
||||||
"java.io.File",
|
"java.io.File",
|
||||||
|
"java.io.FileInputStream",
|
||||||
|
"java.io.FileOutputStream",
|
||||||
|
"java.io.FileReader",
|
||||||
|
"java.io.FileWriter",
|
||||||
|
"java.io.RandomAccessFile",
|
||||||
|
"java.io.ObjectInputStream",
|
||||||
|
"java.io.ObjectOutputStream",
|
||||||
"java.security.AccessController",
|
"java.security.AccessController",
|
||||||
"java.nio.file.Paths",
|
"java.nio.file.Paths",
|
||||||
"java.nio.file.Files",
|
"java.nio.file.Files",
|
||||||
|
"java.nio.file.FileSystems",
|
||||||
"io.legado.app.data.AppDatabase",
|
"io.legado.app.data.AppDatabase",
|
||||||
"io.legado.app.data.AppDatabaseKt",
|
"io.legado.app.data.AppDatabaseKt",
|
||||||
"io.legado.app.utils.ContextExtensionsKt",
|
"io.legado.app.utils.ContextExtensionsKt",
|
||||||
"android.content.Intent",
|
"android.content.Intent",
|
||||||
"androidx.core.content.FileProvider",
|
"androidx.core.content.FileProvider",
|
||||||
"android.provider.Settings",
|
"android.provider.Settings",
|
||||||
"androidx.sqlite.db",
|
|
||||||
"splitties.init.AppCtxKt",
|
"splitties.init.AppCtxKt",
|
||||||
"android.app.ActivityThread",
|
"android.app.ActivityThread",
|
||||||
"android.app.AppGlobals"
|
"android.app.AppGlobals",
|
||||||
|
"okio.JvmSystemFileSystem",
|
||||||
|
"okio.JvmFileHandle",
|
||||||
|
"okio.NioSystemFileSystem",
|
||||||
|
"okio.NioFileSystemFileHandle",
|
||||||
|
"okio.Path",
|
||||||
|
|
||||||
|
"android.system",
|
||||||
|
"android.database",
|
||||||
|
"androidx.sqlite.db",
|
||||||
|
"cn.hutool.core.io",
|
||||||
|
"dalvik.system",
|
||||||
|
"java.nio.file",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun visibleToScripts(obj: Any): Boolean {
|
||||||
|
when (obj) {
|
||||||
|
is ClassLoader,
|
||||||
|
is Class<*>,
|
||||||
|
is Member,
|
||||||
|
is Context,
|
||||||
|
is ObjectInputStream,
|
||||||
|
is ObjectOutputStream,
|
||||||
|
is okio.FileSystem,
|
||||||
|
is okio.FileHandle,
|
||||||
|
is okio.Path,
|
||||||
|
is android.content.Context -> return false
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
when (obj) {
|
||||||
|
is FileSystem,
|
||||||
|
is Path -> return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visibleToScripts(obj.javaClass.name)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visibleToScripts(fullClassName: String): Boolean {
|
override fun visibleToScripts(fullClassName: String): Boolean {
|
||||||
if (!protectedClasses.contains(fullClassName)) {
|
if (!protectedClasses.contains(fullClassName)) {
|
||||||
var className = fullClassName
|
var className = fullClassName
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package com.script.rhino
|
|||||||
import org.mozilla.javascript.Context
|
import org.mozilla.javascript.Context
|
||||||
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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wrap factory is used for security reasons. JSR 223 script
|
* This wrap factory is used for security reasons. JSR 223 script
|
||||||
@@ -50,25 +49,10 @@ object RhinoWrapFactory : WrapFactory() {
|
|||||||
javaObject: Any,
|
javaObject: Any,
|
||||||
staticType: Class<*>?
|
staticType: Class<*>?
|
||||||
): Scriptable? {
|
): Scriptable? {
|
||||||
val classShutter = RhinoClassShutter
|
if (!RhinoClassShutter.visibleToScripts(javaObject)) {
|
||||||
return when (javaObject) {
|
return null
|
||||||
is ClassLoader,
|
|
||||||
is Class<*>,
|
|
||||||
is Member,
|
|
||||||
is Context,
|
|
||||||
is android.content.Context -> {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
val name = javaObject.javaClass.name
|
|
||||||
if (classShutter.visibleToScripts(name)) {
|
|
||||||
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user