refactor: Add main activity onCreate extension hook function

This commit is contained in:
LisoUseInAIKyrios
2025-09-30 22:17:10 +04:00
parent 2d49d76e82
commit 636bded69c
14 changed files with 71 additions and 81 deletions

View File

@@ -705,6 +705,7 @@ public final class app/revanced/patches/shared/misc/extension/ExtensionHook {
}
public final class app/revanced/patches/shared/misc/extension/SharedExtensionPatchKt {
public static final fun activityOnCreateExtensionHook (Ljava/lang/String;)Lkotlin/jvm/functions/Function0;
public static final fun extensionHook (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lapp/revanced/patcher/Fingerprint;)Lapp/revanced/patches/shared/misc/extension/ExtensionHook;
public static final fun extensionHook (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function0;
public static synthetic fun extensionHook$default (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lapp/revanced/patcher/Fingerprint;ILjava/lang/Object;)Lapp/revanced/patches/shared/misc/extension/ExtensionHook;

View File

@@ -1,9 +1,5 @@
package app.revanced.patches.cricbuzz.misc.extension
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val applicationInitHook = extensionHook {
custom { method, classDef ->
method.name == "onCreate" && classDef.endsWith("/NyitoActivity;")
}
}
internal val applicationInitHook = activityOnCreateExtensionHook("/NyitoActivity;")

View File

@@ -1,9 +1,7 @@
package app.revanced.patches.instagram.misc.extension.hooks
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val applicationInitHook = extensionHook {
custom { method, classDef ->
method.name == "onCreate" && classDef.endsWith("/InstagramAppShell;")
}
}
internal val applicationInitHook = activityOnCreateExtensionHook(
"/InstagramAppShell;"
)

View File

@@ -1,9 +1,7 @@
package app.revanced.patches.messenger.misc.extension
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val messengerApplicationOnCreateHook = extensionHook {
custom { method, classDef ->
method.name == "onCreate" && classDef.endsWith("/MessengerApplication;")
}
}
internal val messengerApplicationOnCreateHook = activityOnCreateExtensionHook(
"/MessengerApplication;"
)

View File

@@ -1,7 +1,8 @@
package app.revanced.patches.music.misc.extension.hooks
import app.revanced.patches.music.shared.YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
import app.revanced.patcher.string
import app.revanced.patches.music.shared.YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
import app.revanced.patches.shared.misc.extension.extensionHook
internal val applicationInitHook = extensionHook {
@@ -13,10 +14,6 @@ internal val applicationInitHook = extensionHook {
custom { method, _ -> method.name == "onCreate" }
}
internal val applicationInitOnCreateHook = extensionHook {
returns("V")
parameters("Landroid/os/Bundle;")
custom { method, classDef ->
method.name == "onCreate" && classDef.type == YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
}
}
internal val applicationInitOnCreateHook = activityOnCreateExtensionHook(
YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE
)

View File

@@ -1,9 +1,7 @@
package app.revanced.patches.nunl.ads
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val mainActivityOnCreateHook = extensionHook {
custom { method, classDef ->
classDef.endsWith("/NUApplication;") && method.name == "onCreate"
}
}
internal val mainActivityOnCreateHook = activityOnCreateExtensionHook(
"/NUApplication;"
)

View File

@@ -1,9 +1,7 @@
package app.revanced.patches.primevideo.misc.extension
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val applicationInitHook = extensionHook {
custom { method, classDef ->
method.name == "onCreate" && classDef.endsWith("/SplashScreenActivity;")
}
}
internal val applicationInitHook = activityOnCreateExtensionHook(
"/SplashScreenActivity;"
)

View File

@@ -1,9 +1,7 @@
package app.revanced.patches.reddit.customclients.baconreader.misc.extension.hooks
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val initHook = extensionHook {
custom { method, _ ->
method.definingClass == "Lcom/onelouder/baconreader/BaconReader;" && method.name == "onCreate"
}
}
internal val initHook = activityOnCreateExtensionHook(
"Lcom/onelouder/baconreader/BaconReader;"
)

View File

@@ -1,11 +1,7 @@
package app.revanced.patches.reddit.customclients.boostforreddit.misc.extension.hooks
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val initHook = extensionHook(
insertIndexResolver = { 1 },
) {
custom { method, _ ->
method.definingClass == "Lcom/rubenmayayo/reddit/MyApplication;" && method.name == "onCreate"
}
}
internal val initHook = activityOnCreateExtensionHook(
"Lcom/rubenmayayo/reddit/MyApplication;"
)

View File

@@ -1,11 +1,7 @@
package app.revanced.patches.reddit.customclients.sync.syncforreddit.extension.hooks
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val initHook = extensionHook(
insertIndexResolver = { 1 }, // Insert after call to super class.
) {
custom { method, classDef ->
method.name == "onCreate" && classDef.type == "Lcom/laurencedawson/reddit_sync/RedditApplication;"
}
}
internal val initHook = activityOnCreateExtensionHook(
"Lcom/laurencedawson/reddit_sync/RedditApplication;"
)

View File

@@ -115,3 +115,28 @@ fun extensionHook(
val fingerprint by FingerprintDelegate(block = fingerprintBuilderBlock)
ExtensionHook(fingerprint, insertIndexResolver, contextRegisterResolver)
}
/**
* Creates an extension hook from a non-obfuscated activity, which typically is the main activity
* defined in the app manifest.xml file.
*
* @param activityClassType Either the full activity class type such as `Lcom/company/MainActivity;`
* or the 'ends with' string for the activity such as `/MainActivity;`
*/
fun activityOnCreateExtensionHook(activityClassType: String): () -> ExtensionHook {
if (!activityClassType.endsWith(';')) {
throw IllegalArgumentException("Activity class type does not end with semicolon: $activityClassType")
}
val fullClassType = activityClassType.startsWith('L')
return extensionHook {
returns("V")
parameters("Landroid/os/Bundle;")
custom { method, classDef ->
method.name == "onCreate" &&
if (fullClassType) classDef.type == activityClassType
else classDef.type.endsWith(activityClassType)
}
}
}

View File

@@ -1,14 +1,11 @@
package app.revanced.patches.tiktok.misc.extension
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
import app.revanced.patches.shared.misc.extension.extensionHook
import com.android.tools.smali.dexlib2.AccessFlags
internal val initHook = extensionHook {
custom { method, classDef ->
classDef.type == "Lcom/ss/android/ugc/aweme/main/MainActivity;" &&
method.name == "onCreate"
}
}
internal val initHook = activityOnCreateExtensionHook(
"Lcom/ss/android/ugc/aweme/main/MainActivity;"
)
/**
* In some cases the extension code can be called before

View File

@@ -1,9 +1,5 @@
package app.revanced.patches.twitch.misc.extension
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
internal val initHook = extensionHook {
custom { method, classDef ->
method.name == "onCreate" && classDef.endsWith("/TwitchApplication;")
}
}
internal val initHook = activityOnCreateExtensionHook("/TwitchApplication;")

View File

@@ -1,6 +1,7 @@
package app.revanced.patches.youtube.misc.extension.hooks
import app.revanced.patcher.string
import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook
import app.revanced.patches.shared.misc.extension.extensionHook
import app.revanced.patches.youtube.shared.YOUTUBE_MAIN_ACTIVITY_CLASS_TYPE
@@ -17,11 +18,6 @@ internal val applicationInitHook = extensionHook {
)
}
internal val applicationInitOnCrateHook = extensionHook {
returns("V")
parameters("Landroid/os/Bundle;")
custom { method, classDef ->
method.name == "onCreate" && classDef.type == YOUTUBE_MAIN_ACTIVITY_CLASS_TYPE
}
}
internal val applicationInitOnCrateHook = activityOnCreateExtensionHook(
YOUTUBE_MAIN_ACTIVITY_CLASS_TYPE
)