feat: LSPatch obfuscation

This commit is contained in:
rhunk
2023-11-03 04:11:46 +01:00
parent 07daeaf994
commit f1a368d44e
10 changed files with 206 additions and 27 deletions

View File

@ -64,6 +64,10 @@ class SnapEnhance {
}
runCatching {
LSPatchUpdater.onBridgeConnected(appContext, bridgeClient)
}.onFailure {
logCritical("Failed to init LSPatchUpdater", it)
}
runCatching {
measureTimeMillis {
runBlocking {
init(this)

View File

@ -5,8 +5,8 @@ import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.Hooker
class DeviceSpooferHook: Feature("device_spoofer", loadParams = FeatureLoadParams.ACTIVITY_CREATE_ASYNC) {
override fun asyncOnActivityCreate() {
class DeviceSpooferHook: Feature("device_spoofer", loadParams = FeatureLoadParams.INIT_SYNC) {
override fun init() {
if (context.config.experimental.spoof.globalState != true) return
val fingerprint by context.config.experimental.spoof.device.fingerprint

View File

@ -18,11 +18,24 @@ object LSPatchUpdater {
}
fun onBridgeConnected(context: ModContext, bridgeClient: BridgeClient) {
val obfuscatedModulePath by lazy {
(runCatching {
context::class.java.classLoader?.loadClass("org.lsposed.lspatch.share.Constants")
}.getOrNull())?.declaredFields?.firstOrNull { it.name == "MANAGER_PACKAGE_NAME" }?.also {
it.isAccessible = true
}?.get(null) as? String
}
val embeddedModule = context.androidContext.cacheDir
.resolve("lspatch")
.resolve(BuildConfig.APPLICATION_ID).let { moduleDir ->
if (!moduleDir.exists()) return@let null
moduleDir.listFiles()?.firstOrNull { it.extension == "apk" }
} ?: obfuscatedModulePath?.let { path ->
context.androidContext.cacheDir.resolve(path).let dir@{ moduleDir ->
if (!moduleDir.exists()) return@dir null
moduleDir.listFiles()?.firstOrNull { it.extension == "apk" }
} ?: return
} ?: return
context.log.verbose("Found embedded SE at ${embeddedModule.absolutePath}", TAG)