generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Google News): Add
Enable CustomTabs
and GmsCore support
patch (
#3111) Co-authored-by: benjy3gg <[email protected]> Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
1 parent
5bc9251
commit ad59096
Showing
20 changed files
with
249 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.revanced.patches.googlenews.customtabs | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.googlenews.customtabs.fingerprints.LaunchCustomTabFingerprint | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch( | ||
name = "Enable CustomTabs", | ||
description = "Enables CustomTabs to open articles in your default browser.", | ||
compatiblePackages = [CompatiblePackage("com.google.android.apps.magazines")], | ||
) | ||
@Suppress("unused") | ||
object EnableCustomTabs : BytecodePatch( | ||
setOf(LaunchCustomTabFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
LaunchCustomTabFingerprint.resultOrThrow().let { result -> | ||
result.mutableMethod.apply { | ||
val checkIndex = result.scanResult.patternScanResult!!.endIndex + 1 | ||
val register = getInstruction<OneRegisterInstruction>(checkIndex).registerA | ||
|
||
replaceInstruction(checkIndex, "const/4 v$register, 0x1") | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lin/app/revanced/patches/googlenews/customtabs/fingerprints/LaunchCustomTabFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package app.revanced.patches.googlenews.customtabs.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object LaunchCustomTabFingerprint : MethodFingerprint( | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, | ||
opcodes = listOf( | ||
Opcode.IPUT_OBJECT, | ||
Opcode.CONST_4, | ||
Opcode.IPUT, | ||
Opcode.CONST_4, | ||
Opcode.IPUT_BOOLEAN, | ||
), | ||
customFingerprint = { _, classDef -> classDef.endsWith("CustomTabsArticleLauncher;") }, | ||
) |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/app/revanced/patches/googlenews/misc/gms/Constants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package app.revanced.patches.googlenews.misc.gms | ||
|
||
internal object Constants { | ||
const val MAGAZINES_PACKAGE_NAME = "com.google.android.apps.magazines" | ||
const val REVANCED_MAGAZINES_PACKAGE_NAME = "app.revanced.android.magazines" | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/app/revanced/patches/googlenews/misc/gms/GmsCoreSupportPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package app.revanced.patches.googlenews.misc.gms | ||
|
||
import app.revanced.patches.googlenews.misc.gms.Constants.MAGAZINES_PACKAGE_NAME | ||
import app.revanced.patches.googlenews.misc.gms.Constants.REVANCED_MAGAZINES_PACKAGE_NAME | ||
import app.revanced.patches.googlenews.misc.gms.GmsCoreSupportResourcePatch.gmsCoreVendorGroupIdOption | ||
import app.revanced.patches.googlenews.misc.gms.fingerprints.MagazinesActivityOnCreateFingerprint | ||
import app.revanced.patches.googlenews.misc.gms.fingerprints.ServiceCheckFingerprint | ||
import app.revanced.patches.googlenews.misc.integrations.IntegrationsPatch | ||
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch | ||
|
||
@Suppress("unused") | ||
object GmsCoreSupportPatch : BaseGmsCoreSupportPatch( | ||
fromPackageName = MAGAZINES_PACKAGE_NAME, | ||
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME, | ||
primeMethodFingerprint = null, | ||
earlyReturnFingerprints = setOf(ServiceCheckFingerprint), | ||
mainActivityOnCreateFingerprint = MagazinesActivityOnCreateFingerprint, | ||
integrationsPatchDependency = IntegrationsPatch::class, | ||
gmsCoreSupportResourcePatch = GmsCoreSupportResourcePatch, | ||
// Remove version constraint, | ||
// once https://github.com/ReVanced/revanced-patches/pull/3111#issuecomment-2240877277 is resolved. | ||
compatiblePackages = setOf(CompatiblePackage(MAGAZINES_PACKAGE_NAME, setOf("5.108.0.644447823"))), | ||
fingerprints = setOf(ServiceCheckFingerprint), | ||
) { | ||
override val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/app/revanced/patches/googlenews/misc/gms/GmsCoreSupportResourcePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.revanced.patches.googlenews.misc.gms | ||
|
||
import app.revanced.patches.googlenews.misc.gms.Constants.MAGAZINES_PACKAGE_NAME | ||
import app.revanced.patches.googlenews.misc.gms.Constants.REVANCED_MAGAZINES_PACKAGE_NAME | ||
import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportResourcePatch | ||
|
||
object GmsCoreSupportResourcePatch : BaseGmsCoreSupportResourcePatch( | ||
fromPackageName = MAGAZINES_PACKAGE_NAME, | ||
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME, | ||
spoofedPackageSignature = "24bb24c05e47e0aefa68a58a766179d9b613a666", | ||
) |
9 changes: 9 additions & 0 deletions
9
...revanced/patches/googlenews/misc/gms/fingerprints/MagazinesActivityOnCreateFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.revanced.patches.googlenews.misc.gms.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object MagazinesActivityOnCreateFingerprint : MethodFingerprint( | ||
customFingerprint = { methodDef, classDef -> | ||
methodDef.name == "onCreate" && classDef.endsWith("/StartActivity;") | ||
}, | ||
) |
7 changes: 7 additions & 0 deletions
7
...in/kotlin/app/revanced/patches/googlenews/misc/gms/fingerprints/PrimeMethodFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.patches.googlenews.misc.gms.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object PrimeMethodFingerprint : MethodFingerprint( | ||
strings = listOf("com.google.android.GoogleCamera", "com.android.vending"), | ||
) |
12 changes: 12 additions & 0 deletions
12
...n/kotlin/app/revanced/patches/googlenews/misc/gms/fingerprints/ServiceCheckFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app.revanced.patches.googlenews.misc.gms.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal object ServiceCheckFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, | ||
parameters = listOf("L", "I"), | ||
strings = listOf("Google Play Services not available", "GooglePlayServices not available due to error "), | ||
) |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/app/revanced/patches/googlenews/misc/integrations/IntegrationsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.googlenews.misc.integrations | ||
|
||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.googlenews.misc.integrations.fingerprints.StartActivityInitFingerprint | ||
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch | ||
|
||
@Patch(requiresIntegrations = true) | ||
object IntegrationsPatch : BaseIntegrationsPatch( | ||
setOf(StartActivityInitFingerprint), | ||
) |
41 changes: 41 additions & 0 deletions
41
...evanced/patches/googlenews/misc/integrations/fingerprints/StartActivityInitFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package app.revanced.patches.googlenews.misc.integrations.fingerprints | ||
|
||
import app.revanced.patches.googlenews.misc.integrations.fingerprints.StartActivityInitFingerprint.getApplicationContextIndex | ||
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch.IntegrationsFingerprint | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
internal object StartActivityInitFingerprint : IntegrationsFingerprint( | ||
opcodes = listOf( | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT, | ||
Opcode.CONST_4, | ||
Opcode.IF_EQZ, | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_BOOLEAN, | ||
Opcode.INVOKE_VIRTUAL, // Calls startActivity.getApplicationContext(). | ||
Opcode.MOVE_RESULT_OBJECT, | ||
), | ||
insertIndexResolver = { method -> | ||
getApplicationContextIndex = method.indexOfFirstInstructionOrThrow { | ||
getReference<MethodReference>()?.name == "getApplicationContext" | ||
} | ||
|
||
getApplicationContextIndex + 2 // Below the move-result-object instruction | ||
}, | ||
contextRegisterResolver = { method -> | ||
val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1) | ||
as OneRegisterInstruction | ||
moveResultInstruction.registerA | ||
}, | ||
customFingerprint = { methodDef, classDef -> | ||
methodDef.name == "onCreate" && classDef.endsWith("/StartActivity;") | ||
}, | ||
) { | ||
private var getApplicationContextIndex = -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
...n/kotlin/app/revanced/patches/music/misc/gms/fingerprints/GooglePlayUtilityFingerprint.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.