|
|
@@ -18,10 +18,21 @@ import com.example.modifier.BuildConfig
|
|
|
import com.example.modifier.MainActivity
|
|
|
import com.example.modifier.Utils
|
|
|
import com.example.modifier.baseTag
|
|
|
+import com.example.modifier.constants.PACKAGE_GMS
|
|
|
+import com.example.modifier.extension.kill
|
|
|
+import com.example.modifier.http.api.SysConfigApi
|
|
|
import com.example.modifier.http.ktorClient
|
|
|
+import com.example.modifier.http.response.SysConfigResponse
|
|
|
import com.example.modifier.service.ModifierService
|
|
|
+import io.ktor.client.call.body
|
|
|
+import io.ktor.client.plugins.resources.get
|
|
|
+import io.ktor.client.request.get
|
|
|
import io.ktor.client.request.head
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
+import org.apache.commons.io.FileUtils
|
|
|
+import org.json.JSONObject
|
|
|
import java.io.BufferedInputStream
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
import java.io.File
|
|
|
@@ -162,7 +173,7 @@ suspend fun optimize() {
|
|
|
|
|
|
suspend fun syncTime() {
|
|
|
try {
|
|
|
- Log.i("Modifier", "syncTime: start")
|
|
|
+ Log.i(systemTag, "syncTime: start")
|
|
|
val response = ktorClient.head("http://www.baidu.com")
|
|
|
val dateHeader = response.headers["Date"]
|
|
|
val date = ZonedDateTime.parse(
|
|
|
@@ -292,4 +303,51 @@ fun getIPAddress(): List<String> {
|
|
|
Log.e(systemTag, "Error getIPAddress", e)
|
|
|
emptyList()
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+suspend fun checkPif() {
|
|
|
+ try {
|
|
|
+ val config = ktorClient.get(SysConfigApi.Id(SysConfigApi(), "pif"))
|
|
|
+ .body<SysConfigResponse>()
|
|
|
+ if (config.value.isEmpty()) {
|
|
|
+ Log.i(systemTag, "cannot get pif.json from server")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ val newPif = JSONObject(config.value.split("\n")
|
|
|
+ .joinToString("\n") { line ->
|
|
|
+ line.replace(Regex("^\\s*//.*"), "")
|
|
|
+ })
|
|
|
+ val newFingerPrint = newPif.optString("FINGERPRINT", "")
|
|
|
+ if (newFingerPrint.isEmpty()) {
|
|
|
+ Log.i(systemTag, "cannot get fingerprint from pif.json")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val currentFingerprint = shellRun("cat /data/adb/modules/playintegrityfix/pif.json").let {
|
|
|
+ val json = JSONObject(it.first.split("\n")
|
|
|
+ .joinToString("\n") { line ->
|
|
|
+ line.replace(Regex("^\\s*//.*"), "")
|
|
|
+ })
|
|
|
+ json.optString("FINGERPRINT", "")
|
|
|
+ }
|
|
|
+
|
|
|
+ if (newFingerPrint != currentFingerprint) {
|
|
|
+ val tmpFile: File
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+ tmpFile = File.createTempFile("pif", ".json")
|
|
|
+ FileUtils.writeStringToFile(tmpFile, newPif.toString(), "UTF-8")
|
|
|
+ shellRun(
|
|
|
+ "cp ${tmpFile.path} /data/adb/modules/playintegrityfix/pif.json",
|
|
|
+ PACKAGE_GMS.kill(),
|
|
|
+ )
|
|
|
+ tmpFile.delete()
|
|
|
+ Log.i(systemTag, "pif.json updated, fingerprint: $newFingerPrint")
|
|
|
+ delay(5000)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.i(systemTag, "pif.json is up to date")
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ Log.e(systemTag, "Error checkPif", e)
|
|
|
+ }
|
|
|
}
|