-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup module apk and settings along with app apk
- Loading branch information
Showing
8 changed files
with
197 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/io/github/juby210/swiftbackupprem/BackupModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.github.juby210.swiftbackupprem | ||
|
||
import android.content.Context | ||
import de.robv.android.xposed.XC_MethodHook | ||
import de.robv.android.xposed.XposedBridge | ||
import io.github.juby210.swiftbackupprem.util.PreferencesManager | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
import java.io.File | ||
import java.lang.reflect.Modifier | ||
|
||
fun hookBackupApk(cl: ClassLoader, ctx: Context, customFirebaseApp: Boolean, prefs: PreferencesManager) { | ||
val pathsA = cl.loadClass("${paths!!.name}\$a") | ||
XposedBridge.hookMethod(backupApk!!.getDeclaredMethod("c"), object : XC_MethodHook() { | ||
override fun afterHookedMethod(param: MethodHookParam) { | ||
val pathsClass = paths!! | ||
val aInstance = pathsClass.getDeclaredField("y").get(null) | ||
val instance = pathsA.getDeclaredMethod("d").invoke(aInstance) | ||
val basePath = pathsClass.getDeclaredMethod("m").invoke(instance) as String | ||
|
||
val dir = File(basePath, "sbp") | ||
if (!dir.exists()) dir.mkdir() | ||
|
||
val apkFile = File(dir, "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}).apk") | ||
if (!apkFile.exists()) | ||
File(ctx.packageManager.getPackageInfo(BuildConfig.APPLICATION_ID, 0).applicationInfo.sourceDir).copyTo(apkFile, true) | ||
|
||
if (customFirebaseApp) with(prefs) { | ||
val json = JSONObject().apply { | ||
put("client", JSONArray().apply { | ||
put(JSONObject().apply { | ||
put("client_info", JSONObject().apply { put("mobilesdk_app_id", googleAppId) }) | ||
put("api_key", JSONArray().apply { put(JSONObject().apply { put("current_key", googleApiKey) }) }) | ||
}) | ||
}) | ||
put("project_info", JSONObject().apply { | ||
put("firebase_url", firebaseDatabaseUrl) | ||
put("project_number", gcmDefaultSenderId) | ||
put("storage_bucket", googleStorageBucket) | ||
put(Consts.projectId, projectId) | ||
}) | ||
put(Consts.oauthClientId, clientId) | ||
}.toString() | ||
File(dir, "google-services.json").run { if (!exists() || readText() != json) writeText(json) } | ||
} | ||
} | ||
}) | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/io/github/juby210/swiftbackupprem/Consts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
app/src/main/java/io/github/juby210/swiftbackupprem/DexKit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
@file:JvmName("DexKit") | ||
|
||
package io.github.juby210.swiftbackupprem | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import android.widget.Toast | ||
import org.luckypray.dexkit.DexKitBridge | ||
import org.luckypray.dexkit.query.matchers.* | ||
import java.lang.reflect.Modifier | ||
|
||
private val classesClientId = mapOf(561 to "kf.s0", 569 to "rf.r0") | ||
private val classesBackupApk = mapOf(561 to "org.swiftapps.swiftbackup.common.w1", 569 to "org.swiftapps.swiftbackup.common.n2") | ||
private val classesPaths = mapOf(561 to "me.b", 569 to "te.c") | ||
|
||
@JvmField | ||
var clientId: Class<*>? = null | ||
@JvmField | ||
var backupApk: Class<*>? = null | ||
@JvmField | ||
var paths: Class<*>? = null | ||
|
||
@Suppress("DEPRECATION") | ||
fun findObfuscatedClasses(ctx: Context, cl: ClassLoader, sourceDir: String) { | ||
val ver = Integer.valueOf(ctx.packageManager.getPackageInfo(Consts.packageName, 0).versionCode) | ||
if (classesClientId.containsKey(ver)) { | ||
clientId = cl.loadClass(classesClientId[ver]) | ||
backupApk = cl.loadClass(classesBackupApk[ver]) | ||
paths = cl.loadClass(classesPaths[ver]) | ||
} else { | ||
System.loadLibrary("dexkit") | ||
val excludePackages = listOf("android", "androidx", "com", "iammert", "java", "javax", "kotlin", "kotlinx", "moe", "nz.mega", | ||
"okhttp3", "okio", "org", "retrofit", "rikka") | ||
DexKitBridge.create(sourceDir)?.use { bridge -> | ||
bridge.findClass { | ||
excludePackages(excludePackages) | ||
matcher { | ||
fields { | ||
add { | ||
modifiers(Modifier.PUBLIC or Modifier.STATIC or Modifier.FINAL) | ||
name("a") | ||
} | ||
add { | ||
modifiers(Modifier.PRIVATE or Modifier.STATIC or Modifier.FINAL) | ||
name("b") | ||
} | ||
add { | ||
modifiers(Modifier.PRIVATE or Modifier.STATIC or Modifier.FINAL) | ||
name("c") | ||
type("java.lang.String") | ||
} | ||
add { | ||
modifiers(Modifier.PRIVATE or Modifier.STATIC or Modifier.FINAL) | ||
name("d") | ||
type("android.net.Uri") | ||
} | ||
count(4) | ||
} | ||
addMethod { | ||
modifiers(Modifier.PUBLIC or Modifier.FINAL) | ||
returnType("android.content.Intent") | ||
name("f") | ||
addParamType("boolean") | ||
} | ||
} | ||
}.firstOrNull()?.let { | ||
clientId = it.getInstance(cl) | ||
Log.d("SBP", "Found client id class: ${it.name}") | ||
} | ||
|
||
bridge.findClass { | ||
searchPackages("org.swiftapps.swiftbackup.common") | ||
matcher { | ||
fields { | ||
addForName("a") | ||
count(1) | ||
} | ||
addMethod { | ||
modifiers(Modifier.PRIVATE or Modifier.FINAL) | ||
returnType("void") | ||
name("c") | ||
paramCount(0) | ||
usingStrings("stable", "swift_backup_apks/", "SwiftBackupApkSaver") | ||
} | ||
} | ||
}.firstOrNull()?.let { | ||
backupApk = it.getInstance(cl) | ||
Log.d("SBP", "Found backup apk class: ${it.name}") | ||
} | ||
|
||
bridge.findClass { | ||
excludePackages(excludePackages) | ||
matcher { | ||
methods { | ||
add { | ||
name("<init>") | ||
addParamType("org.swiftapps.swiftbackup.anonymous.MFirebaseUser") | ||
addParamType("java.lang.String") | ||
paramCount(2) | ||
usingStrings("accounts/", "backups/", "cache/", "apps/", "local/", "cloud/", "icon_cache/", "sms/", "calls/") | ||
} | ||
add { | ||
modifiers(Modifier.PUBLIC or Modifier.FINAL) | ||
returnType("java.lang.String") | ||
name("m") | ||
paramCount(0) | ||
} | ||
} | ||
} | ||
}.firstOrNull()?.let { | ||
paths = it.getInstance(cl) | ||
Log.d("SBP", "Found paths class: ${it.name}") | ||
} | ||
} | ||
|
||
if (clientId == null || backupApk == null || paths == null) Toast.makeText( | ||
ctx, | ||
"[SBP] Couldn't fully hook Swift Backup. Check if there's module update or report an issue.", | ||
Toast.LENGTH_LONG | ||
).show() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters