mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-30 13:30:19 +02:00
fix(core/xposed_loader): prevent loading in sub processes
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
parent
4b93ec7181
commit
d8e98d575b
@ -1,7 +1,6 @@
|
|||||||
package me.rhunk.snapenhance.core
|
package me.rhunk.snapenhance.core
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Application
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -53,10 +52,9 @@ class SnapEnhance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
fun init(context: Context) {
|
||||||
Application::class.java.hook("attach", HookStage.BEFORE) { param ->
|
|
||||||
appContext = ModContext(
|
appContext = ModContext(
|
||||||
androidContext = param.arg<Context>(0).also { classLoader = it.classLoader }
|
androidContext = context.also { classLoader = it.classLoader }
|
||||||
)
|
)
|
||||||
appContext.apply {
|
appContext.apply {
|
||||||
bridgeClient = BridgeClient(this)
|
bridgeClient = BridgeClient(this)
|
||||||
@ -103,19 +101,10 @@ class SnapEnhance {
|
|||||||
}.also {
|
}.also {
|
||||||
appContext.log.verbose("init took ${it}ms")
|
appContext.log.verbose("init took ${it}ms")
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
|
||||||
isBridgeInitialized = true
|
|
||||||
}.onFailure {
|
|
||||||
appContext.logCritical("Failed to initialize bridge", it)
|
|
||||||
InAppOverlay.showCrashOverlay("SnapEnhance failed to initialize. Please check logs for more details.", it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hookMainActivity("onCreate") {
|
hookMainActivity("onPostCreate") {
|
||||||
val isMainActivityNotNull = appContext.mainActivity != null
|
|
||||||
appContext.mainActivity = this
|
appContext.mainActivity = this
|
||||||
if (isMainActivityNotNull || !appContext.mappings.isMappingsLoaded) return@hookMainActivity
|
if (!appContext.mappings.isMappingsLoaded) return@hookMainActivity
|
||||||
appContext.isMainActivityPaused = false
|
appContext.isMainActivityPaused = false
|
||||||
onActivityCreate()
|
onActivityCreate()
|
||||||
appContext.actionManager.onNewIntent(intent)
|
appContext.actionManager.onNewIntent(intent)
|
||||||
@ -140,6 +129,13 @@ class SnapEnhance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.onSuccess {
|
||||||
|
isBridgeInitialized = true
|
||||||
|
}.onFailure {
|
||||||
|
appContext.logCritical("Failed to initialize bridge", it)
|
||||||
|
InAppOverlay.showCrashOverlay("SnapEnhance failed to initialize. Please check logs for more details.", it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun init(scope: CoroutineScope) {
|
private fun init(scope: CoroutineScope) {
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
package me.rhunk.snapenhance.core
|
package me.rhunk.snapenhance.core
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||||
|
import de.robv.android.xposed.XposedBridge
|
||||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||||
|
import me.rhunk.snapenhance.common.BuildConfig
|
||||||
import me.rhunk.snapenhance.common.Constants
|
import me.rhunk.snapenhance.common.Constants
|
||||||
|
import me.rhunk.snapenhance.core.util.hook.HookStage
|
||||||
|
import me.rhunk.snapenhance.core.util.hook.hook
|
||||||
|
|
||||||
class XposedLoader : IXposedHookLoadPackage {
|
class XposedLoader : IXposedHookLoadPackage {
|
||||||
override fun handleLoadPackage(p0: XC_LoadPackage.LoadPackageParam) {
|
override fun handleLoadPackage(p0: XC_LoadPackage.LoadPackageParam) {
|
||||||
if (p0.packageName != Constants.SNAPCHAT_PACKAGE_NAME) return
|
if (p0.packageName != Constants.SNAPCHAT_PACKAGE_NAME) return
|
||||||
SnapEnhance()
|
// prevent loading in sub-processes
|
||||||
|
if (p0.processName.contains(":")) return
|
||||||
|
XposedBridge.log("Loading SnapEnhance v${BuildConfig.VERSION_NAME}#${BuildConfig.GIT_HASH} (package: ${BuildConfig.APPLICATION_ID})")
|
||||||
|
Application::class.java.hook("attach", HookStage.BEFORE) { param ->
|
||||||
|
SnapEnhance().init(param.arg(0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user