@@ -11,7 +11,6 @@ import android.app.Application
11
11
import android.app.UiModeManager
12
12
import android.content.res.Configuration
13
13
import android.os.Build
14
- import android.os.StrictMode
15
14
import android.util.Log
16
15
import androidx.appcompat.app.AppCompatDelegate
17
16
import androidx.recyclerview.widget.LinearLayoutManager
@@ -37,10 +36,13 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
37
36
import org.lsposed.hiddenapibypass.HiddenApiBypass
38
37
import rikka.sui.Sui
39
38
import java.io.File
39
+ import java.io.FileInputStream
40
40
import java.io.FileNotFoundException
41
+ import java.io.InputStream
41
42
import java.lang.ref.WeakReference
43
+ import java.math.BigInteger
44
+ import java.security.MessageDigest
42
45
import java.time.ZonedDateTime
43
- import java.util.concurrent.Executors
44
46
45
47
class App : Application () {
46
48
@@ -62,39 +64,9 @@ class App : Application() {
62
64
instance = WeakReference (this )
63
65
HookManager .context = WeakReference (this )
64
66
65
- val externalStorage = getExternalFilesDir(null )!!
66
-
67
- Prefs .init (applicationContext)
68
- FileUtil .init (externalStorage)
69
-
70
67
setupHooks()
71
68
loadPlugins()
72
69
73
- if (BuildConfig .DEBUG ) {
74
- StrictMode .setVmPolicy(
75
- StrictMode .VmPolicy .Builder ().apply {
76
- detectLeakedRegistrationObjects()
77
- detectActivityLeaks()
78
- detectContentUriWithoutPermission()
79
- detectFileUriExposure()
80
- detectCleartextNetwork()
81
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .P ) {
82
- penaltyLog()
83
- return @apply
84
- }
85
- permitNonSdkApiUsage()
86
- penaltyListener(Executors .newSingleThreadExecutor()) { violation ->
87
- Log .e(" StrictMode" , " VM violation" , violation)
88
- violation.printStackTrace()
89
- }
90
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
91
- detectIncorrectContextUse()
92
- detectUnsafeIntentLaunch()
93
- }
94
- }.build()
95
- )
96
- }
97
-
98
70
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
99
71
HiddenApiBypass .addHiddenApiExemptions(" L" )
100
72
}
@@ -142,9 +114,6 @@ class App : Application() {
142
114
* Extracts kotlin stdlib and stdlib-common from assets.
143
115
*/
144
116
fun extractFiles () {
145
- FileUtil .classpathDir.resolve(" kotlin-stdlib-1.8.0.jar" ).apply {
146
- if (exists()) delete()
147
- }
148
117
extractAsset(
149
118
" kotlin-stdlib-1.9.0.jar" ,
150
119
FileUtil .classpathDir.resolve(" kotlin-stdlib-1.9.0.jar" )
@@ -156,7 +125,10 @@ class App : Application() {
156
125
}
157
126
158
127
fun extractAsset (assetName : String , targetFile : File ) {
159
- targetFile.exists().ifTrue { return }
128
+ if (targetFile.exists() && assetNeedsUpdate(assetName, targetFile)) {
129
+ targetFile.delete()
130
+ }
131
+
160
132
try {
161
133
assets.open(assetName).use { inputStream ->
162
134
targetFile.outputStream().use { outputStream ->
@@ -168,6 +140,25 @@ class App : Application() {
168
140
}
169
141
}
170
142
143
+ fun assetNeedsUpdate (assetName : String , targetFile : File ): Boolean {
144
+ val assetInputStream = assets.open(assetName)
145
+ val targetFileInputStream = FileInputStream (targetFile)
146
+ val assetChecksum = calculateChecksum(assetInputStream)
147
+ val targetFileChecksum = calculateChecksum(targetFileInputStream)
148
+ return assetChecksum != targetFileChecksum
149
+ }
150
+
151
+ fun calculateChecksum (inputStream : InputStream ): String {
152
+ val md = MessageDigest .getInstance(" SHA-256" )
153
+ val buffer = ByteArray (8192 )
154
+ var bytesRead: Int
155
+ while (inputStream.read(buffer).also { bytesRead = it } != - 1 ) {
156
+ md.update(buffer, 0 , bytesRead)
157
+ }
158
+ val digest = md.digest()
159
+ return BigInteger (1 , digest).toString(16 )
160
+ }
161
+
171
162
fun disableModules () {
172
163
JavacConfigProvider .disableModules()
173
164
}
@@ -186,7 +177,6 @@ class App : Application() {
186
177
}
187
178
188
179
private fun setupHooks () {
189
-
190
180
// Some libraries may call System.exit() to exit the app, which crashes the app.
191
181
// Currently, only JGit does this.
192
182
HookManager .registerHook(object : Hook (
@@ -223,8 +213,6 @@ class App : Application() {
223
213
param.result = null
224
214
}
225
215
})
226
-
227
-
228
216
}
229
217
230
218
override fun onConfigurationChanged (newConfig : Configuration ) {
0 commit comments