diff --git a/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt index 723ee432f..786e93f2c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.amazon -import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.returnEarly @Suppress("unused") val deepLinkingPatch = bytecodePatch( @@ -11,12 +11,6 @@ val deepLinkingPatch = bytecodePatch( compatibleWith("com.amazon.mShop.android.shopping") apply { - deepLinkingMethod.addInstructions( - 0, - """ - const/4 v0, 0x1 - return v0 - """, - ) + deepLinkingMethod.returnEarly(true) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt index 199be0b70..fc8a3322b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.cieid.restrictions.root -import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.returnEarly @Suppress("unused") val bypassRootChecksPatch = bytecodePatch( @@ -11,6 +11,6 @@ val bypassRootChecksPatch = bytecodePatch( compatibleWith("it.ipzs.cieid") apply { - checkRootMethod.addInstruction(1, "return-void") + checkRootMethod.returnEarly() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt index a3565a931..9c1bbe82c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt @@ -21,10 +21,10 @@ val disableAdsPatch = bytecodePatch( // SharedPreferences has a debug boolean value with key "disable_ads", which maps to "DebugCategory.DISABLE_ADS". // // MonetizationDebugSettings seems to be the most general setting to work fine. - initializeMonetizationDebugSettingsMethod.match( // TODO - monetizationDebugSettingsToStringMethod.classDef + initializeMonetizationDebugSettingsMethodMatch.match( + monetizationDebugSettingsToStringMethod.classDef, ).method.apply { - val insertIndex = initializeMonetizationDebugSettingsMethod.instructionMatches.first().index + val insertIndex = initializeMonetizationDebugSettingsMethodMatch.indices.first() val register = getInstruction(insertIndex).registerA addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/Fingerprints.kt index d6a2f4aa8..20b047f9f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/Fingerprints.kt @@ -5,15 +5,14 @@ import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.initializeMonetizationDebugSettingsMethod by gettingFirstMutableMethodDeclaratively { +internal val initializeMonetizationDebugSettingsMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) returnType("V") // Parameters have not been reliable for fingerprinting between versions. opcodes(Opcode.IPUT_BOOLEAN) } -internal val BytecodePatchContext.monetizationDebugSettingsToStringMethod by gettingFirstMutableMethodDeclaratively( - "MonetizationDebugSettings(" // Partial string match. -) { +internal val BytecodePatchContext.monetizationDebugSettingsToStringMethod by gettingFirstMutableMethodDeclaratively { name("toString") + instructions(string("MonetizationDebugSettings(", String::contains)) } diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt index 7d19663c6..56892c0fb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt @@ -10,7 +10,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") val enableDebugMenuPatch = bytecodePatch( name = "Enable debug menu", - use = false + use = false, ) { compatibleWith("com.duolingo") @@ -19,18 +19,13 @@ val enableDebugMenuPatch = bytecodePatch( debugCategoryAllowOnReleaseBuildsMethod.returnEarly(true) // Change build config debug build flag. - buildConfigProviderConstructorMethod.match( // TODO - buildConfigProviderToStringMethod.classDef + buildConfigProviderConstructorMethodMatch.match( + buildConfigProviderToStringMethod.classDef, ).let { - val index = it.patternMatch.startIndex // TODO + val index = it.indices.first() - it.apply { - val register = getInstruction(index).registerA // TODO - addInstruction( - index + 1, - "const/4 v$register, 0x1" - ) - } + val register = it.method.getInstruction(index).registerA + it.method.addInstruction(index + 1, "const/4 v$register, 0x1") } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/Fingerprints.kt index 6e1e7fcfe..312333ec5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/Fingerprints.kt @@ -12,17 +12,16 @@ internal val BytecodePatchContext.debugCategoryAllowOnReleaseBuildsMethod by get parameterTypes() } -internal val BytecodePatchContext.buildConfigProviderConstructorMethod by gettingFirstMutableMethodDeclaratively { +internal val buildConfigProviderConstructorMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) parameterTypes() opcodes(Opcode.CONST_4) } -internal val BytecodePatchContext.buildConfigProviderToStringMethod by gettingFirstMutableMethodDeclaratively( - "BuildConfigProvider(" // Partial string match. -) { +internal val BytecodePatchContext.buildConfigProviderToStringMethod by gettingFirstMutableMethodDeclaratively { name("toString") parameterTypes() returnType("Ljava/lang/String;") + instructions(string("BuildConfigProvider(", String::contains)) } diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/energy/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/energy/Fingerprints.kt index ce8c9af66..b455cd7dd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/energy/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/energy/Fingerprints.kt @@ -14,10 +14,12 @@ internal val BytecodePatchContext.initializeEnergyConfigMethod by gettingFirstMu } // Class name currently is not obfuscated, but it may be in the future. -internal val BytecodePatchContext.energyConfigToStringMethod by gettingFirstMutableMethodDeclaratively( - "EnergyConfig(", "maxEnergy=" // Partial string matches. -) { +internal val BytecodePatchContext.energyConfigToStringMethod by gettingFirstMutableMethodDeclaratively { name("toString") parameterTypes() returnType("Ljava/lang/String;") + instructions( + string("EnergyConfig(", String::contains), + string("maxEnergy=", String::contains), + ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt index f84adf8f1..9a2ffae70 100644 --- a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.finanzonline.detection.bootloader -import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.returnEarly @Suppress("unused") val bootloaderDetectionPatch = bytecodePatch( @@ -11,14 +11,8 @@ val bootloaderDetectionPatch = bytecodePatch( compatibleWith("at.gv.bmf.bmf2go") apply { - setOf(createKeyMethod, bootStateMethod).forEach { fingerprint -> - fingerprint.addInstructions( - 0, - """ - const/4 v0, 0x1 - return v0 - """, - ) + setOf(createKeyMethod, bootStateMethod).forEach { method -> + method.returnEarly(true) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/Fingerprints.kt index 6f7ec158a..1ce7ef8d4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/Fingerprints.kt @@ -29,18 +29,17 @@ internal val BytecodePatchContext.bootStateMethod by gettingFirstMutableMethodDe Opcode.IF_NE, Opcode.GOTO, Opcode.MOVE, - Opcode.RETURN + Opcode.RETURN, ) } - // Located @ at.gv.bmf.bmf2go.taxequalization.tools.utils.AttestationHelper#createKey (3.0.1) internal val BytecodePatchContext.createKeyMethod by gettingFirstMutableMethodDeclaratively( "attestation", "SHA-256", "random", "EC", - "AndroidKeyStore" + "AndroidKeyStore", ) { accessFlags(AccessFlags.PUBLIC) returnType("Z") diff --git a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt index d58a0ea34..e09afa967 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt @@ -13,8 +13,8 @@ val enableCustomTabsPatch = bytecodePatch( compatibleWith("com.google.android.apps.magazines") apply { - launchCustomTabMethod.apply { - val checkIndex = launchCustomTabMethod.instructionMatches.last().index + 1 // TODO + launchCustomTabMethodMatch.method.apply { + val checkIndex = launchCustomTabMethodMatch.indices.last() + 1 val register = getInstruction(checkIndex).registerA replaceInstruction(checkIndex, "const/4 v$register, 0x1") diff --git a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/Fingerprints.kt index aa5adaefe..edf6ccdc2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/Fingerprints.kt @@ -2,13 +2,12 @@ package app.revanced.patches.googlenews.customtabs import app.revanced.patcher.accessFlags import app.revanced.patcher.definingClass -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.firstMethodComposite import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.launchCustomTabMethod by gettingFirstMutableMethodDeclaratively { +internal val launchCustomTabMethodMatch = firstMethodComposite { definingClass("CustomTabsArticleLauncher;"::endsWith) accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) opcodes( diff --git a/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt index 70a906e74..3fa17fc60 100644 --- a/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.hexeditor.ad -import app.revanced.patcher.extensions.replaceInstructions import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.returnEarly @Suppress("unused") val disableAdsPatch = bytecodePatch( @@ -10,12 +10,6 @@ val disableAdsPatch = bytecodePatch( compatibleWith("com.myprog.hexedit") apply { - primaryAdsMethod.replaceInstructions( - 0, - """ - const/4 v0, 0x1 - return v0 - """, - ) + primaryAdsMethod.returnEarly(true) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/DisableVersionCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/DisableVersionCheckPatch.kt deleted file mode 100644 index ad1e0f269..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/DisableVersionCheckPatch.kt +++ /dev/null @@ -1,22 +0,0 @@ -package app.revanced.patches.lightroom.misc.version - -import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patches.lightroom.misc.bypassVersionCheck.refreshRemoteConfigurationMethod - -@Suppress("unused") -val disableVersionCheckPatch = bytecodePatch( - name = "Disable version check", - description = "Disables the server-side version check that prevents the app from starting.", -) { - compatibleWith("com.adobe.lrmobile"("9.3.0")) - - apply { - refreshRemoteConfigurationMethod.apply { - val igetIndex = refreshRemoteConfigurationMethod.patternMatch!!.endIndex // TODO - - // This value represents the server command to clear all version restrictions. - val statusForceReset = "-0x2"; - replaceInstruction(igetIndex, "const/4 v1, $statusForceReset") - } - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt index be4b51152..b4dcc7826 100644 --- a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.lightroom.misc.login +import app.revanced.patcher.extensions.instructions import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch @@ -10,10 +11,8 @@ val disableMandatoryLoginPatch = bytecodePatch( compatibleWith("com.adobe.lrmobile"("9.3.0")) apply { - isLoggedInMethod.apply { - val index = implementation!!.instructions.lastIndex - 1 - // Set isLoggedIn = true. - replaceInstruction(index, "const/4 v0, 0x1") - } + val index = isLoggedInMethod.instructions.lastIndex - 1 + // Set isLoggedIn = true. + isLoggedInMethod.replaceInstruction(index, "const/4 v0, 0x1") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/DisableVersionCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/DisableVersionCheckPatch.kt new file mode 100644 index 000000000..86916848c --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/DisableVersionCheckPatch.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.lightroom.misc.version + +import app.revanced.patcher.extensions.replaceInstruction +import app.revanced.patcher.patch.bytecodePatch + +@Suppress("unused") +val disableVersionCheckPatch = bytecodePatch( + name = "Disable version check", + description = "Disables the server-side version check that prevents the app from starting.", +) { + compatibleWith("com.adobe.lrmobile"("9.3.0")) + + apply { + val igetIndex = refreshRemoteConfigurationMethodMatch.indices.last() + + // This value represents the server command to clear all version restrictions. + val statusForceReset = "-0x2" + refreshRemoteConfigurationMethodMatch.method.replaceInstruction(igetIndex, "const/4 v1, $statusForceReset") + } +} diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/Fingerprints.kt similarity index 56% rename from patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/Fingerprints.kt rename to patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/Fingerprints.kt index 59573fb7e..3921d0e06 100644 --- a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/bypassVersionCheck/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/version/Fingerprints.kt @@ -1,15 +1,14 @@ -package app.revanced.patches.lightroom.misc.bypassVersionCheck +package app.revanced.patches.lightroom.misc.version import app.revanced.patcher.accessFlags -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.firstMethodComposite import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.refreshRemoteConfigurationMethod by gettingFirstMutableMethodDeclaratively( +internal val refreshRemoteConfigurationMethodMatch = firstMethodComposite( "com.adobe.lrmobile.denylisted_version_set_key", - "com.adobe.lrmobile.app_min_version_key" + "com.adobe.lrmobile.app_min_version_key", ) { accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC) opcodes( diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/metaai/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/metaai/Fingerprints.kt index d063fbf2a..bf0cc14e6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/metaai/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/metaai/Fingerprints.kt @@ -7,12 +7,11 @@ import com.android.tools.smali.dexlib2.Opcode internal val BytecodePatchContext.getMobileConfigBoolMethod by gettingFirstMutableMethodDeclaratively { returnType("Z") opcodes(Opcode.RETURN) - custom { immutableClassDef.interfaces.contains("Lcom/facebook/mobileconfig/factory/MobileConfigUnsafeContext;") } + custom { "Lcom/facebook/mobileconfig/factory/MobileConfigUnsafeContext;" in immutableClassDef.interfaces } } internal val BytecodePatchContext.metaAIKillSwitchCheckMethod by gettingFirstMutableMethodDeclaratively("SearchAiagentImplementationsKillSwitch") { opcodes(Opcode.CONST_WIDE) - } internal val BytecodePatchContext.extensionMethodMethod by gettingFirstMutableMethodDeclaratively("REPLACED_BY_PATCH") { name(EXTENSION_METHOD_NAME) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/Fingerprints.kt index e11767321..0f7b59691 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/Fingerprints.kt @@ -4,14 +4,11 @@ import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patches.music.shared.YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE import app.revanced.patches.shared.misc.mapping.ResourceType -import app.revanced.patches.shared.misc.mapping.resourceLiteral internal val BytecodePatchContext.cairoSplashAnimationConfigMethod by gettingFirstMutableMethodDeclaratively { name("onCreate") returnType("V") definingClass(YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE) parameterTypes("Landroid/os/Bundle;") - instructions( - resourceLiteral(ResourceType.LAYOUT, "main_activity_launch_animation") - ) + instructions(ResourceType.LAYOUT("main_activity_launch_animation")) } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt index 2c8d39601..5b4fcdc1e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt @@ -1,6 +1,5 @@ package app.revanced.patches.music.misc.backgroundplayback -import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.music.misc.extension.sharedExtensionPatch import app.revanced.patches.music.misc.settings.settingsPatch @@ -12,22 +11,18 @@ val backgroundPlaybackPatch = bytecodePatch( ) { dependsOn( sharedExtensionPatch, - settingsPatch + settingsPatch, ) compatibleWith( "com.google.android.apps.youtube.music"( "7.29.52", - "8.10.52" - ) + "8.10.52", + ), ) apply { - kidsBackgroundPlaybackPolicyControllerMethod.addInstruction( - 0, - "return-void", - ) - + kidsBackgroundPlaybackPolicyControllerMethod.returnEarly() backgroundPlaybackDisableMethod.returnEarly(true) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt index 6611cad90..f06e50304 100644 --- a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt +++ b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt @@ -1,8 +1,8 @@ package app.revanced.patches.protonvpn.splittunneling -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.extensions.removeInstruction +import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt index 9c6bab891..dd2ef2c69 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt @@ -1,7 +1,6 @@ package app.revanced.patches.shared.misc.mapping -import app.revanced.patcher.InstructionLocation -import app.revanced.patcher.LiteralFilter +import app.revanced.patcher.Predicate import app.revanced.patcher.extensions.wideLiteral import app.revanced.patcher.literal import app.revanced.patcher.patch.PatchException @@ -35,10 +34,12 @@ enum class ResourceType(val value: String) { STYLEABLE("styleable"), TRANSITION("transition"), VALUES("values"), - XML("xml"); + XML("xml"), + ; - operator fun invoke(name: String): Instruction.() -> Boolean = - getResourceId(this, name).let { { wideLiteral(it) } } + val id = getResourceId(this, name) + + operator fun invoke(name: String): Predicate = { wideLiteral == id } companion object { private val VALUE_MAP: Map = entries.associateBy { it.value } @@ -82,7 +83,7 @@ fun hasResourceId(type: ResourceType, name: String) = resourceMappings[type.valu fun resourceLiteral( type: ResourceType, name: String, - location: InstructionLocation = InstructionLocation.MatchAfterAnywhere() + location: InstructionLocation = InstructionLocation.MatchAfterAnywhere(), ) = literal({ getResourceId(type, name) }, null, location) val resourceMappingPatch = resourcePatch { diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt index 634a3c7da..3d5f119cf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt @@ -37,7 +37,7 @@ val enableOfflineSync = bytecodePatch( // Patch the URL builder to use the HTTPS_STREAM endpoint // instead of the offline sync endpoint to downloading the track. - downloadOperationsURLBuilderFingerprint.apply { + downloadOperationsURLBuilderMethod.apply { val getEndpointsEnumFieldIndex = 1 val getEndpointsEnumFieldInstruction = getInstruction(getEndpointsEnumFieldIndex) @@ -53,7 +53,7 @@ val enableOfflineSync = bytecodePatch( // The HTTPS_STREAM endpoint does not return the necessary headers for offline sync. // Mock the headers to prevent the app from crashing by setting them to empty strings. // The headers are all cosmetic and do not affect the functionality of the app. - downloadOperationsHeaderVerificationFingerprint.apply { + downloadOperationsHeaderVerificationMethod.apply { // The first three null checks need to be patched. instructions.asSequence().filter { it.opcode == Opcode.IF_EQZ diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/Fingerprints.kt index 367c0b1a3..e2d2b8b0e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/Fingerprints.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.downloadOperationsURLBuilderFingerprint by gettingFirstMutableMethodDeclaratively { +internal val BytecodePatchContext.downloadOperationsURLBuilderMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Ljava/lang/String") parameterTypes("L", "L") @@ -16,10 +16,10 @@ internal val BytecodePatchContext.downloadOperationsURLBuilderFingerprint by get ) } -internal val BytecodePatchContext.downloadOperationsHeaderVerificationFingerprint by gettingFirstMutableMethodDeclaratively( +internal val BytecodePatchContext.downloadOperationsHeaderVerificationMethod by gettingFirstMutableMethodDeclaratively( "X-SC-Mime-Type", "X-SC-Preset", - "X-SC-Quality" + "X-SC-Quality", ) { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt index 06e79a8c0..bcaa71f68 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt @@ -1,13 +1,12 @@ package app.revanced.patches.strava.upselling -import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.patch.bytecodePatch -import com.android.tools.smali.dexlib2.mutable.MutableMethod.Companion.toMutable import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.immutable.ImmutableMethod +import com.android.tools.smali.dexlib2.mutable.MutableMethod.Companion.toMutable @Suppress("unused") val disableSubscriptionSuggestionsPatch = bytecodePatch( @@ -20,11 +19,11 @@ val disableSubscriptionSuggestionsPatch = bytecodePatch( val pageSuffix = "_upsell" val label = "original" - val className = getModulesMethod.classDef.type - val originalMethod = getModulesMethod + val className = getModulesMethodMatch.classDef.type + val originalMethod = getModulesMethodMatch.method val returnType = originalMethod.returnType - getModulesMethod.classDef.methods.add( + getModulesMethodMatch.classDef.methods.add( ImmutableMethod( className, helperMethodName, @@ -53,16 +52,14 @@ val disableSubscriptionSuggestionsPatch = bytecodePatch( }, ) - val getModulesIndex = getModulesMethod.instructionMatches.first().index // TODO - with(originalMethod) { - removeInstruction(getModulesIndex) - addInstructions( - getModulesIndex, - """ - invoke-direct {p0}, $className->$helperMethodName()$returnType - move-result-object v0 - """, - ) - } + val getModulesIndex = getModulesMethodMatch.indices.first() + originalMethod.removeInstruction(getModulesIndex) + originalMethod.addInstructions( + getModulesIndex, + """ + invoke-direct {p0}, $className->$helperMethodName()$returnType + move-result-object v0 + """, + ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/Fingerprints.kt index 16ad17c4b..0db287d75 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/Fingerprints.kt @@ -1,13 +1,12 @@ package app.revanced.patches.strava.upselling import app.revanced.patcher.definingClass -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.firstMethodComposite import app.revanced.patcher.name import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.getModulesMethod by gettingFirstMutableMethodDeclaratively { +internal val getModulesMethodMatch = firstMethodComposite { name("getModules") definingClass("/GenericLayoutEntry;"::endsWith) opcodes(Opcode.IGET_OBJECT) diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt index 41b96be49..d47d71767 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt @@ -1,10 +1,6 @@ package app.revanced.patches.tiktok.interaction.downloads -import app.revanced.patcher.extensions.addInstruction -import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.removeInstructions +import app.revanced.patcher.extensions.* import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch import app.revanced.patches.tiktok.misc.settings.settingsPatch @@ -75,7 +71,7 @@ val downloadsPatch = bytecodePatch( } } - settingsStatusLoadFingerprint.method.addInstruction( // TODO + settingsStatusLoadFingerprint.method.addInstruction( 0, "invoke-static {}, Lapp/revanced/extension/tiktok/settings/SettingsStatus;->enableDownload()V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt index 503cfe046..c447c2a59 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.tumblr.annoyances.popups -import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.returnEarly @Suppress("unused") val disableGiftMessagePopupPatch = bytecodePatch( @@ -11,6 +11,6 @@ val disableGiftMessagePopupPatch = bytecodePatch( compatibleWith("com.tumblr") apply { - showGiftMessagePopupMethod.addInstructions(0, "return-void") + showGiftMessagePopupMethod.returnEarly() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt index a54515c40..d37f78d4a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt @@ -28,7 +28,7 @@ val embeddedAdsPatch = bytecodePatch( ListPreference("revanced_block_embedded_ads"), ) - // Inject OkHttp3 application interceptor + // Inject OkHttp3 application interceptor. createsUsherClientMethod.addInstructions( 3, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt index 8e94d88b1..59534f0dc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt @@ -1,10 +1,10 @@ package app.revanced.patches.twitch.chat.autoclaim +import app.revanced.patcher.extensions.ExternalLabel import app.revanced.patcher.extensions.addInstructionsWithLabels import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patcher.extensions.ExternalLabel import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt index 2892cc50d..f3ead1743 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt @@ -33,8 +33,8 @@ val debugModePatch = bytecodePatch( isDebugConfigEnabledMethod, isOmVerificationEnabledMethod, shouldShowDebugOptionsMethod, - ).forEach { fingerprint -> - fingerprint.addInstructions( + ).forEach { method -> + method.addInstructions( 0, """ invoke-static {}, Lapp/revanced/extension/twitch/patches/DebugModePatch;->isDebugModeEnabled()Z