diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt index d5d4c0508..ea9234675 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt @@ -1,8 +1,11 @@ package app.revanced.patches.instagram.feed +import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.firstMutableMethodDeclaratively +import app.revanced.patcher.immutableClassDef import app.revanced.patcher.name import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch @@ -32,10 +35,9 @@ val `Limit feed to followed profiles` by creatingBytecodePatch( mainFeedHeaderMapFinderMethod.apply { mainFeedRequestHeaderFieldName = indexOfFirstInstructionOrThrow { - getReference().let { ref -> - ref?.type == "Ljava/util/Map;" && - ref.definingClass == mainFeedRequestClassMethod.immutableClassDef.toString() - } + val reference = fieldReference + reference?.type == "Ljava/util/Map;" && + reference.definingClass == mainFeedRequestClassMethod.classDef.type }.let { instructionIndex -> getInstruction(instructionIndex).getReference()!!.name } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt index 7cb165095..508f984a1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatch.kt @@ -22,14 +22,14 @@ val `Enable developer menu` by creatingBytecodePatch( clearNotificationReceiverMethodMatch.let { val stringIndex = it.indices.first() - it.method.indexOfFirstInstructionReversedOrThrow(stringIndex) { + it.immutableMethod.indexOfFirstInstructionReversedOrThrow(stringIndex) { val reference = methodReference opcode in listOf(Opcode.INVOKE_STATIC, Opcode.INVOKE_STATIC_RANGE) && reference?.parameterTypes?.size == 1 && reference.parameterTypes.first() == "Lcom/instagram/common/session/UserSession;" && reference.returnType == "Z" }.let { index -> - navigate(it.method).to(index).stop().returnEarly(true) + navigate(it.immutableMethod).to(index).stop().returnEarly(true) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/Fingerprints.kt index fac001fad..9264dd37a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/Fingerprints.kt @@ -1,13 +1,9 @@ package app.revanced.patches.mifitness.misc.locale -import app.revanced.patcher.definingClass -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively -import app.revanced.patcher.name -import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext +import app.revanced.patcher.* import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.syncBluetoothLanguageMethod by gettingFirstMutableMethodDeclaratively { +internal val syncBluetoothLanguageMethodMatch = firstMethodComposite { name("syncBluetoothLanguage") definingClass("Lcom/xiaomi/fitness/devicesettings/DeviceSettingsSyncer") opcodes(Opcode.MOVE_RESULT_OBJECT) diff --git a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt index 3aaed8bf8..0c77028ae 100644 --- a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt @@ -15,11 +15,11 @@ val `Force English locale` by creatingBytecodePatch( dependsOn(`Fix login`) apply { - syncBluetoothLanguageMethod.apply { - val resolvePhoneLocaleInstruction = syncBluetoothLanguageMethod.instructionMatches.first().index // TODO - val registerIndexToUpdate = getInstruction(resolvePhoneLocaleInstruction).registerA + syncBluetoothLanguageMethodMatch.let { + val resolvePhoneLocaleInstruction = it.indices.first() + val registerIndexToUpdate = it.method.getInstruction(resolvePhoneLocaleInstruction).registerA - replaceInstruction( + it.method.replaceInstruction( resolvePhoneLocaleInstruction, "const-string v$registerIndexToUpdate, \"en_gb\"", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/Fingerprints.kt index a3f204d91..41573b7e5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/Fingerprints.kt @@ -1,15 +1,15 @@ package app.revanced.patches.music.ad.video -import app.revanced.patcher.gettingFirstMethodDeclaratively +import app.revanced.patcher.firstMethodComposite import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.showVideoAdsParentMethod by gettingFirstMethodDeclaratively { +internal val showVideoAdsParentMethodMatch = firstMethodComposite( + "maybeRegenerateCpnAndStatsClient called unexpectedly, but no error.", +) { opcodes( Opcode.MOVE_RESULT_OBJECT, Opcode.INVOKE_VIRTUAL, Opcode.IGET_OBJECT, ) - strings("maybeRegenerateCpnAndStatsClient called unexpectedly, but no error.") } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt index 5621023b4..1110669e8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt @@ -35,8 +35,8 @@ val `Hide music video ads` by creatingBytecodePatch( SwitchPreference("revanced_music_hide_video_ads"), ) - navigate(showVideoAdsParentMethod.immutableMethod) - .to(showVideoAdsParentMethod.instructionMatches.first().index + 1) + navigate(showVideoAdsParentMethodMatch.immutableMethod) + .to(showVideoAdsParentMethodMatch.indices.first() + 1) .stop() .addInstructions( 0, diff --git a/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/Fingerprints.kt index dacca3d29..2a805c386 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/Fingerprints.kt @@ -1,7 +1,7 @@ package app.revanced.patches.music.audio.exclusiveaudio import app.revanced.patcher.accessFlags -import app.revanced.patcher.gettingFirstMethodDeclaratively +import app.revanced.patcher.gettingFirstMutableMethodDeclaratively import app.revanced.patcher.opcodes import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext @@ -9,7 +9,7 @@ import app.revanced.patcher.returnType import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.allowExclusiveAudioPlaybackMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.allowExclusiveAudioPlaybackMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Z") parameterTypes() diff --git a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/Fingerprints.kt index 759d0f0f9..b5dfe5703 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/Fingerprints.kt @@ -1,11 +1,10 @@ package app.revanced.patches.music.interaction.permanentrepeat import app.revanced.patcher.* -import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.repeatTrackMethod by gettingFirstMutableMethodDeclaratively("w_st") { +internal val repeatTrackMethodMatch = firstMethodComposite("w_st") { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes("L", "L") diff --git a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt index d1e3a5536..b08f7ce69 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt @@ -38,10 +38,10 @@ val `Permanent repeat` by creatingBytecodePatch( SwitchPreference("revanced_music_play_permanent_repeat"), ) - val startIndex = repeatTrackMethod.indices.last() // TODO - val repeatIndex = startIndex + 1 + repeatTrackMethodMatch.method.apply { + val startIndex = repeatTrackMethodMatch.indices.last() + val repeatIndex = startIndex + 1 - repeatTrackMethod.apply { // Start index is at a branch, but the same // register is clobbered in both branch paths. val freeRegister = findFreeRegister(startIndex + 1) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/Fingerprints.kt index e24bc7807..ca113c236 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/Fingerprints.kt @@ -1,20 +1,9 @@ package app.revanced.patches.music.layout.buttons -import app.revanced.patcher.accessFlags -import app.revanced.patcher.custom -import app.revanced.patcher.definingClass +import app.revanced.patcher.* import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively -import app.revanced.patcher.immutableClassDef -import app.revanced.patcher.instructions -import app.revanced.patcher.invoke -import app.revanced.patcher.literal -import app.revanced.patcher.matchIndexed -import app.revanced.patcher.opcodes -import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType -import app.revanced.patcher.unorderedAllOf +import app.revanced.util.literal import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -26,12 +15,10 @@ internal val BytecodePatchContext.mediaRouteButtonMethod by gettingFirstMutableM internal val BytecodePatchContext.playerOverlayChipMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("L") - custom { - instructions { literal { playerOverlayChip() } } - } + instructions(playerOverlayChip()) } -internal val BytecodePatchContext.historyMenuItemMethod by gettingFirstMutableMethodDeclaratively { +internal val historyMenuItemMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes("Landroid/view/Menu;") @@ -39,13 +26,13 @@ internal val BytecodePatchContext.historyMenuItemMethod by gettingFirstMutableMe Opcode.INVOKE_INTERFACE, Opcode.RETURN_VOID, ) - historyMenuItem() + literal { historyMenuItem } custom { - immutableClassDef.methods.count() == 5 // TODO CONFIRM + immutableClassDef.methods.count() == 5 } } -internal val BytecodePatchContext.historyMenuItemOfflineTabMethod by gettingFirstMutableMethodDeclaratively { +internal val historyMenuItemOfflineTabMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes("Landroid/view/Menu;") @@ -63,12 +50,12 @@ internal val BytecodePatchContext.searchActionViewMethod by gettingFirstMutableM accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Landroid/view/View;") parameterTypes() - searchButton() + literal { searchButton } } internal val BytecodePatchContext.topBarMenuItemImageViewMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Landroid/view/View;") parameterTypes() - topBarMenuItemImageView() + literal { topBarMenuItemImageView } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/HideButtons.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/HideButtons.kt index 9d81bc6e0..718cf5e03 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/HideButtons.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/buttons/HideButtons.kt @@ -3,6 +3,8 @@ package app.revanced.patches.music.layout.buttons import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.firstMutableMethod +import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -67,11 +69,11 @@ val `Hide buttons` by creatingBytecodePatch( // Region for hide history button in the top bar. arrayOf( - historyMenuItemFingerprint, - historyMenuItemOfflineTabFingerprint, - ).forEach { fingerprint -> - fingerprint.method.apply { - val targetIndex = fingerprint.patternMatch.startIndex + historyMenuItemMethodMatch, + historyMenuItemOfflineTabMethodMatch, + ).forEach { match -> + match.method.apply { + val targetIndex = match.indices.first() val targetRegister = getInstruction(targetIndex).registerD addInstructions( @@ -86,11 +88,11 @@ val `Hide buttons` by creatingBytecodePatch( // Region for hide cast, search and notification buttons in the top bar. arrayOf( - Triple(playerOverlayChipFingerprint, playerOverlayChip, "hideCastButton"), - Triple(searchActionViewFingerprint, searchButton, "hideSearchButton"), - Triple(topBarMenuItemImageViewFingerprint, topBarMenuItemImageView, "hideNotificationButton"), - ).forEach { (fingerprint, resourceIdLiteral, methodName) -> - fingerprint.method.apply { + Triple(playerOverlayChipMethod, playerOverlayChip, "hideCastButton"), + Triple(searchActionViewMethod, searchButton, "hideSearchButton"), + Triple(topBarMenuItemImageViewMethod, topBarMenuItemImageView, "hideNotificationButton"), + ).forEach { (method, resourceIdLiteral, methodName) -> + method.apply { val resourceIndex = indexOfFirstLiteralInstructionOrThrow(resourceIdLiteral) val targetIndex = indexOfFirstInstructionOrThrow( resourceIndex, @@ -107,8 +109,8 @@ val `Hide buttons` by creatingBytecodePatch( } // Region for hide cast button in the player. - mediaRouteButtonFingerprint.classDef.methods.single { method -> - method.name == "setVisibility" + mediaRouteButtonMethod.immutableClassDef.firstMutableMethod { + name == "setVisibility" }.addInstructions( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/Fingerprints.kt index 8efd5b064..9d7fe75ca 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/Fingerprints.kt @@ -1,13 +1,10 @@ package app.revanced.patches.music.layout.compactheader -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.opcodes -import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType +import app.revanced.patcher.* import app.revanced.util.literal import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.chipCloudMethod by gettingFirstMethodDeclaratively { +internal val chipCloudMethodMatch = firstMethodComposite { returnType("V") opcodes( Opcode.CONST, diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt index 2cc3006f1..467f29b91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt @@ -43,11 +43,11 @@ val `Hide category bar` by creatingBytecodePatch( chipCloud = ResourceType.LAYOUT["chip_cloud"] - chipCloudMethod.apply { - val targetIndex = chipCloudMethod.patternMatch.endIndex - val targetRegister = getInstruction(targetIndex).registerA + chipCloudMethodMatch.let { + val targetIndex = it.indices.last() + val targetRegister = it.method.getInstruction(targetIndex).registerA - addInstruction( + it.method.addInstruction( targetIndex + 1, "invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR->hideCategoryBar(Landroid/view/View;)V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt index c272a7bad..b2bfd39c9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt @@ -2,8 +2,12 @@ package app.revanced.patches.music.layout.miniplayercolor +import app.revanced.patcher.accessFlags import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.firstMutableMethodDeclaratively +import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.creatingBytecodePatch +import app.revanced.patcher.returnType import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.patches.music.misc.extension.sharedExtensionPatch @@ -45,8 +49,8 @@ val `Change miniplayer color` by creatingBytecodePatch( SwitchPreference("revanced_music_change_miniplayer_color"), ) - switchToggleColorMethod.match(miniPlayerConstructorMethod.classDef).let { - val relativeIndex = it.patternMatch.endIndex + 1 + switchToggleColorMethodMatch.match(miniPlayerConstructorMethodMatch.immutableClassDef).let { + val relativeIndex = it.indices.last() + 1 val invokeVirtualIndex = it.method.indexOfFirstInstructionOrThrow( relativeIndex, @@ -62,20 +66,24 @@ val `Change miniplayer color` by creatingBytecodePatch( val colorMathPlayerIGetReference = it.method .getInstruction(iGetIndex).reference as FieldReference - val colorGreyIndex = miniPlayerConstructorMethod.indexOfFirstInstructionReversedOrThrow { - getReference()?.name == "getColor" - } - val iPutIndex = miniPlayerConstructorMethod.indexOfFirstInstructionOrThrow( + val colorGreyIndex = + miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionReversedOrThrow { + getReference()?.name == "getColor" + } + val iPutIndex = miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionOrThrow( colorGreyIndex, Opcode.IPUT, ) - val colorMathPlayerIPutReference = miniPlayerConstructorMethod + val colorMathPlayerIPutReference = miniPlayerConstructorMethodMatch.immutableMethod .getInstruction(iPutIndex).reference - miniPlayerConstructorMethod.classDef.methods.single { method -> - method.accessFlags == AccessFlags.PUBLIC.value or AccessFlags.FINAL.value && - method.returnType == "V" && - method.parameters == it.immutableMethod.parameters + miniPlayerConstructorMethodMatch.immutableClassDef.firstMutableMethodDeclaratively { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returnType("V") + parameterTypes( + parameterTypePrefixes = it.method.parameterTypes.map { type -> type.toString() } + .toTypedArray(), + ) }.apply { val insertIndex = indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT) val freeRegister = findFreeRegister(insertIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/Fingerprints.kt index 3afcdb610..95d32778a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/Fingerprints.kt @@ -1,28 +1,24 @@ package app.revanced.patches.music.layout.miniplayercolor -import app.revanced.patcher.accessFlags -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.instructions -import app.revanced.patcher.opcodes -import app.revanced.patcher.parameterTypes +import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType import app.revanced.patches.shared.misc.mapping.ResourceType import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.ClassDef -internal val BytecodePatchContext.miniPlayerConstructorMethod by gettingFirstMethodDeclaratively { +internal val miniPlayerConstructorMethodMatch = firstMethodComposite { returnType("V") instructions( ResourceType.ID("mpp_player_bottom_sheet"), + "sharedToggleMenuItemMutations"(), ) - strings("sharedToggleMenuItemMutations") } /** - * Matches to the class found in [miniPlayerConstructorMethod]. + * Matches to the class found in [miniPlayerConstructorMethodMatch]. */ -internal val BytecodePatchContext.switchToggleColorMethod by gettingFirstMethodDeclaratively { +internal val switchToggleColorMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL) returnType("V") parameterTypes("L", "J") diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/Fingerprints.kt index 41c0db9d6..de0949c06 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/Fingerprints.kt @@ -1,11 +1,6 @@ package app.revanced.patches.music.layout.navigationbar -import app.revanced.patcher.accessFlags -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.opcodes -import app.revanced.patcher.parameterTypes -import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType +import app.revanced.patcher.* import app.revanced.util.containsLiteralInstruction import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction @@ -14,7 +9,7 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.reference.MethodReference -internal val BytecodePatchContext.tabLayoutTextMethod by gettingFirstMethodDeclaratively { +internal val tabLayoutTextMethodMatch = firstMethodComposite("FEmusic_search") { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes("L") @@ -27,10 +22,9 @@ internal val BytecodePatchContext.tabLayoutTextMethod by gettingFirstMethodDecla Opcode.INVOKE_INTERFACE, Opcode.MOVE_RESULT, ) - strings("FEmusic_search") - custom { method, _ -> - method.containsLiteralInstruction(text1) && - indexOfGetVisibilityInstruction(method) >= 0 + custom { + containsLiteralInstruction(text1) && + indexOfGetVisibilityInstruction(this) >= 0 } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/NavigationBarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/NavigationBarPatch.kt index 39764bf88..a89694577 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/NavigationBarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/navigationbar/NavigationBarPatch.kt @@ -82,7 +82,7 @@ val `Navigation bar` by creatingBytecodePatch( ), ) - tabLayoutTextMethod.apply { + tabLayoutTextMethodMatch.method.apply { // Hide navigation labels. val constIndex = indexOfFirstLiteralInstructionOrThrow(text1) val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST) @@ -99,7 +99,7 @@ val `Navigation bar` by creatingBytecodePatch( ) // Set navigation enum and hide navigation buttons. - val enumIndex = tabLayoutTextMethod.patternMatch.startIndex + 3 + val enumIndex = tabLayoutTextMethodMatch.indices.first() + 3 val enumRegister = getInstruction(enumIndex).registerA val insertEnumIndex = indexOfFirstInstructionOrThrow(Opcode.AND_INT_LIT8) - 2 diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/Fingerprints.kt index 40673bebb..d5ae2ae65 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/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.hideGetPremiumMethod by gettingFirstMutableMethodDeclaratively( +internal val hideGetPremiumMethodMatch = firstMethodComposite( "FEmusic_history", "FEmusic_offline" ) { diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt index f07e8a71b..f297e5002 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt @@ -39,23 +39,25 @@ val `Hide 'Get Music Premium'` by creatingBytecodePatch( SwitchPreference("revanced_music_hide_get_premium_label"), ) - hideGetPremiumMethod.apply { - val insertIndex = hideGetPremiumMethod.indices.last() // TODO + hideGetPremiumMethodMatch.let { + val insertIndex = it.indices.last() - val setVisibilityInstruction = getInstruction(insertIndex) - val getPremiumViewRegister = setVisibilityInstruction.registerC - val visibilityRegister = setVisibilityInstruction.registerD + it.method.apply { + val setVisibilityInstruction = getInstruction(insertIndex) + val getPremiumViewRegister = setVisibilityInstruction.registerC + val visibilityRegister = setVisibilityInstruction.registerD - replaceInstruction( - insertIndex, - "const/16 v$visibilityRegister, 0x8", - ) + replaceInstruction( + insertIndex, + "const/16 v$visibilityRegister, 0x8", + ) - addInstruction( - insertIndex + 1, - "invoke-virtual {v$getPremiumViewRegister, v$visibilityRegister}, " + - "Landroid/view/View;->setVisibility(I)V", - ) + addInstruction( + insertIndex + 1, + "invoke-virtual {v$getPremiumViewRegister, v$visibilityRegister}, " + + "Landroid/view/View;->setVisibility(I)V", + ) + } } membershipSettingsMethod.addInstructionsWithLabels( diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/extension/hooks/ApplicationInitHook.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/extension/hooks/ApplicationInitHook.kt index 194f13422..2fefbb783 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/extension/hooks/ApplicationInitHook.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/extension/hooks/ApplicationInitHook.kt @@ -1,5 +1,7 @@ package app.revanced.patches.music.misc.extension.hooks +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke import app.revanced.patcher.name import app.revanced.patcher.parameterTypes import app.revanced.patcher.returnType @@ -11,7 +13,7 @@ internal val applicationInitHook = extensionHook { name("onCreate") returnType("V") parameterTypes() - strings("activity") + instructions("activity"()) } internal val applicationInitOnCreateHook = activityOnCreateExtensionHook(YOUTUBE_MUSIC_MAIN_ACTIVITY_CLASS_TYPE) diff --git a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/Fingerprints.kt index 5e5902dd7..0ecc20d44 100644 --- a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/Fingerprints.kt @@ -1,12 +1,10 @@ package app.revanced.patches.protonvpn.splittunneling -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively -import app.revanced.patcher.name -import app.revanced.patcher.opcodes +import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.enableSplitTunnelingUiMethod by gettingFirstMutableMethodDeclaratively("currentModeAppNames") { +internal val enableSplitTunnelingUiMethodMatch = firstMethodComposite("currentModeAppNames") { opcodes( Opcode.MOVE_OBJECT, Opcode.MOVE_FROM16, 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 22f7ffafd..8bfc0f302 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 @@ -14,11 +14,10 @@ val `Unlock split tunneling` by creatingBytecodePatch { compatibleWith("ch.protonvpn.android") apply { - val registerIndex = enableSplitTunnelingUiMethod.patternMatch!!.endIndex - 1 // TODO - - enableSplitTunnelingUiMethod.apply { - val register = getInstruction(registerIndex).registerA - replaceInstruction(registerIndex, "const/4 v$register, 0x0") + enableSplitTunnelingUiMethodMatch.let { + val registerIndex = it.indices.last() - 1 + val register = it.method.getInstruction(registerIndex).registerA + it.method.replaceInstruction(registerIndex, "const/4 v$register, 0x0") } initializeSplitTunnelingSettingsUIMethod.apply { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt index 03e83fa8a..318dda2c2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt @@ -69,11 +69,11 @@ val `Open Shorts in regular player` by creatingBytecodePatch( // Find the obfuscated method name for PlaybackStartDescriptor.videoId() val (videoIdStartMethod, videoIdIndex) = if (is_20_39_or_greater) { watchPanelVideoIdMethodMatch.let { - it.method to it.indices.last() + it.immutableMethod to it.indices.last() } } else { playbackStartFeatureFlagMethodMatch.let { - it.method to it.indices.first() + it.immutableMethod to it.indices.first() } } val playbackStartVideoIdMethodName = navigate(videoIdStartMethod).to(videoIdIndex).stop().name