Skip to content

Commit 273af26

Browse files
benjy3ggbenjy3ggoSumAtrIX
authored
feat(Google News): Add Enable CustomTabs and GmsCore support patch (#3111)
Co-authored-by: benjy3gg <[email protected]> Co-authored-by: oSumAtrIX <[email protected]>
1 parent 2b1b081 commit 273af26

File tree

20 files changed

+249
-55
lines changed

20 files changed

+249
-55
lines changed

api/revanced-patches.api

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ public final class app/revanced/patches/finanzonline/detection/root/RootDetectio
217217
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
218218
}
219219

220+
public final class app/revanced/patches/googlenews/customtabs/EnableCustomTabs : app/revanced/patcher/patch/BytecodePatch {
221+
public static final field INSTANCE Lapp/revanced/patches/googlenews/customtabs/EnableCustomTabs;
222+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
223+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
224+
}
225+
226+
public final class app/revanced/patches/googlenews/misc/gms/GmsCoreSupportPatch : app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportPatch {
227+
public static final field INSTANCE Lapp/revanced/patches/googlenews/misc/gms/GmsCoreSupportPatch;
228+
}
229+
230+
public final class app/revanced/patches/googlenews/misc/gms/GmsCoreSupportResourcePatch : app/revanced/patches/shared/misc/gms/BaseGmsCoreSupportResourcePatch {
231+
public static final field INSTANCE Lapp/revanced/patches/googlenews/misc/gms/GmsCoreSupportResourcePatch;
232+
}
233+
234+
public final class app/revanced/patches/googlenews/misc/integrations/IntegrationsPatch : app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch {
235+
public static final field INSTANCE Lapp/revanced/patches/googlenews/misc/integrations/IntegrationsPatch;
236+
}
237+
220238
public final class app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions : app/revanced/patcher/patch/BytecodePatch {
221239
public static final field INSTANCE Lapp/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions;
222240
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
@@ -2033,7 +2051,11 @@ public final class app/revanced/util/BytecodeUtilsKt {
20332051
public static final fun indexOfIdResourceOrThrow (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I
20342052
public static final fun injectHideViewCall (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;IILjava/lang/String;Ljava/lang/String;)V
20352053
public static final fun resultOrThrow (Lapp/revanced/patcher/fingerprint/MethodFingerprint;)Lapp/revanced/patcher/fingerprint/MethodFingerprintResult;
2054+
public static final fun returnEarly (Lapp/revanced/patcher/fingerprint/MethodFingerprint;Z)V
2055+
public static final fun returnEarly (Ljava/lang/Iterable;Z)V
20362056
public static final fun returnEarly (Ljava/util/List;Z)V
2057+
public static synthetic fun returnEarly$default (Lapp/revanced/patcher/fingerprint/MethodFingerprint;ZILjava/lang/Object;)V
2058+
public static synthetic fun returnEarly$default (Ljava/lang/Iterable;ZILjava/lang/Object;)V
20372059
public static synthetic fun returnEarly$default (Ljava/util/List;ZILjava/lang/Object;)V
20382060
public static final fun transformMethods (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lkotlin/jvm/functions/Function1;)V
20392061
public static final fun traverseClassHierarchy (Lapp/revanced/patcher/data/BytecodeContext;Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lkotlin/jvm/functions/Function1;)V
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package app.revanced.patches.googlenews.customtabs
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6+
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.annotation.CompatiblePackage
8+
import app.revanced.patcher.patch.annotation.Patch
9+
import app.revanced.patches.googlenews.customtabs.fingerprints.LaunchCustomTabFingerprint
10+
import app.revanced.util.resultOrThrow
11+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
12+
13+
@Patch(
14+
name = "Enable CustomTabs",
15+
description = "Enables CustomTabs to open articles in your default browser.",
16+
compatiblePackages = [CompatiblePackage("com.google.android.apps.magazines")],
17+
)
18+
@Suppress("unused")
19+
object EnableCustomTabs : BytecodePatch(
20+
setOf(LaunchCustomTabFingerprint)
21+
) {
22+
override fun execute(context: BytecodeContext) {
23+
LaunchCustomTabFingerprint.resultOrThrow().let { result ->
24+
result.mutableMethod.apply {
25+
val checkIndex = result.scanResult.patternScanResult!!.endIndex + 1
26+
val register = getInstruction<OneRegisterInstruction>(checkIndex).registerA
27+
28+
replaceInstruction(checkIndex, "const/4 v$register, 0x1")
29+
}
30+
}
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app.revanced.patches.googlenews.customtabs.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
import com.android.tools.smali.dexlib2.Opcode
7+
8+
internal object LaunchCustomTabFingerprint : MethodFingerprint(
9+
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
10+
opcodes = listOf(
11+
Opcode.IPUT_OBJECT,
12+
Opcode.CONST_4,
13+
Opcode.IPUT,
14+
Opcode.CONST_4,
15+
Opcode.IPUT_BOOLEAN,
16+
),
17+
customFingerprint = { _, classDef -> classDef.endsWith("CustomTabsArticleLauncher;") },
18+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package app.revanced.patches.googlenews.misc.gms
2+
3+
internal object Constants {
4+
const val MAGAZINES_PACKAGE_NAME = "com.google.android.apps.magazines"
5+
const val REVANCED_MAGAZINES_PACKAGE_NAME = "app.revanced.android.magazines"
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package app.revanced.patches.googlenews.misc.gms
2+
3+
import app.revanced.patches.googlenews.misc.gms.Constants.MAGAZINES_PACKAGE_NAME
4+
import app.revanced.patches.googlenews.misc.gms.Constants.REVANCED_MAGAZINES_PACKAGE_NAME
5+
import app.revanced.patches.googlenews.misc.gms.GmsCoreSupportResourcePatch.gmsCoreVendorGroupIdOption
6+
import app.revanced.patches.googlenews.misc.gms.fingerprints.MagazinesActivityOnCreateFingerprint
7+
import app.revanced.patches.googlenews.misc.gms.fingerprints.ServiceCheckFingerprint
8+
import app.revanced.patches.googlenews.misc.integrations.IntegrationsPatch
9+
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch
10+
11+
@Suppress("unused")
12+
object GmsCoreSupportPatch : BaseGmsCoreSupportPatch(
13+
fromPackageName = MAGAZINES_PACKAGE_NAME,
14+
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME,
15+
primeMethodFingerprint = null,
16+
earlyReturnFingerprints = setOf(ServiceCheckFingerprint),
17+
mainActivityOnCreateFingerprint = MagazinesActivityOnCreateFingerprint,
18+
integrationsPatchDependency = IntegrationsPatch::class,
19+
gmsCoreSupportResourcePatch = GmsCoreSupportResourcePatch,
20+
// Remove version constraint,
21+
// once https://github.com/ReVanced/revanced-patches/pull/3111#issuecomment-2240877277 is resolved.
22+
compatiblePackages = setOf(CompatiblePackage(MAGAZINES_PACKAGE_NAME, setOf("5.108.0.644447823"))),
23+
fingerprints = setOf(ServiceCheckFingerprint),
24+
) {
25+
override val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.revanced.patches.googlenews.misc.gms
2+
3+
import app.revanced.patches.googlenews.misc.gms.Constants.MAGAZINES_PACKAGE_NAME
4+
import app.revanced.patches.googlenews.misc.gms.Constants.REVANCED_MAGAZINES_PACKAGE_NAME
5+
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportResourcePatch
6+
7+
object GmsCoreSupportResourcePatch : BaseGmsCoreSupportResourcePatch(
8+
fromPackageName = MAGAZINES_PACKAGE_NAME,
9+
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME,
10+
spoofedPackageSignature = "24bb24c05e47e0aefa68a58a766179d9b613a666",
11+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.revanced.patches.googlenews.misc.gms.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
internal object MagazinesActivityOnCreateFingerprint : MethodFingerprint(
6+
customFingerprint = { methodDef, classDef ->
7+
methodDef.name == "onCreate" && classDef.endsWith("/StartActivity;")
8+
},
9+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package app.revanced.patches.googlenews.misc.gms.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
internal object PrimeMethodFingerprint : MethodFingerprint(
6+
strings = listOf("com.google.android.GoogleCamera", "com.android.vending"),
7+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package app.revanced.patches.googlenews.misc.gms.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
7+
internal object ServiceCheckFingerprint : MethodFingerprint(
8+
returnType = "V",
9+
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
10+
parameters = listOf("L", "I"),
11+
strings = listOf("Google Play Services not available", "GooglePlayServices not available due to error "),
12+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package app.revanced.patches.googlenews.misc.integrations
2+
3+
import app.revanced.patcher.patch.annotation.Patch
4+
import app.revanced.patches.googlenews.misc.integrations.fingerprints.StartActivityInitFingerprint
5+
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch
6+
7+
@Patch(requiresIntegrations = true)
8+
object IntegrationsPatch : BaseIntegrationsPatch(
9+
setOf(StartActivityInitFingerprint),
10+
)

0 commit comments

Comments
 (0)