diff --git a/app/src/main/kotlin/io/github/revenge/xposed/Main.kt b/app/src/main/kotlin/io/github/revenge/xposed/Main.kt index a93c45d..125954d 100644 --- a/app/src/main/kotlin/io/github/revenge/xposed/Main.kt +++ b/app/src/main/kotlin/io/github/revenge/xposed/Main.kt @@ -14,6 +14,21 @@ import cocobo1.pupu.xposed.modules.appearance.ThemesModule import cocobo1.pupu.xposed.modules.bridge.AdditionalBridgeMethodsModule import cocobo1.pupu.xposed.modules.bridge.BridgeModule +object HookStateHolder { + /** + * Whether all hooks are completed, and we are ready to load the JS bundle. + */ + val readyDeferred = CompletableDeferred() + + /** + * Whether we have successfully received a [Context] yet. + * Sometimes the app process is recreated and Xposed hooks way too late for us to get [Context] from [ContextWrapper.attachBaseContext]. + * But since Xposed hooks before [Activity.onCreate], we can still get it from there and still initialize properly. + */ + @Volatile + var gotContext = false +} + class Main : Module(), IXposedHookLoadPackage, IXposedHookZygoteInit { private var hooked = false private val modules = mutableListOf( @@ -22,6 +37,8 @@ class Main : Module(), IXposedHookLoadPackage, IXposedHookZygoteInit { AdditionalBridgeMethodsModule(), UpdaterModule(), FixResourcesModule(), + BlockDeepLinksTrackingModule(), + BlockCrashReportingModule(), LogBoxModule(), FontsModule(), ThemesModule(), diff --git a/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockCrashReportingModule.kt b/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockCrashReportingModule.kt new file mode 100644 index 0000000..523a945 --- /dev/null +++ b/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockCrashReportingModule.kt @@ -0,0 +1,34 @@ +package io.github.revenge.xposed.modules.no_track + +import android.content.Context +import de.robv.android.xposed.callbacks.XC_LoadPackage +import io.github.revenge.xposed.Module +import io.github.revenge.xposed.Utils.Log + +/** + * Hooks Discord's crash reporting to disable Sentry initialization. + * While Discord doesn't have Sentry auto-initialization on by default, we still hook the content provider just to be safe. + */ +class BlockCrashReportingModule : Module() { + override fun onLoad(packageParam: XC_LoadPackage.LoadPackageParam) = with(packageParam) { + val crashReportingClass = classLoader.safeLoadClass("com.discord.crash_reporting.CrashReporting") + crashReportingClass?.hookMethod( + "init", Context::class.java, String::class.java + ) { + before { + Log.i("Blocked CrashReporting initialization") + result = null + } + } + + val sentryInitProviderClass = classLoader.safeLoadClass("io.sentry.android.core.SentryInitProvider") + sentryInitProviderClass?.hookMethod("onCreate") { + before { + Log.i("Blocked SentryInitProvider initialization") + result = true + } + } + + return@with + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockDeepLinksTrackingModule.kt b/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockDeepLinksTrackingModule.kt new file mode 100644 index 0000000..e6b95b4 --- /dev/null +++ b/app/src/main/kotlin/io/github/revenge/xposed/modules/no_track/BlockDeepLinksTrackingModule.kt @@ -0,0 +1,25 @@ +package io.github.revenge.xposed.modules.no_track + +import android.content.Context +import de.robv.android.xposed.callbacks.XC_LoadPackage +import io.github.revenge.xposed.Module +import io.github.revenge.xposed.Utils.Log + +/** + * Hooks Discord's deep links tracking to disable AppsFlyer initialization. + */ +class BlockDeepLinksTrackingModule : Module() { + override fun onLoad(packageParam: XC_LoadPackage.LoadPackageParam) = with(packageParam) { + val deepLinksClass = classLoader.safeLoadClass("com.discord.deep_link.DeepLinks") + deepLinksClass?.hookMethod( + "init", Context::class.java + ) { + before { + Log.i("Blocked DeepLinks tracking initialization") + result = null + } + } + + return@with + } +} \ No newline at end of file