mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
NativeLoader
应该是这样关? 猫脑过载.png
This commit is contained in:
parent
fc0d7a62af
commit
82269bb171
@ -58,21 +58,7 @@ internal object NativeLoader {
|
|||||||
fun load(name: String) {
|
fun load(name: String) {
|
||||||
try {
|
try {
|
||||||
if (name == "shamrock" || name == "clover") {
|
if (name == "shamrock" || name == "clover") {
|
||||||
|
|
||||||
/* val context = MobileQQ.getContext()
|
|
||||||
val packageManager = context.packageManager
|
|
||||||
val applicationInfo = packageManager.getApplicationInfo("moe.fuqiuluo.shamrock.hided", 0)
|
|
||||||
val file = File(applicationInfo.nativeLibraryDir)
|
|
||||||
LogCenter.log("LoadLibrary(name = $name)")
|
|
||||||
System.load(file.resolve("lib$name.so").also {
|
|
||||||
if (!it.exists()) {
|
|
||||||
LogCenter.log("LoadLibrary(name = $name) failed, file not exists.", level = Level.ERROR)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}.absolutePath)*/
|
|
||||||
|
|
||||||
onload(name, getCtx())
|
onload(name, getCtx())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val sourceFile = externalLibPath.resolve("lib$name.so")
|
val sourceFile = externalLibPath.resolve("lib$name.so")
|
||||||
val soFile = MobileQQ.getContext().filesDir.parentFile!!.resolve("txlib").resolve("lib$name.so")
|
val soFile = MobileQQ.getContext().filesDir.parentFile!!.resolve("txlib").resolve("lib$name.so")
|
||||||
@ -93,7 +79,7 @@ internal object NativeLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCtx() = MobileQQ.getContext()
|
private fun getCtx() = MobileQQ.getContext()
|
||||||
|
|
||||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
||||||
fun onload(name: String, context: Context) {
|
fun onload(name: String, context: Context) {
|
||||||
@ -112,7 +98,7 @@ internal object NativeLoader {
|
|||||||
try {
|
try {
|
||||||
FileUtil.writeFromStream(libStream, tmpSoFile)
|
FileUtil.writeFromStream(libStream, tmpSoFile)
|
||||||
if (!soFile.exists()) {
|
if (!soFile.exists()) {
|
||||||
LogCenter.log("SO文件 ${name} 不存在,正在尝试加载", Level.INFO)
|
LogCenter.log("SO文件 $name 不存在,正在尝试加载", Level.INFO)
|
||||||
tmpSoFile.renameTo(soFile)
|
tmpSoFile.renameTo(soFile)
|
||||||
} else {
|
} else {
|
||||||
val oldStream = FileUtil.getInputStream(soFile)
|
val oldStream = FileUtil.getInputStream(soFile)
|
||||||
@ -122,6 +108,8 @@ internal object NativeLoader {
|
|||||||
soFile.delete()
|
soFile.delete()
|
||||||
tmpSoFile.renameTo(soFile)
|
tmpSoFile.renameTo(soFile)
|
||||||
}
|
}
|
||||||
|
oldStream.close()
|
||||||
|
newStream.close()
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
System.load(soFile.absolutePath)
|
System.load(soFile.absolutePath)
|
||||||
@ -134,9 +122,11 @@ internal object NativeLoader {
|
|||||||
LogCenter.log(e.toString(), Level.WARN)
|
LogCenter.log(e.toString(), Level.WARN)
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
if (tmpSoFile.exists()) {
|
try {
|
||||||
tmpSoFile.delete()
|
libStream.close()
|
||||||
}
|
if (tmpSoFile.exists()) { tmpSoFile.delete() }
|
||||||
|
System.gc()
|
||||||
|
} catch (e: Exception) { LogCenter.log(e.toString(), Level.WARN) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user