From 9435ca52defb11819e8ab749fef923efb69a9172 Mon Sep 17 00:00:00 2001 From: aiselp Date: Wed, 14 Jun 2023 13:30:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=90=8E=E6=97=A0=E6=B3=95=E5=8A=A0=E8=BD=BD=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/AssetAndUrlModuleSourceProvider.kt | 35 +++++++++++++++---- version.properties | 6 ++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt b/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt index 96dfdbcb..ca5781b5 100644 --- a/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt +++ b/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt @@ -6,8 +6,12 @@ import android.net.Uri import com.google.gson.Gson import okhttp3.OkHttpClient import okhttp3.Request +import org.autojs.autojs.engine.encryption.ScriptEncryption.decrypt +import org.autojs.autojs.script.EncryptedScriptFileHeader +import org.autojs.autojs.script.EncryptedScriptFileHeader.isValidFile import org.mozilla.javascript.commonjs.module.provider.ModuleSource import org.mozilla.javascript.commonjs.module.provider.ModuleSourceProviderBase +import java.io.ByteArrayInputStream import java.io.File import java.io.InputStream import java.io.InputStreamReader @@ -22,11 +26,13 @@ class AssetAndUrlModuleSourceProvider( private val okHttpClient = OkHttpClient.Builder().followRedirects(true).build() private val contentResolver: ContentResolver = context.contentResolver private val moduleSources: ArrayList = arrayListOf(mBaseURI, npmModuleSource) + private val encryptionSource = File(context.filesDir, "project") companion object { val mBaseURI: URI = URI.create("file:/android_asset/modules") - val npmModuleSource:URI = URI.create("file:/android_asset/modules/npm") + val npmModuleSource: URI = URI.create("file:/android_asset/modules/npm") } + //初始化脚本以及启动文件只会从此方法加载模块,子模块加载没有以"./"或"../"开头的模块也会从此方法加载 override fun loadFromPrivilegedLocations(moduleId: String, validator: Any?): ModuleSource? { //println("加载私有模块:$moduleId") @@ -75,10 +81,8 @@ class AssetAndUrlModuleSourceProvider( InputStreamReader(packageFile.inputStream()), Map::class.java ) - val main = json["main"] as String? - main?.let { - packageFile.toURI().resolve(main) - } + val main = json["main"] as String + packageFile.toURI().resolve(main) } catch (e: Exception) { null } @@ -95,13 +99,32 @@ class AssetAndUrlModuleSourceProvider( mContext.assets.open(uri.path.replace("/android_asset/", "")) } else contentResolver.openInputStream(Uri.parse(uri.toString())) if (inputStream != null) { - createModuleSource(inputStream, uri, base, validator) + createModuleEncryptionSource(inputStream, uri, base, validator) } else null } catch (e: Exception) { null } } + private fun createModuleEncryptionSource( + inputStream: InputStream, + uri: URI, + base: URI?, + validator: Any?, + ): ModuleSource? { + //只处理内部位于apk内部资源的脚本文件 + val i = if (uri.path.startsWith(encryptionSource.path)) { + val bytes = ByteArray(inputStream.available()) + inputStream.read(bytes) + inputStream.close() + if (isValidFile(bytes)) { + val clearText = decrypt(bytes, EncryptedScriptFileHeader.BLOCK_SIZE, bytes.size) + ByteArrayInputStream(clearText) + } else inputStream + } else inputStream + return createModuleSource(i, uri, base, validator) + } + private fun loadFromHttp(uri: URI, base: URI?, validator: Any?): ModuleSource? { return try { Request.Builder().url(uri.toString()).build().let { request -> diff --git a/version.properties b/version.properties index 0cb338a1..f08a7391 100644 --- a/version.properties +++ b/version.properties @@ -1,8 +1,8 @@ -#Sat Jun 10 19:42:58 CST 2023 -BUILD_TIME=1686397378556 +#Wed Jun 14 13:27:56 CST 2023 +BUILD_TIME=1686720476407 COMPILE_SDK_VERSION=33 JAVA_VERSION=20 MIN_SDK_VERSION=24 TARGET_SDK_VERSION=33 -VERSION_BUILD=1911 +VERSION_BUILD=1914 VERSION_NAME=6.3.1 From 9579db0f25e2f615cc3bc39c76c2825edc76b333 Mon Sep 17 00:00:00 2001 From: aiselp Date: Wed, 14 Jun 2023 17:26:53 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8Btimer=E5=B7=A5=E4=BD=9C=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/autojs/autojs/core/looper/Timer.kt | 17 ++++++++++++----- version.properties | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt b/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt index 95dad6c9..368caa7d 100644 --- a/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt +++ b/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt @@ -7,6 +7,7 @@ import org.autojs.autojs.runtime.ScriptRuntime import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.Context import org.mozilla.javascript.Scriptable +import org.mozilla.javascript.Undefined import java.util.concurrent.ConcurrentHashMap import kotlin.random.Random @@ -22,6 +23,7 @@ class Timer( private val mRuntime: ScriptRuntime = runtime private val mHandler: Handler = Handler(looper) private val isUiLoop: Boolean = looper == Looper.getMainLooper() + private val context: Context? by lazy { Context.getCurrentContext() } constructor(runtime: ScriptRuntime, ) : this(runtime, Looper.myLooper()!!) @@ -36,17 +38,22 @@ class Timer( return id } - private fun callFunction(callback: Any, thiz: Any?, args :Any?) { - val myArgs = args?.let { args as Array<*> }?: emptyArray() - val map = myArgs.map { Context.javaToJS(it, callback as BaseFunction) } + private fun callFunction(callback: Any, thiz: Any?, args: Any?) { + val func = callback as BaseFunction + val map: Array = + (args as? Array<*>)?.map { Context.javaToJS(it, callback.parentScope) } + ?.toTypedArray() ?: emptyArray() try { - (callback as BaseFunction).call(Context.getCurrentContext(),callback.parentScope, - thiz as? Scriptable?, map.toTypedArray() + func.call( + context ?: Context.enter(), func.parentScope, + thiz as? Scriptable ?: Undefined.SCRIPTABLE_UNDEFINED, map ) } catch (e: Exception) { if (isUiLoop) { mRuntime.exit(e) } else throw e + }finally { + context ?: Context.exit() } } diff --git a/version.properties b/version.properties index f08a7391..afcad997 100644 --- a/version.properties +++ b/version.properties @@ -1,8 +1,8 @@ -#Wed Jun 14 13:27:56 CST 2023 -BUILD_TIME=1686720476407 +#Wed Jun 14 18:20:43 CST 2023 +BUILD_TIME=1686738043084 COMPILE_SDK_VERSION=33 JAVA_VERSION=20 MIN_SDK_VERSION=24 TARGET_SDK_VERSION=33 -VERSION_BUILD=1914 +VERSION_BUILD=1916 VERSION_NAME=6.3.1 From 3931b1cc82c1edb8f39117d63e924c1f5a3bfbe1 Mon Sep 17 00:00:00 2001 From: aiselp Date: Wed, 14 Jun 2023 20:49:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/AssetAndUrlModuleSourceProvider.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt b/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt index ca5781b5..e25ac4b5 100644 --- a/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt +++ b/app/src/main/java/org/autojs/autojs/engine/module/AssetAndUrlModuleSourceProvider.kt @@ -26,7 +26,6 @@ class AssetAndUrlModuleSourceProvider( private val okHttpClient = OkHttpClient.Builder().followRedirects(true).build() private val contentResolver: ContentResolver = context.contentResolver private val moduleSources: ArrayList = arrayListOf(mBaseURI, npmModuleSource) - private val encryptionSource = File(context.filesDir, "project") companion object { val mBaseURI: URI = URI.create("file:/android_asset/modules") @@ -111,17 +110,14 @@ class AssetAndUrlModuleSourceProvider( uri: URI, base: URI?, validator: Any?, - ): ModuleSource? { - //只处理内部位于apk内部资源的脚本文件 - val i = if (uri.path.startsWith(encryptionSource.path)) { - val bytes = ByteArray(inputStream.available()) - inputStream.read(bytes) - inputStream.close() - if (isValidFile(bytes)) { - val clearText = decrypt(bytes, EncryptedScriptFileHeader.BLOCK_SIZE, bytes.size) - ByteArrayInputStream(clearText) - } else inputStream - } else inputStream + ): ModuleSource { + val bytes = ByteArray(inputStream.available()) + inputStream.read(bytes) + inputStream.close() + val i = if (isValidFile(bytes)) { + val clearText = decrypt(bytes, EncryptedScriptFileHeader.BLOCK_SIZE, bytes.size) + ByteArrayInputStream(clearText) + } else ByteArrayInputStream(bytes) return createModuleSource(i, uri, base, validator) } From ace958aaf66b4c987cd883e5322c7b34582d921d Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Wed, 12 Jul 2023 15:24:07 +0800 Subject: [PATCH 4/4] modified: .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 23e2d18c..b94598e8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ output.json output-metadata.json desktop.ini +sync.ffs_db .bak .git