Merge pull request #269 from PisLuanyao/master

fix NativeLoader for Emu
This commit is contained in:
白池 2024-03-01 15:40:44 +08:00 committed by GitHub
commit 61ffb37951
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -89,6 +89,7 @@ internal object NativeLoader {
val soPath = getLibFilePath(name) val soPath = getLibFilePath(name)
val soFile = File(soDir, name) val soFile = File(soDir, name)
fun reloadSo(tmp: File? = null) { fun reloadSo(tmp: File? = null) {
XposedBridge.log("[Shamrock] 重载SO文件 $soFile")
LogCenter.log("SO文件大小不一致或不存在正在重新加载", Level.INFO) LogCenter.log("SO文件大小不一致或不存在正在重新加载", Level.INFO)
soFile.delete() soFile.delete()
if (tmp == null) moduleClassLoader.getResourceAsStream(soPath).use { origin -> if (tmp == null) moduleClassLoader.getResourceAsStream(soPath).use { origin ->
@ -99,7 +100,7 @@ internal object NativeLoader {
if (!soFile.exists()) { if (!soFile.exists()) {
reloadSo() reloadSo()
} else { } else {
val tmpSoFile = soFile.resolve("$name.tmp").also { file -> val tmpSoFile = File(soDir, "$name.tmp").also { file ->
if (file.exists()) file.delete() if (file.exists()) file.delete()
file.outputStream().use { file.outputStream().use {
moduleClassLoader.getResourceAsStream(soPath).use { origin -> moduleClassLoader.getResourceAsStream(soPath).use { origin ->
@ -107,11 +108,12 @@ internal object NativeLoader {
} }
} }
} }
XposedBridge.log("[Shamrock] 正在校验${name}库文件")
if (soFile.length() != tmpSoFile.length() || MD5.getFileMD5(soFile).let { if (soFile.length() != tmpSoFile.length() || MD5.getFileMD5(soFile).let {
it != MD5.getFileMD5(tmpSoFile) it != MD5.getFileMD5(tmpSoFile)
}) { }) {
reloadSo(tmpSoFile) reloadSo(tmpSoFile)
} } else { tmpSoFile.delete() }
} }
try { try {
System.load(soFile.absolutePath) System.load(soFile.absolutePath)