refactor(Utils): appropriate message is displayed in the exception when the index is not found

This commit is contained in:
inotia00 2024-06-22 19:52:46 +09:00
parent 27c40de516
commit e1f3da76c4
65 changed files with 407 additions and 338 deletions

View File

@ -14,8 +14,8 @@ import app.revanced.patches.music.utils.integrations.Constants.ACCOUNT_CLASS_DES
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -43,8 +43,8 @@ object AccountComponentsPatch : BaseBytecodePatch(
MenuEntryFingerprint.resultOrThrow().let { MenuEntryFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val textIndex = getTargetIndexWithMethodReferenceName("setText") val textIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val viewIndex = getTargetIndexWithMethodReferenceName("addView") val viewIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val textRegister = getInstruction<FiveRegisterInstruction>(textIndex).registerD val textRegister = getInstruction<FiveRegisterInstruction>(textIndex).registerD
val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD
@ -64,9 +64,9 @@ object AccountComponentsPatch : BaseBytecodePatch(
AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { result -> AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply { result.mutableMethod.apply {
val textColorIndex = getTargetIndexWithMethodReferenceName("setTextColor") val textColorIndex = getTargetIndexWithMethodReferenceNameOrThrow("setTextColor")
val setVisibilityIndex = val setVisibilityIndex =
getTargetIndexWithMethodReferenceName(textColorIndex, "setVisibility") getTargetIndexWithMethodReferenceNameOrThrow(textColorIndex, "setVisibility")
val textViewInstruction = val textViewInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex) getInstruction<FiveRegisterInstruction>(setVisibilityIndex)
@ -99,7 +99,7 @@ object AccountComponentsPatch : BaseBytecodePatch(
TermsOfServiceFingerprint.resultOrThrow().let { TermsOfServiceFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = val insertIndex =
getTargetIndexWithReference("/PrivacyTosFooter;->setVisibility(I)V") getTargetIndexWithReferenceOrThrow("/PrivacyTosFooter;->setVisibility(I)V")
val visibilityRegister = val visibilityRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerD getInstruction<FiveRegisterInstruction>(insertIndex).registerD

View File

@ -15,10 +15,10 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.LikeDis
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -48,7 +48,7 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
// hook download button // hook download button
val addViewIndex = getTargetIndexWithMethodReferenceName("addView") val addViewIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val addViewRegister = val addViewRegister =
getInstruction<FiveRegisterInstruction>(addViewIndex).registerD getInstruction<FiveRegisterInstruction>(addViewIndex).registerD
@ -58,13 +58,13 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
) )
// hide action button label // hide action button label
val noLabelIndex = indexOfFirstInstruction { val noLabelIndex = indexOfFirstInstructionOrThrow {
val reference = (this as? ReferenceInstruction)?.reference.toString() val reference = (this as? ReferenceInstruction)?.reference.toString()
opcode == Opcode.INVOKE_DIRECT opcode == Opcode.INVOKE_DIRECT
&& reference.endsWith("<init>(Landroid/content/Context;)V") && reference.endsWith("<init>(Landroid/content/Context;)V")
&& !reference.contains("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;") && !reference.contains("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;")
} - 2 } - 2
val replaceIndex = indexOfFirstInstruction { val replaceIndex = indexOfFirstInstructionOrThrow {
val reference = (this as? ReferenceInstruction)?.reference.toString() val reference = (this as? ReferenceInstruction)?.reference.toString()
opcode == Opcode.INVOKE_DIRECT opcode == Opcode.INVOKE_DIRECT
&& reference.endsWith("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;-><init>(Landroid/content/Context;)V") && reference.endsWith("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;-><init>(Landroid/content/Context;)V")
@ -83,10 +83,10 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
removeInstruction(replaceIndex) removeInstruction(replaceIndex)
// hide action button // hide action button
val hasNextIndex = getTargetIndexWithMethodReferenceName("hasNext") val hasNextIndex = getTargetIndexWithMethodReferenceNameOrThrow("hasNext")
val freeRegister = min(implementation!!.registerCount - parameters.size - 2, 15) val freeRegister = min(implementation!!.registerCount - parameters.size - 2, 15)
val spannedIndex = getTargetIndexWithReference(")Landroid/text/Spanned;") val spannedIndex = getTargetIndexWithReferenceOrThrow(")Landroid/text/Spanned;")
val spannedRegister = val spannedRegister =
getInstruction<FiveRegisterInstruction>(spannedIndex).registerC getInstruction<FiveRegisterInstruction>(spannedIndex).registerC
val spannedReference = getInstruction<ReferenceInstruction>(spannedIndex).reference val spannedReference = getInstruction<ReferenceInstruction>(spannedIndex).reference

View File

@ -25,8 +25,8 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.Interst
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -139,15 +139,15 @@ object AdsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.PrivacyTosFooter) getWideLiteralInstructionIndex(SharedResourceIdPatch.PrivacyTosFooter)
val walkerIndex = getTargetIndex(constIndex + 2, Opcode.INVOKE_VIRTUAL) val walkerIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL)
val viewIndex = getTargetIndex(constIndex, Opcode.IGET_OBJECT) val viewIndex = getTargetIndexOrThrow(constIndex, Opcode.IGET_OBJECT)
val viewReference = val viewReference =
getInstruction<ReferenceInstruction>(viewIndex).reference.toString() getInstruction<ReferenceInstruction>(viewIndex).reference.toString()
val walkerMethod = getWalkerMethod(context, walkerIndex) val walkerMethod = getWalkerMethod(context, walkerIndex)
walkerMethod.apply { walkerMethod.apply {
val insertIndex = getTargetIndexWithReference(viewReference) val insertIndex = getTargetIndexWithReferenceOrThrow(viewReference)
val nullCheckIndex = getTargetIndex(insertIndex - 1, Opcode.IF_NEZ) val nullCheckIndex = getTargetIndexOrThrow(insertIndex - 1, Opcode.IF_NEZ)
val nullCheckRegister = val nullCheckRegister =
getInstruction<OneRegisterInstruction>(nullCheckIndex).registerA getInstruction<OneRegisterInstruction>(nullCheckIndex).registerA

View File

@ -25,11 +25,11 @@ import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -98,7 +98,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
val constIndex = val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.TrimSilenceSwitch) getWideLiteralInstructionIndex(SharedResourceIdPatch.TrimSilenceSwitch)
val onCheckedChangedListenerIndex = val onCheckedChangedListenerIndex =
getTargetIndex(constIndex, Opcode.INVOKE_DIRECT) getTargetIndexOrThrow(constIndex, Opcode.INVOKE_DIRECT)
val onCheckedChangedListenerReference = val onCheckedChangedListenerReference =
getInstruction<ReferenceInstruction>(onCheckedChangedListenerIndex).reference getInstruction<ReferenceInstruction>(onCheckedChangedListenerIndex).reference
val onCheckedChangedListenerDefiningClass = val onCheckedChangedListenerDefiningClass =
@ -108,7 +108,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
onCheckedChangedListenerClass.methods.find { method -> method.name == "onCheckedChanged" } onCheckedChangedListenerClass.methods.find { method -> method.name == "onCheckedChanged" }
?.apply { ?.apply {
val walkerIndex = indexOfFirstInstruction { val walkerIndex = indexOfFirstInstructionOrThrow {
val reference = val reference =
((this as? ReferenceInstruction)?.reference as? MethodReference) ((this as? ReferenceInstruction)?.reference as? MethodReference)
@ -118,7 +118,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
&& reference.parameterTypes[0] == "Z" && reference.parameterTypes[0] == "Z"
} }
getWalkerMethod(context, walkerIndex).apply { getWalkerMethod(context, walkerIndex).apply {
val insertIndex = getTargetIndex(Opcode.MOVE_RESULT) val insertIndex = getTargetIndexOrThrow(Opcode.MOVE_RESULT)
val insertRegister = val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA getInstruction<OneRegisterInstruction>(insertIndex).registerA
@ -142,7 +142,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
MenuItemFingerprint.resultOrThrow().let { MenuItemFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val freeIndex = getTargetIndex(Opcode.OR_INT_LIT16) val freeIndex = getTargetIndexOrThrow(Opcode.OR_INT_LIT16)
val textViewIndex = it.scanResult.patternScanResult!!.startIndex val textViewIndex = it.scanResult.patternScanResult!!.startIndex
val imageViewIndex = it.scanResult.patternScanResult!!.endIndex val imageViewIndex = it.scanResult.patternScanResult!!.endIndex
@ -153,7 +153,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
val imageViewRegister = val imageViewRegister =
getInstruction<OneRegisterInstruction>(imageViewIndex).registerA getInstruction<OneRegisterInstruction>(imageViewIndex).registerA
val enumIndex = indexOfFirstInstruction { val enumIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_STATIC opcode == Opcode.INVOKE_STATIC
&& (this as? ReferenceInstruction)?.reference.toString() && (this as? ReferenceInstruction)?.reference.toString()
.contains("(I)L") .contains("(I)L")
@ -176,7 +176,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
TouchOutsideFingerprint.resultOrThrow().let { TouchOutsideFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val setOnClickListenerIndex = val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceName("setOnClickListener") getTargetIndexWithMethodReferenceNameOrThrow("setOnClickListener")
val setOnClickListenerRegister = val setOnClickListenerRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC
@ -190,7 +190,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
EndButtonsContainerFingerprint.resultOrThrow().let { EndButtonsContainerFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(EndButtonsContainer) val startIndex = getWideLiteralInstructionIndex(EndButtonsContainer)
val targetIndex = getTargetIndex(startIndex, Opcode.MOVE_RESULT_OBJECT) val targetIndex = getTargetIndexOrThrow(startIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -33,8 +33,8 @@ import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml import app.revanced.patches.shared.voicesearch.VoiceSearchUtils.patchXml
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -186,7 +186,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
if (SettingsPatch.upward0642) { if (SettingsPatch.upward0642) {
TopBarMenuItemImageViewFingerprint.resultOrThrow().mutableMethod.apply { TopBarMenuItemImageViewFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(TopBarMenuItemImageView) val constIndex = getWideLiteralInstructionIndex(TopBarMenuItemImageView)
val targetIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT) val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(
@ -237,7 +237,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
parentResult.mutableMethod.apply { parentResult.mutableMethod.apply {
val constIndex = val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.MusicTasteBuilderShelf) getWideLiteralInstructionIndex(SharedResourceIdPatch.MusicTasteBuilderShelf)
val targetIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT) val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(
@ -284,7 +284,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
) )
SearchBarFingerprint.resultOrThrow().let { SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val setVisibilityIndex = getTargetIndexWithMethodReferenceName("setVisibility") val setVisibilityIndex = getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityInstruction = val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex) getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

View File

@ -9,7 +9,7 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -28,7 +28,7 @@ object OldStyleLibraryShelfPatch : BaseBytecodePatch(
BrowseIdFingerprint.resultOrThrow().let { BrowseIdFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val stringIndex = getStringInstructionIndex("FEmusic_offline") val stringIndex = getStringInstructionIndex("FEmusic_offline")
val targetIndex = getTargetIndexReversed(stringIndex, Opcode.IGET_OBJECT) val targetIndex = getTargetIndexReversedOrThrow(stringIndex, Opcode.IGET_OBJECT)
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
addInstructions( addInstructions(

View File

@ -12,10 +12,10 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -42,15 +42,15 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
PendingIntentReceiverFingerprint.resultOrThrow().let { PendingIntentReceiverFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = getStringInstructionIndex("YTM Dislike") val startIndex = getStringInstructionIndex("YTM Dislike")
val onClickRelayIndex = getTargetIndexReversed(startIndex, Opcode.INVOKE_VIRTUAL) val onClickRelayIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickRelayMethod = getWalkerMethod(context, onClickRelayIndex) val onClickRelayMethod = getWalkerMethod(context, onClickRelayIndex)
onClickRelayMethod.apply { onClickRelayMethod.apply {
val onClickMethodIndex = getTargetIndexReversed(Opcode.INVOKE_DIRECT) val onClickMethodIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_DIRECT)
val onClickMethod = getWalkerMethod(context, onClickMethodIndex) val onClickMethod = getWalkerMethod(context, onClickMethodIndex)
onClickMethod.apply { onClickMethod.apply {
val onClickIndex = indexOfFirstInstruction { val onClickIndex = indexOfFirstInstructionOrThrow {
val reference = val reference =
((this as? ReferenceInstruction)?.reference as? MethodReference) ((this as? ReferenceInstruction)?.reference as? MethodReference)
@ -69,7 +69,7 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
DislikeButtonOnClickListenerFingerprint.resultOrThrow().let { DislikeButtonOnClickListenerFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val onClickIndex = getTargetIndexWithReference(onClickReference.toString()) val onClickIndex = getTargetIndexWithReferenceOrThrow(onClickReference.toString())
injectCall(onClickIndex) injectCall(onClickIndex)
} }
} }
@ -83,7 +83,7 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
} }
private fun MutableMethod.injectCall(onClickIndex: Int) { private fun MutableMethod.injectCall(onClickIndex: Int) {
val targetIndex = getTargetIndexReversed(onClickIndex, Opcode.IF_EQZ) val targetIndex = getTargetIndexReversedOrThrow(onClickIndex, Opcode.IF_EQZ)
val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructionsWithLabels( addInstructionsWithLabels(

View File

@ -12,8 +12,8 @@ import app.revanced.patches.music.utils.integrations.Constants.NAVIGATION_CLASS_
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -64,7 +64,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
TabLayoutTextFingerprint.resultOrThrow().let { TabLayoutTextFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(SharedResourceIdPatch.Text1) val constIndex = getWideLiteralInstructionIndex(SharedResourceIdPatch.Text1)
val targetIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
@ -98,9 +98,9 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3 val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
val insertEnumIndex = getTargetIndex(Opcode.AND_INT_LIT8) - 2 val insertEnumIndex = getTargetIndexOrThrow(Opcode.AND_INT_LIT8) - 2
val pivotTabIndex = getTargetIndexWithMethodReferenceName("getVisibility") val pivotTabIndex = getTargetIndexWithMethodReferenceNameOrThrow("getVisibility")
val pivotTabRegister = getInstruction<Instruction35c>(pivotTabIndex).registerC val pivotTabRegister = getInstruction<Instruction35c>(pivotTabIndex).registerC
addInstruction( addInstruction(

View File

@ -51,9 +51,9 @@ import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
@ -133,8 +133,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
colorMathPlayerMethodParameter = parameters colorMathPlayerMethodParameter = parameters
val relativeIndex = it.scanResult.patternScanResult!!.endIndex + 1 val relativeIndex = it.scanResult.patternScanResult!!.endIndex + 1
val invokeVirtualIndex = getTargetIndex(relativeIndex, Opcode.INVOKE_VIRTUAL) val invokeVirtualIndex = getTargetIndexOrThrow(relativeIndex, Opcode.INVOKE_VIRTUAL)
val iGetIndex = getTargetIndex(relativeIndex, Opcode.IGET) val iGetIndex = getTargetIndexOrThrow(relativeIndex, Opcode.IGET)
colorMathPlayerInvokeVirtualReference = colorMathPlayerInvokeVirtualReference =
getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference
@ -142,11 +142,11 @@ object PlayerComponentsPatch : BaseBytecodePatch(
getInstruction<ReferenceInstruction>(iGetIndex).reference getInstruction<ReferenceInstruction>(iGetIndex).reference
// black player background // black player background
val invokeDirectIndex = getTargetIndex(Opcode.INVOKE_DIRECT) val invokeDirectIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT)
val targetMethod = getWalkerMethod(context, invokeDirectIndex) val targetMethod = getWalkerMethod(context, invokeDirectIndex)
targetMethod.apply { targetMethod.apply {
val insertIndex = getTargetIndex(0, Opcode.IF_NE) val insertIndex = getTargetIndexOrThrow(0, Opcode.IF_NE)
addInstructions( addInstructions(
insertIndex, """ insertIndex, """
@ -161,7 +161,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
parentResult.mutableMethod.apply { parentResult.mutableMethod.apply {
val colorGreyIndex = getWideLiteralInstructionIndex(ColorGrey) val colorGreyIndex = getWideLiteralInstructionIndex(ColorGrey)
val iPutIndex = getTargetIndex(colorGreyIndex, Opcode.IPUT) val iPutIndex = getTargetIndexOrThrow(colorGreyIndex, Opcode.IPUT)
colorMathPlayerIPutReference = colorMathPlayerIPutReference =
getInstruction<ReferenceInstruction>(iPutIndex).reference getInstruction<ReferenceInstruction>(iPutIndex).reference
@ -175,10 +175,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
mutableMethod.apply { mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 3 val freeRegister = implementation!!.registerCount - parameters.size - 3
val invokeDirectIndex = getTargetIndexReversed( val invokeDirectIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_DIRECT)
implementation!!.instructions.size - 1,
Opcode.INVOKE_DIRECT
)
val invokeDirectReference = val invokeDirectReference =
getInstruction<ReferenceInstruction>(invokeDirectIndex).reference getInstruction<ReferenceInstruction>(invokeDirectIndex).reference
@ -339,9 +336,9 @@ object PlayerComponentsPatch : BaseBytecodePatch(
reversed: Boolean reversed: Boolean
): Reference { ): Reference {
val targetIndex = if (reversed) val targetIndex = if (reversed)
getTargetIndexReversed(swipeToDismissWidgetIndex, opcode) getTargetIndexReversedOrThrow(swipeToDismissWidgetIndex, opcode)
else else
getTargetIndex(swipeToDismissWidgetIndex, opcode) getTargetIndexOrThrow(swipeToDismissWidgetIndex, opcode)
return getInstruction<ReferenceInstruction>(targetIndex).reference return getInstruction<ReferenceInstruction>(targetIndex).reference
} }
@ -369,7 +366,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val stringIndex = val stringIndex =
getStringInstructionIndex("INTERACTION_LOGGING_GESTURE_TYPE_SWIPE") getStringInstructionIndex("INTERACTION_LOGGING_GESTURE_TYPE_SWIPE")
val sPutObjectIndex = getTargetIndex(stringIndex, Opcode.SPUT_OBJECT) val sPutObjectIndex = getTargetIndexOrThrow(stringIndex, Opcode.SPUT_OBJECT)
swipeToDismissSGetObjectReference = swipeToDismissSGetObjectReference =
getInstruction<ReferenceInstruction>(sPutObjectIndex).reference getInstruction<ReferenceInstruction>(sPutObjectIndex).reference
@ -407,7 +404,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
dismissBehaviorMethod.apply { dismissBehaviorMethod.apply {
val insertIndex = val insertIndex =
getTargetIndexWithFieldReferenceType("Ljava/util/concurrent/atomic/AtomicBoolean;") getTargetIndexWithFieldReferenceTypeOrThrow("Ljava/util/concurrent/atomic/AtomicBoolean;")
val primaryRegister = val primaryRegister =
getInstruction<TwoRegisterInstruction>(insertIndex).registerB getInstruction<TwoRegisterInstruction>(insertIndex).registerB
val secondaryRegister = primaryRegister + 1 val secondaryRegister = primaryRegister + 1
@ -530,7 +527,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
SwitchToggleColorFingerprint.resultOrThrow().let { SwitchToggleColorFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val invokeDirectIndex = getTargetIndex(Opcode.INVOKE_DIRECT) val invokeDirectIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT)
val walkerMethod = getWalkerMethod(context, invokeDirectIndex) val walkerMethod = getWalkerMethod(context, invokeDirectIndex)
walkerMethod.addInstructions( walkerMethod.addInstructions(
@ -563,7 +560,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
AudioVideoSwitchToggleFingerprint.resultOrThrow().mutableMethod.apply { AudioVideoSwitchToggleFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AudioVideoSwitchToggle) val constIndex = getWideLiteralInstructionIndex(AudioVideoSwitchToggle)
val viewIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT) val viewIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA
addInstruction( addInstruction(
@ -659,7 +656,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val startIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val endIndex = it.scanResult.patternScanResult!!.endIndex val endIndex = it.scanResult.patternScanResult!!.endIndex
val imageViewIndex = val imageViewIndex =
getTargetIndexWithFieldReferenceType("Landroid/widget/ImageView;") getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/widget/ImageView;")
val shuffleReference1 = getInstruction<ReferenceInstruction>(startIndex).reference val shuffleReference1 = getInstruction<ReferenceInstruction>(startIndex).reference
val shuffleReference2 = val shuffleReference2 =
@ -833,7 +830,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val miniPlayerPlayPauseReplayButtonRegister = val miniPlayerPlayPauseReplayButtonRegister =
getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA
val findViewByIdIndex = val findViewByIdIndex =
getTargetIndex(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL) getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL)
val parentViewRegister = val parentViewRegister =
getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC
@ -856,7 +853,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val constRegister = val constRegister =
getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA
val findViewByIdIndex = val findViewByIdIndex =
getTargetIndex(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL) getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL)
val findViewByIdRegister = val findViewByIdRegister =
getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC
@ -874,7 +871,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val miniPlayerPlayPauseReplayButtonIndex = val miniPlayerPlayPauseReplayButtonIndex =
getWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton) getWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
val invokeStaticIndex = val invokeStaticIndex =
getTargetIndex(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_STATIC) getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_STATIC)
val viewArrayRegister = getInstruction<FiveRegisterInstruction>(invokeStaticIndex).registerC val viewArrayRegister = getInstruction<FiveRegisterInstruction>(invokeStaticIndex).registerC
addInstructions( addInstructions(
@ -892,7 +889,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
fieldName: String fieldName: String
) { ) {
val startIndex = getStringInstructionIndex(intentString) val startIndex = getStringInstructionIndex(intentString)
val onClickIndex = getTargetIndexReversed(startIndex, Opcode.INVOKE_VIRTUAL) val onClickIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickReference = getInstruction<ReferenceInstruction>(onClickIndex).reference val onClickReference = getInstruction<ReferenceInstruction>(onClickIndex).reference
val onClickReferenceDefiningClass = (onClickReference as MethodReference).definingClass val onClickReferenceDefiningClass = (onClickReference as MethodReference).definingClass

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.layout.header.ChangeHeaderPatch import app.revanced.patches.music.layout.header.ChangeHeaderPatch
import app.revanced.patches.music.utils.fix.header.fingerprints.HeaderSwitchConfigFingerprint import app.revanced.patches.music.utils.fix.header.fingerprints.HeaderSwitchConfigFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -33,7 +33,7 @@ object RestoreOldHeaderPatch : BytecodePatch(
HeaderSwitchConfigFingerprint.result?.let { HeaderSwitchConfigFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = val targetIndex =
getTargetIndex(getWideLiteralInstructionIndex(45617851), Opcode.MOVE_RESULT) getTargetIndexOrThrow(getWideLiteralInstructionIndex(45617851), Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -13,7 +13,7 @@ import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.LikeFi
import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.RemoveLikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.RemoveLikeFingerprint
import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.TextComponentFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.TextComponentFingerprint
import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -53,7 +53,7 @@ object ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
TextComponentFingerprint.resultOrThrow().let { TextComponentFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = indexOfFirstInstruction { val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_STATIC opcode == Opcode.INVOKE_STATIC
&& (this as ReferenceInstruction).reference.toString() && (this as ReferenceInstruction).reference.toString()
.endsWith("Ljava/lang/CharSequence;") .endsWith("Ljava/lang/CharSequence;")

View File

@ -17,7 +17,7 @@ import app.revanced.patches.music.utils.settings.fingerprints.PreferenceFingerpr
import app.revanced.patches.music.utils.settings.fingerprints.SettingsHeadersFragmentFingerprint import app.revanced.patches.music.utils.settings.fingerprints.SettingsHeadersFragmentFingerprint
import app.revanced.patches.shared.fingerprints.SharedSettingFingerprint import app.revanced.patches.shared.fingerprints.SharedSettingFingerprint
import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -52,7 +52,7 @@ object SettingsBytecodePatch : BytecodePatch(
*/ */
SharedSettingFingerprint.resultOrThrow().let { SharedSettingFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val stringIndex = getTargetIndex(Opcode.CONST_STRING) val stringIndex = getTargetIndexOrThrow(Opcode.CONST_STRING)
val stringRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA val stringRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA
replaceInstruction( replaceInstruction(

View File

@ -14,8 +14,8 @@ import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackC
import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint
import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -70,7 +70,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Set seekbar thickness // Set seekbar thickness
val roundIndex = getTargetIndexWithMethodReferenceName("round") + 1 val roundIndex = getTargetIndexWithMethodReferenceNameOrThrow("round") + 1
val roundRegister = getInstruction<OneRegisterInstruction>(roundIndex).registerA val roundRegister = getInstruction<OneRegisterInstruction>(roundIndex).registerA
addInstruction( addInstruction(
roundIndex + 1, roundIndex + 1,
@ -79,7 +79,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Draw segment // Draw segment
val drawCircleIndex = getTargetIndexWithMethodReferenceNameReversed("drawCircle") val drawCircleIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("drawCircle")
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex) val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction( addInstruction(
drawCircleIndex, drawCircleIndex,
@ -114,7 +114,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Draw segment // Draw segment
val drawCircleIndex = getTargetIndexWithMethodReferenceName("drawCircle") val drawCircleIndex = getTargetIndexWithMethodReferenceNameOrThrow("drawCircle")
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex) val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction( addInstruction(
drawCircleIndex, drawCircleIndex,

View File

@ -23,8 +23,8 @@ import app.revanced.patches.music.video.information.fingerprints.VideoQualityLis
import app.revanced.patches.music.video.information.fingerprints.VideoQualityTextFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoQualityTextFingerprint
import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversed import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
@ -138,8 +138,8 @@ object VideoInformationPatch : BytecodePatch(
) )
VideoLengthFingerprint.resultOrThrow().let { VideoLengthFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val invalidateIndex = getTargetIndexWithMethodReferenceNameReversed("invalidate") val invalidateIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversed( val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversedOrThrow(
invalidateIndex + 1, invalidateIndex + 1,
"Landroid/graphics/Rect;" "Landroid/graphics/Rect;"
) )

View File

@ -13,7 +13,7 @@ import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint import app.revanced.patches.music.video.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint
import app.revanced.patches.music.video.playback.fingerprints.UserQualityChangeFingerprint import app.revanced.patches.music.video.playback.fingerprints.UserQualityChangeFingerprint
import app.revanced.patches.music.video.videoid.VideoIdPatch import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -52,7 +52,7 @@ object VideoPlaybackPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method -> method.name == "onItemClick" } it.mutableClass.methods.find { method -> method.name == "onItemClick" }
onItemClickMethod?.apply { onItemClickMethod?.apply {
val targetIndex = getTargetIndex(Opcode.IGET) val targetIndex = getTargetIndexOrThrow(Opcode.IGET)
val targetRegister = val targetRegister =
getInstruction<TwoRegisterInstruction>(targetIndex).registerA getInstruction<TwoRegisterInstruction>(targetIndex).registerA

View File

@ -12,8 +12,8 @@ import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACK
import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithFieldReferenceName import app.revanced.util.getTargetIndexWithFieldReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -42,7 +42,7 @@ object AdsPatch : BaseBytecodePatch(
// region Filter promoted ads (does not work in popular or latest feed) // region Filter promoted ads (does not work in popular or latest feed)
AdPostFingerprint.resultOrThrow().let { AdPostFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithFieldReferenceName("children") val targetIndex = getTargetIndexWithFieldReferenceNameOrThrow("children")
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
addInstructions( addInstructions(
@ -59,7 +59,7 @@ object AdsPatch : BaseBytecodePatch(
// By removing the appending instruction no ad posts gets appended to the feed. // By removing the appending instruction no ad posts gets appended to the feed.
NewAdPostFingerprint.resultOrThrow().let { NewAdPostFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceName("add") val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("add")
val targetInstruction = getInstruction<FiveRegisterInstruction>(targetIndex) val targetInstruction = getInstruction<FiveRegisterInstruction>(targetIndex)
replaceInstruction( replaceInstruction(

View File

@ -9,10 +9,10 @@ import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACK
import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceName import app.revanced.util.getTargetIndexWithFieldReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -41,19 +41,19 @@ object RecentlyVisitedShelfPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method -> method.name == "<init>" } it.mutableClass.methods.find { method -> method.name == "<init>" }
?.apply { ?.apply {
val recentlyVisitedFieldIndex = val recentlyVisitedFieldIndex =
getTargetIndexWithFieldReferenceName("RECENTLY_VISITED") getTargetIndexWithFieldReferenceNameOrThrow("RECENTLY_VISITED")
val recentlyVisitedObjectIndex = val recentlyVisitedObjectIndex =
getTargetIndex(recentlyVisitedFieldIndex, Opcode.IPUT_OBJECT) getTargetIndexOrThrow(recentlyVisitedFieldIndex, Opcode.IPUT_OBJECT)
recentlyVisitedReference = recentlyVisitedReference =
getInstruction<ReferenceInstruction>(recentlyVisitedObjectIndex).reference getInstruction<ReferenceInstruction>(recentlyVisitedObjectIndex).reference
} ?: throw PatchException("Constructor method not found!") } ?: throw PatchException("Constructor method not found!")
it.mutableMethod.apply { it.mutableMethod.apply {
val recentlyVisitedObjectIndex = val recentlyVisitedObjectIndex =
getTargetIndexWithReference(recentlyVisitedReference.toString()) getTargetIndexWithReferenceOrThrow(recentlyVisitedReference.toString())
arrayOf( arrayOf(
getTargetIndex(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC), getTargetIndexOrThrow(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC),
getTargetIndexReversed(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC) getTargetIndexReversedOrThrow(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC)
).forEach { staticIndex -> ).forEach { staticIndex ->
val insertRegister = val insertRegister =
getInstruction<OneRegisterInstruction>(staticIndex + 1).registerA getInstruction<OneRegisterInstruction>(staticIndex + 1).registerA

View File

@ -15,7 +15,7 @@ import app.revanced.patches.reddit.utils.settings.fingerprints.AcknowledgementsL
import app.revanced.patches.reddit.utils.settings.fingerprints.OssLicensesMenuActivityOnCreateFingerprint import app.revanced.patches.reddit.utils.settings.fingerprints.OssLicensesMenuActivityOnCreateFingerprint
import app.revanced.patches.reddit.utils.settings.fingerprints.SettingsStatusLoadFingerprint import app.revanced.patches.reddit.utils.settings.fingerprints.SettingsStatusLoadFingerprint
import app.revanced.patches.shared.fingerprints.SharedSettingFingerprint import app.revanced.patches.shared.fingerprints.SharedSettingFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -49,7 +49,7 @@ object SettingsBytecodePatch : BytecodePatch(
*/ */
SharedSettingFingerprint.resultOrThrow().let { SharedSettingFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val stringIndex = getTargetIndex(Opcode.CONST_STRING) val stringIndex = getTargetIndexOrThrow(Opcode.CONST_STRING)
val stringRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA val stringRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA
replaceInstruction( replaceInstruction(

View File

@ -12,11 +12,11 @@ import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.ads.fingerprints.MusicAdsFingerprint import app.revanced.patches.shared.ads.fingerprints.MusicAdsFingerprint
import app.revanced.patches.shared.ads.fingerprints.VideoAdsFingerprint import app.revanced.patches.shared.ads.fingerprints.VideoAdsFingerprint
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -37,7 +37,7 @@ abstract class BaseAdsPatch(
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
MusicAdsFingerprint.resultOrThrow().let { MusicAdsFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference)
opcode == Opcode.INVOKE_VIRTUAL opcode == Opcode.INVOKE_VIRTUAL
@ -112,7 +112,7 @@ abstract class BaseAdsPatch(
// Find the instruction whose name is "show" in [MethodReference] and click the 'AlertDialog.BUTTON_POSITIVE' button. // Find the instruction whose name is "show" in [MethodReference] and click the 'AlertDialog.BUTTON_POSITIVE' button.
// In this case, an instruction for 'getButton' must be added to smali, not in integrations // In this case, an instruction for 'getButton' must be added to smali, not in integrations
// (This custom dialog cannot be cast to [AlertDialog] or [Dialog]) // (This custom dialog cannot be cast to [AlertDialog] or [Dialog])
val dialogIndex = getTargetIndexWithMethodReferenceName("show") val dialogIndex = getTargetIndexWithMethodReferenceNameOrThrow("show")
val dialogReference = getInstruction<ReferenceInstruction>(dialogIndex).reference val dialogReference = getInstruction<ReferenceInstruction>(dialogIndex).reference
val dialogDefiningClass = (dialogReference as MethodReference).definingClass val dialogDefiningClass = (dialogReference as MethodReference).definingClass
val getButtonMethod = context.findClass(dialogDefiningClass)!! val getButtonMethod = context.findClass(dialogDefiningClass)!!
@ -123,7 +123,7 @@ abstract class BaseAdsPatch(
val getButtonCall = val getButtonCall =
dialogDefiningClass + "->" + getButtonMethod.name + "(I)Landroid/widget/Button;" dialogDefiningClass + "->" + getButtonMethod.name + "(I)Landroid/widget/Button;"
val dialogRegister = getInstruction<FiveRegisterInstruction>(dialogIndex).registerC val dialogRegister = getInstruction<FiveRegisterInstruction>(dialogIndex).registerC
val freeIndex = getTargetIndex(dialogIndex, Opcode.IF_EQZ) val freeIndex = getTargetIndexOrThrow(dialogIndex, Opcode.IF_EQZ)
val freeRegister = getInstruction<OneRegisterInstruction>(freeIndex).registerA val freeRegister = getInstruction<OneRegisterInstruction>(freeIndex).registerA
addInstructions( addInstructions(

View File

@ -8,10 +8,10 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.shared.customspeed.fingerprints.SpeedArrayGeneratorFingerprint import app.revanced.patches.shared.customspeed.fingerprints.SpeedArrayGeneratorFingerprint
import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFallBackFingerprint import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFallBackFingerprint
import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFingerprint import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
@ -39,7 +39,7 @@ abstract class BaseCustomPlaybackSpeedPatch(
""" """
) )
val sizeIndex = getTargetIndexWithMethodReferenceName("size") + 1 val sizeIndex = getTargetIndexWithMethodReferenceNameOrThrow("size") + 1
val sizeRegister = getInstruction<OneRegisterInstruction>(sizeIndex).registerA val sizeRegister = getInstruction<OneRegisterInstruction>(sizeIndex).registerA
addInstructions( addInstructions(
@ -49,7 +49,7 @@ abstract class BaseCustomPlaybackSpeedPatch(
""" """
) )
val arrayIndex = getTargetIndexWithFieldReferenceType("[F") val arrayIndex = getTargetIndexWithFieldReferenceTypeOrThrow("[F")
val arrayRegister = getInstruction<OneRegisterInstruction>(arrayIndex).registerA val arrayRegister = getInstruction<OneRegisterInstruction>(arrayIndex).registerA
addInstructions( addInstructions(
@ -71,9 +71,9 @@ abstract class BaseCustomPlaybackSpeedPatch(
).forEach { ).forEach {
it.mutableMethod.apply { it.mutableMethod.apply {
val limiterMinConstIndex = val limiterMinConstIndex =
indexOfFirstInstruction { (this as? NarrowLiteralInstruction)?.narrowLiteral == 0.25f.toRawBits() } indexOfFirstInstructionOrThrow { (this as? NarrowLiteralInstruction)?.narrowLiteral == 0.25f.toRawBits() }
val limiterMaxConstIndex = val limiterMaxConstIndex =
getTargetIndex(limiterMinConstIndex + 1, Opcode.CONST_HIGH16) getTargetIndexOrThrow(limiterMinConstIndex + 1, Opcode.CONST_HIGH16)
val limiterMinConstDestination = val limiterMinConstDestination =
getInstruction<OneRegisterInstruction>(limiterMinConstIndex).registerA getInstruction<OneRegisterInstruction>(limiterMinConstIndex).registerA

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.dialog.fingerprints.CreateDialogFingerprint import app.revanced.patches.shared.dialog.fingerprints.CreateDialogFingerprint
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -22,7 +22,7 @@ abstract class BaseViewerDiscretionDialogPatch(
} }
) { ) {
private fun MutableMethod.invoke(isAgeVerified: Boolean) { private fun MutableMethod.invoke(isAgeVerified: Boolean) {
val showDialogIndex = getTargetIndexWithMethodReferenceName("show") val showDialogIndex = getTargetIndexWithMethodReferenceNameOrThrow("show")
val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC
val methodName = val methodName =

View File

@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.drawable.fingerprints.DrawableFingerprint import app.revanced.patches.shared.drawable.fingerprints.DrawableFingerprint
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -17,7 +17,7 @@ object DrawableColorPatch : BytecodePatch(
DrawableFingerprint.resultOrThrow().mutableMethod.apply { DrawableFingerprint.resultOrThrow().mutableMethod.apply {
insertMethod = this insertMethod = this
insertIndex = getTargetIndexWithMethodReferenceNameReversed("setColor") insertIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("setColor")
insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
} }
} }

View File

@ -15,9 +15,9 @@ import app.revanced.patches.shared.litho.fingerprints.LithoFilterPatchConstructo
import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint
import app.revanced.patches.shared.litho.fingerprints.SetByteBufferFingerprint import app.revanced.patches.shared.litho.fingerprints.SetByteBufferFingerprint
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
@ -56,7 +56,7 @@ object LithoFilterPatch : BytecodePatch(
SetByteBufferFingerprint.resultOrThrow().let { SetByteBufferFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndex(Opcode.IF_EQZ) + 1 val insertIndex = getTargetIndexOrThrow(Opcode.IF_EQZ) + 1
addInstruction( addInstruction(
insertIndex, insertIndex,
@ -136,17 +136,17 @@ object LithoFilterPatch : BytecodePatch(
} }
val stringBuilderIndex = val stringBuilderIndex =
getTargetIndexWithFieldReferenceType("Ljava/lang/StringBuilder;") getTargetIndexWithFieldReferenceTypeOrThrow("Ljava/lang/StringBuilder;")
val stringBuilderRegister = val stringBuilderRegister =
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
val emptyStringIndex = getStringInstructionIndex("") val emptyStringIndex = getStringInstructionIndex("")
val identifierIndex = getTargetIndexReversed(emptyStringIndex, Opcode.IPUT_OBJECT) val identifierIndex = getTargetIndexReversedOrThrow(emptyStringIndex, Opcode.IPUT_OBJECT)
val identifierRegister = val identifierRegister =
getInstruction<TwoRegisterInstruction>(identifierIndex).registerA getInstruction<TwoRegisterInstruction>(identifierIndex).registerA
val objectIndex = getTargetIndex(emptyStringIndex, Opcode.INVOKE_VIRTUAL) val objectIndex = getTargetIndexOrThrow(emptyStringIndex, Opcode.INVOKE_VIRTUAL)
val objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC val objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC
val insertIndex = stringBuilderIndex + 1 val insertIndex = stringBuilderIndex + 1

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import kotlin.properties.Delegates import kotlin.properties.Delegates
@ -37,7 +37,7 @@ abstract class BaseMainActivityResolvePatch(
// set onBackPressed method // set onBackPressed method
onBackPressedMethod = getMethod("onBackPressed") onBackPressedMethod = getMethod("onBackPressed")
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID) onBackPressedMethodIndex = onBackPressedMethod.getTargetIndexOrThrow(Opcode.RETURN_VOID)
} }
fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) = fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) =

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.opus.fingerprints.CodecReferenceFingerprint import app.revanced.patches.shared.opus.fingerprints.CodecReferenceFingerprint
import app.revanced.patches.shared.opus.fingerprints.CodecSelectorFingerprint import app.revanced.patches.shared.opus.fingerprints.CodecSelectorFingerprint
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -31,7 +31,7 @@ abstract class BaseOpusCodecsPatch(
CodecReferenceFingerprint.resultOrThrow().let { CodecReferenceFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithReference("Ljava/util/Set;") val targetIndex = getTargetIndexWithReferenceOrThrow("Ljava/util/Set;")
opusCodecReference = getInstruction<ReferenceInstruction>(targetIndex).reference opusCodecReference = getInstruction<ReferenceInstruction>(targetIndex).reference
} }
} }

View File

@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint
import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint.indexOfReleaseInstruction import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint.indexOfReleaseInstruction
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@ -20,7 +20,7 @@ abstract class BaseSpoofAppVersionPatch(
CreatePlayerRequestBodyWithModelFingerprint.resultOrThrow().mutableMethod.apply { CreatePlayerRequestBodyWithModelFingerprint.resultOrThrow().mutableMethod.apply {
val versionIndex = indexOfReleaseInstruction(this) + 1 val versionIndex = indexOfReleaseInstruction(this) + 1
val insertIndex = getTargetIndexReversed(versionIndex, Opcode.IPUT_OBJECT) val insertIndex = getTargetIndexReversedOrThrow(versionIndex, Opcode.IPUT_OBJECT)
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
addInstructions( addInstructions(

View File

@ -33,11 +33,11 @@ import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CaptionToggleContainer import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CaptionToggleContainer
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceName
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -114,7 +114,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
CaptionsButtonFingerprint.resultOrThrow().mutableMethod.apply { CaptionsButtonFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer) val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer)
val insertIndex = getTargetIndexReversed(constIndex, Opcode.IF_EQZ) val insertIndex = getTargetIndexReversedOrThrow(constIndex, Opcode.IF_EQZ)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions( addInstructions(
@ -127,7 +127,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
CaptionsButtonSyntheticFingerprint.resultOrThrow().mutableMethod.apply { CaptionsButtonSyntheticFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer) val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer)
val targetIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT) val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(
@ -190,7 +190,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
ElementParserFingerprint.resultOrThrow().let { ElementParserFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2 val freeRegister = implementation!!.registerCount - parameters.size - 2
val insertIndex = indexOfFirstInstruction { val insertIndex = indexOfFirstInstructionOrThrow {
val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference)
reference?.parameterTypes?.size == 1 reference?.parameterTypes?.size == 1
@ -198,7 +198,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
&& reference.returnType.startsWith("L") && reference.returnType.startsWith("L")
} }
val objectIndex = getTargetIndex(Opcode.MOVE_OBJECT) val objectIndex = getTargetIndexOrThrow(Opcode.MOVE_OBJECT)
val objectRegister = getInstruction<TwoRegisterInstruction>(objectIndex).registerA val objectRegister = getInstruction<TwoRegisterInstruction>(objectIndex).registerA
val jumpIndex = it.scanResult.patternScanResult!!.startIndex val jumpIndex = it.scanResult.patternScanResult!!.startIndex
@ -257,7 +257,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
val iteratorRegister = val iteratorRegister =
getInstruction<FiveRegisterInstruction>(iteratorIndex).registerC getInstruction<FiveRegisterInstruction>(iteratorIndex).registerC
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference)
opcode == Opcode.INVOKE_INTERFACE opcode == Opcode.INVOKE_INTERFACE
@ -265,7 +265,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
&& reference.parameterTypes == channelTabBuilderMethod.parameterTypes && reference.parameterTypes == channelTabBuilderMethod.parameterTypes
} }
val objectIndex = getTargetIndexReversed(targetIndex, Opcode.IGET_OBJECT) val objectIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.IGET_OBJECT)
val objectInstruction = getInstruction<TwoRegisterInstruction>(objectIndex) val objectInstruction = getInstruction<TwoRegisterInstruction>(objectIndex)
val objectReference = getInstruction<ReferenceInstruction>(objectIndex).reference val objectReference = getInstruction<ReferenceInstruction>(objectIndex).reference

View File

@ -7,8 +7,8 @@ import app.revanced.patches.youtube.general.audiotracks.fingerprints.StreamingMo
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -28,16 +28,16 @@ object AudioTracksPatch : BaseBytecodePatch(
StreamingModelBuilderFingerprint.resultOrThrow().let { StreamingModelBuilderFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val formatStreamModelIndex = indexOfFirstInstruction { val formatStreamModelIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.CHECK_CAST opcode == Opcode.CHECK_CAST
&& (this as ReferenceInstruction).reference.toString() == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;" && (this as ReferenceInstruction).reference.toString() == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;"
} }
val arrayListIndex = getTargetIndexWithReference( val arrayListIndex = getTargetIndexWithReferenceOrThrow(
formatStreamModelIndex, formatStreamModelIndex,
"Ljava/util/List;->add(Ljava/lang/Object;)Z" "Ljava/util/List;->add(Ljava/lang/Object;)Z"
) )
val insertIndex = val insertIndex =
getTargetIndexWithReference(arrayListIndex, "Ljava/util/List;->isEmpty()Z") + 2 getTargetIndexWithReferenceOrThrow(arrayListIndex, "Ljava/util/List;->isEmpty()Z") + 2
val formatStreamModelRegister = val formatStreamModelRegister =
getInstruction<OneRegisterInstruction>(formatStreamModelIndex).registerA getInstruction<OneRegisterInstruction>(formatStreamModelIndex).registerA

View File

@ -27,8 +27,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.viewgroup.ViewGroupMarginLayoutParamsHookPatch import app.revanced.patches.youtube.utils.viewgroup.ViewGroupMarginLayoutParamsHookPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceName
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -173,7 +173,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AccountSwitcherAccessibility) val constIndex = getWideLiteralInstructionIndex(AccountSwitcherAccessibility)
val insertIndex = getTargetIndex(constIndex, Opcode.IF_EQZ) val insertIndex = getTargetIndexOrThrow(constIndex, Opcode.IF_EQZ)
val setVisibilityIndex = val setVisibilityIndex =
getTargetIndexWithMethodReferenceName(insertIndex, "setVisibility") getTargetIndexWithMethodReferenceName(insertIndex, "setVisibility")
val visibilityRegister = val visibilityRegister =
@ -195,7 +195,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
SettingsMenuFingerprint.resultOrThrow().let { SettingsMenuFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = val insertIndex =
getTargetIndexWithFieldReferenceType("Landroid/support/v7/widget/RecyclerView;") getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;")
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
addInstruction( addInstruction(
@ -229,7 +229,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
TooltipContentFullscreenFingerprint.resultOrThrow().mutableMethod.apply { TooltipContentFullscreenFingerprint.resultOrThrow().mutableMethod.apply {
val literalIndex = getWideLiteralInstructionIndex(45384061) val literalIndex = getWideLiteralInstructionIndex(45384061)
val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT) val targetIndex = getTargetIndexOrThrow(literalIndex, Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -10,8 +10,8 @@ import app.revanced.patches.youtube.general.layoutswitch.fingerprints.LayoutSwit
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -34,7 +34,7 @@ object LayoutSwitchPatch : BaseBytecodePatch(
GetFormFactorFingerprint.resultOrThrow().let { GetFormFactorFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val jumpIndex = getTargetIndexReversed(Opcode.SGET_OBJECT) val jumpIndex = getTargetIndexReversedOrThrow(Opcode.SGET_OBJECT)
addInstructionsWithLabels( addInstructionsWithLabels(
0, """ 0, """
@ -56,7 +56,7 @@ object LayoutSwitchPatch : BaseBytecodePatch(
LayoutSwitchFingerprint.resultOrThrow().let { LayoutSwitchFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndex(Opcode.IF_NEZ) val insertIndex = getTargetIndexOrThrow(Opcode.IF_NEZ)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions( addInstructions(

View File

@ -13,7 +13,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_D
import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -82,7 +82,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
PivotBarSetTextFingerprint.resultOrThrow().let { PivotBarSetTextFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceName("setText") val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC
addInstruction( addInstruction(

View File

@ -39,10 +39,10 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.doRecursively import app.revanced.util.doRecursively
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getTargetIndexWithReferenceReversed import app.revanced.util.getTargetIndexWithReferenceReversedOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionHook import app.revanced.util.literalInstructionHook
@ -129,7 +129,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
) )
DrawerContentViewFingerprint.resultOrThrow().let { DrawerContentViewFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("addView") val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstruction( addInstruction(
@ -145,7 +145,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
setActionBarRingoMutableClass.methods.first { method -> setActionBarRingoMutableClass.methods.first { method ->
MethodUtil.isConstructor(method) MethodUtil.isConstructor(method)
}.apply { }.apply {
val insertIndex = getTargetIndex(Opcode.IPUT_BOOLEAN) val insertIndex = getTargetIndexOrThrow(Opcode.IPUT_BOOLEAN)
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
addInstruction( addInstruction(
@ -278,12 +278,12 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
CreateSearchSuggestionsFingerprint.resultOrThrow().let { result -> CreateSearchSuggestionsFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply { result.mutableMethod.apply {
val relativeIndex = getWideLiteralInstructionIndex(40) val relativeIndex = getWideLiteralInstructionIndex(40)
val replaceIndex = getTargetIndexWithReferenceReversed( val replaceIndex = getTargetIndexWithReferenceReversedOrThrow(
relativeIndex, relativeIndex,
"Landroid/widget/ImageView;->setVisibility(I)V" "Landroid/widget/ImageView;->setVisibility(I)V"
) - 1 ) - 1
val jumpIndex = getTargetIndexWithReference( val jumpIndex = getTargetIndexWithReferenceOrThrow(
relativeIndex, relativeIndex,
"Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;" "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;"
) + 4 ) + 4
@ -333,7 +333,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val setVisibilityIndex = val setVisibilityIndex =
getTargetIndexWithMethodReferenceName(startIndex, "setVisibility") getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setVisibility")
val setVisibilityInstruction = val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex) getInstruction<FiveRegisterInstruction>(setVisibilityIndex)
@ -349,7 +349,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(VoiceSearch) val startIndex = getWideLiteralInstructionIndex(VoiceSearch)
val setOnClickListenerIndex = val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceName(startIndex, "setOnClickListener") getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setOnClickListener")
val viewRegister = val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

View File

@ -8,7 +8,7 @@ import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLink
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -32,7 +32,7 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch(
).forEach { fingerprint -> ).forEach { fingerprint ->
fingerprint.resultOrThrow().let { fingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("parse") val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("parse")
val insertRegister = val insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerC getInstruction<FiveRegisterInstruction>(insertIndex).registerC

View File

@ -11,8 +11,8 @@ import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PAC
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -49,9 +49,9 @@ object AmbientModeSwitchPatch : BaseBytecodePatch(
getStringInstructionIndex("android.os.action.POWER_SAVE_MODE_CHANGED") getStringInstructionIndex("android.os.action.POWER_SAVE_MODE_CHANGED")
val targetIndex = val targetIndex =
if (reversed) if (reversed)
getTargetIndexReversed(stringIndex, Opcode.INVOKE_DIRECT) getTargetIndexReversedOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
else else
getTargetIndex(stringIndex, Opcode.INVOKE_DIRECT) getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
val targetClass = val targetClass =
(getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference).definingClass (getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference).definingClass

View File

@ -24,7 +24,7 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullS
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.PlayerCollapseButton import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.PlayerCollapseButton
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TitleAnchor import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TitleAnchor
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -65,7 +65,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AutoNavToggle) val constIndex = getWideLiteralInstructionIndex(AutoNavToggle)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndex(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1 val jumpIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
addInstructionsWithLabels( addInstructionsWithLabels(
constIndex, """ constIndex, """
@ -125,7 +125,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
TitleAnchorFingerprint.resultOrThrow().mutableMethod.apply { TitleAnchorFingerprint.resultOrThrow().mutableMethod.apply {
val titleAnchorConstIndex = getWideLiteralInstructionIndex(TitleAnchor) val titleAnchorConstIndex = getWideLiteralInstructionIndex(TitleAnchor)
val titleAnchorIndex = getTargetIndex(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT) val titleAnchorIndex = getTargetIndexOrThrow(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
val titleAnchorRegister = val titleAnchorRegister =
getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA
@ -137,7 +137,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
val playerCollapseButtonConstIndex = val playerCollapseButtonConstIndex =
getWideLiteralInstructionIndex(PlayerCollapseButton) getWideLiteralInstructionIndex(PlayerCollapseButton)
val playerCollapseButtonIndex = val playerCollapseButtonIndex =
getTargetIndex(playerCollapseButtonConstIndex, Opcode.CHECK_CAST) getTargetIndexOrThrow(playerCollapseButtonConstIndex, Opcode.CHECK_CAST)
val playerCollapseButtonRegister = val playerCollapseButtonRegister =
getInstruction<OneRegisterInstruction>(playerCollapseButtonIndex).registerA getInstruction<OneRegisterInstruction>(playerCollapseButtonIndex).registerA
@ -158,7 +158,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
(instruction.value as? WideLiteralInstruction)?.wideLiteral == FullScreenButton (instruction.value as? WideLiteralInstruction)?.wideLiteral == FullScreenButton
} }
val constIndex = buttonCalls.elementAt(buttonCalls.size - 1).index val constIndex = buttonCalls.elementAt(buttonCalls.size - 1).index
val castIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) val castIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val insertIndex = castIndex + 1 val insertIndex = castIndex + 1
val insertRegister = getInstruction<OneRegisterInstruction>(castIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(castIndex).registerA
@ -179,7 +179,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
PlayerControlsVisibilityModelFingerprint.resultOrThrow().let { PlayerControlsVisibilityModelFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val callIndex = getTargetIndex(Opcode.INVOKE_DIRECT_RANGE) val callIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT_RANGE)
val callInstruction = getInstruction<Instruction3rc>(callIndex) val callInstruction = getInstruction<Instruction3rc>(callIndex)
val hasNextParameterRegister = callInstruction.startRegister + HAS_NEXT val hasNextParameterRegister = callInstruction.startRegister + HAS_NEXT

View File

@ -12,7 +12,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -58,12 +58,12 @@ object CommentsComponentPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492) val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492)
val emojiPickerOnClickListenerIndex = val emojiPickerOnClickListenerIndex =
getTargetIndex(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT) getTargetIndexOrThrow(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
val emojiPickerOnClickListenerMethod = val emojiPickerOnClickListenerMethod =
getWalkerMethod(context, emojiPickerOnClickListenerIndex) getWalkerMethod(context, emojiPickerOnClickListenerIndex)
emojiPickerOnClickListenerMethod.apply { emojiPickerOnClickListenerMethod.apply {
val insertIndex = getTargetIndex(Opcode.IF_EQZ) val insertIndex = getTargetIndexOrThrow(Opcode.IF_EQZ)
val insertRegister = val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA getInstruction<OneRegisterInstruction>(insertIndex).registerA

View File

@ -38,9 +38,9 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FadeD
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ScrimOverlay import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ScrimOverlay
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SeekUndoEduOverlayStub import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SeekUndoEduOverlayStub
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -90,7 +90,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let { YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(ScrimOverlay) val constIndex = getWideLiteralInstructionIndex(ScrimOverlay)
val targetIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
@ -203,7 +203,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(FadeDurationFast) val constIndex = getWideLiteralInstructionIndex(FadeDurationFast)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val insertIndex = getTargetIndexReversed(constIndex, Opcode.INVOKE_VIRTUAL) + 1 val insertIndex = getTargetIndexReversedOrThrow(constIndex, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex = implementation!!.instructions.let { instruction -> val jumpIndex = implementation!!.instructions.let { instruction ->
insertIndex + instruction.subList(insertIndex, instruction.size - 1) insertIndex + instruction.subList(insertIndex, instruction.size - 1)
.indexOfFirst { instructions -> .indexOfFirst { instructions ->
@ -272,7 +272,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val onClickListenerIndex = val onClickListenerIndex =
getTargetIndexWithMethodReferenceName(insertIndex, "setOnClickListener") getTargetIndexWithMethodReferenceNameOrThrow(insertIndex, "setOnClickListener")
val constComponent = getConstComponent(insertIndex, onClickListenerIndex - 1) val constComponent = getConstComponent(insertIndex, onClickListenerIndex - 1)
if (constComponent.isNotEmpty()) { if (constComponent.isNotEmpty()) {
@ -318,7 +318,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;") method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;")
}?.apply { }?.apply {
val setOnClickListenerIndex = val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceName("setOnClickListener") getTargetIndexWithMethodReferenceNameOrThrow("setOnClickListener")
val setOnClickListenerRegister = val setOnClickListenerRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

View File

@ -19,7 +19,7 @@ import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -61,7 +61,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2 val freeRegister = implementation!!.registerCount - parameters.size - 2
val imageSpanIndex = it.scanResult.patternScanResult!!.startIndex val imageSpanIndex = it.scanResult.patternScanResult!!.startIndex
val setTextIndex = getTargetIndexWithMethodReferenceName("setText") val setTextIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
addInstruction(setTextIndex, "nop") addInstruction(setTextIndex, "nop")
addInstructionsWithLabels( addInstructionsWithLabels(
@ -94,7 +94,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
if (SettingsPatch.upward1902) { if (SettingsPatch.upward1902) {
TextViewComponentFingerprint.resultOrThrow().let { TextViewComponentFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("setTextIsSelectable") val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("setTextIsSelectable")
val insertInstruction = getInstruction<FiveRegisterInstruction>(insertIndex) val insertInstruction = getInstruction<FiveRegisterInstruction>(insertIndex)
replaceInstruction( replaceInstruction(
@ -111,7 +111,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
) )
EngagementPanelTitleFingerprint.resultOrThrow().mutableMethod.apply { EngagementPanelTitleFingerprint.resultOrThrow().mutableMethod.apply {
val contentDescriptionIndex = val contentDescriptionIndex =
getTargetIndexWithMethodReferenceName("setContentDescription") getTargetIndexWithMethodReferenceNameOrThrow("setContentDescription")
val contentDescriptionRegister = val contentDescriptionRegister =
getInstruction<FiveRegisterInstruction>(contentDescriptionIndex).registerD getInstruction<FiveRegisterInstruction>(contentDescriptionIndex).registerD

View File

@ -16,7 +16,7 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetFooterText import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetFooterText
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionViewHook import app.revanced.util.literalInstructionViewHook
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -64,7 +64,7 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(
QualityMenuViewInflateFingerprint QualityMenuViewInflateFingerprint
).forEach { fingerprint -> ).forEach { fingerprint ->
fingerprint.resultOrThrow().mutableMethod.apply { fingerprint.resultOrThrow().mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("addHeaderView") val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addHeaderView")
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstructions( addInstructions(

View File

@ -18,9 +18,10 @@ import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DE
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -132,7 +133,7 @@ object ChangeTogglePatch : BaseBytecodePatch(
CinematicLightingFingerprint.resultOrThrow().let { CinematicLightingFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val iGetIndex = indexOfFirstInstruction { val iGetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET opcode == Opcode.IGET
&& getReference<FieldReference>()?.definingClass == definingClass && getReference<FieldReference>()?.definingClass == definingClass
} }
@ -140,10 +141,10 @@ object ChangeTogglePatch : BaseBytecodePatch(
val stringIndex = getStringInstructionIndex("menu_item_cinematic_lighting") val stringIndex = getStringInstructionIndex("menu_item_cinematic_lighting")
val checkCastIndex = getTargetIndexReversed(stringIndex, Opcode.CHECK_CAST) val checkCastIndex = getTargetIndexReversedOrThrow(stringIndex, Opcode.CHECK_CAST)
val iGetObjectPrimaryIndex = val iGetObjectPrimaryIndex =
getTargetIndexReversed(checkCastIndex, Opcode.IGET_OBJECT) getTargetIndexReversedOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectSecondaryIndex = getTargetIndex(checkCastIndex, Opcode.IGET_OBJECT) val iGetObjectSecondaryIndex = getTargetIndexOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val checkCastReference = val checkCastReference =
getInstruction<ReferenceInstruction>(checkCastIndex).reference getInstruction<ReferenceInstruction>(checkCastIndex).reference
@ -152,14 +153,14 @@ object ChangeTogglePatch : BaseBytecodePatch(
val iGetObjectSecondaryReference = val iGetObjectSecondaryReference =
getInstruction<ReferenceInstruction>(iGetObjectSecondaryIndex).reference getInstruction<ReferenceInstruction>(iGetObjectSecondaryIndex).reference
val invokeVirtualIndex = getTargetIndex(stringIndex, Opcode.INVOKE_VIRTUAL) val invokeVirtualIndex = getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_VIRTUAL)
val invokeVirtualInstruction = val invokeVirtualInstruction =
getInstruction<FiveRegisterInstruction>(invokeVirtualIndex) getInstruction<FiveRegisterInstruction>(invokeVirtualIndex)
val freeRegisterC = invokeVirtualInstruction.registerC val freeRegisterC = invokeVirtualInstruction.registerC
val freeRegisterD = invokeVirtualInstruction.registerD val freeRegisterD = invokeVirtualInstruction.registerD
val freeRegisterE = invokeVirtualInstruction.registerE val freeRegisterE = invokeVirtualInstruction.registerE
val insertIndex = getTargetIndex(stringIndex, Opcode.RETURN_VOID) val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.RETURN_VOID)
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, """ insertIndex, """

View File

@ -32,8 +32,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullS
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QuickActionsElementContainer import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QuickActionsElementContainer
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
@ -80,7 +80,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
EngagementPanelFingerprint.resultOrThrow().let { EngagementPanelFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val literalIndex = getWideLiteralInstructionIndex(FullScreenEngagementPanel) val literalIndex = getWideLiteralInstructionIndex(FullScreenEngagementPanel)
val targetIndex = getTargetIndex(literalIndex, Opcode.CHECK_CAST) val targetIndex = getTargetIndexOrThrow(literalIndex, Opcode.CHECK_CAST)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(
@ -93,7 +93,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
PlayerTitleViewFingerprint.resultOrThrow().let { PlayerTitleViewFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("addView") val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val insertReference = val insertReference =
getInstruction<ReferenceInstruction>(insertIndex).reference.toString() getInstruction<ReferenceInstruction>(insertIndex).reference.toString()
if (!insertReference.startsWith("Landroid/widget/FrameLayout;")) if (!insertReference.startsWith("Landroid/widget/FrameLayout;"))
@ -116,7 +116,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AutoNavPreviewStub) val constIndex = getWideLiteralInstructionIndex(AutoNavPreviewStub)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndex(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1 val jumpIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
addInstructionsWithLabels( addInstructionsWithLabels(
constIndex, """ constIndex, """
@ -158,7 +158,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
} }
val constIndex = containerCalls.elementAt(containerCalls.size - 1).index val constIndex = containerCalls.elementAt(containerCalls.size - 1).index
val checkCastIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) val checkCastIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val insertRegister = val insertRegister =
getInstruction<OneRegisterInstruction>(checkCastIndex).registerA getInstruction<OneRegisterInstruction>(checkCastIndex).registerA
@ -182,8 +182,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let { YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceName("setFocusableInTouchMode") val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("setFocusableInTouchMode")
val walkerIndex = getTargetIndex(targetIndex, Opcode.INVOKE_STATIC) val walkerIndex = getTargetIndexOrThrow(targetIndex, Opcode.INVOKE_STATIC)
val walkerMethod = getWalkerMethod(context, walkerIndex) val walkerMethod = getWalkerMethod(context, walkerIndex)
walkerMethod.apply { walkerMethod.apply {
@ -243,8 +243,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val stringIndex = val stringIndex =
getStringInstructionIndex("Acquiring NetLatencyActionLogger failed. taskId=") getStringInstructionIndex("Acquiring NetLatencyActionLogger failed. taskId=")
val invokeIndex = getTargetIndex(stringIndex, Opcode.INVOKE_INTERFACE) val invokeIndex = getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_INTERFACE)
val targetIndex = getTargetIndex(invokeIndex, Opcode.CHECK_CAST) val targetIndex = getTargetIndexOrThrow(invokeIndex, Opcode.CHECK_CAST)
val targetClass = context val targetClass = context
.findClass(getInstruction<ReferenceInstruction>(targetIndex).reference.toString())!! .findClass(getInstruction<ReferenceInstruction>(targetIndex).reference.toString())!!
.mutableClass .mutableClass
@ -310,7 +310,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
result.mutableMethod.apply { result.mutableMethod.apply {
val stringIndex = val stringIndex =
getStringInstructionIndex("android.intent.action.SCREEN_ON") getStringInstructionIndex("android.intent.action.SCREEN_ON")
val insertIndex = getTargetIndex(stringIndex, Opcode.IF_EQZ) + 1 val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.IF_EQZ) + 1
addInstruction( addInstruction(
insertIndex, insertIndex,

View File

@ -13,7 +13,7 @@ import app.revanced.patches.youtube.player.hapticfeedback.fingerprints.ZoomHapti
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -65,7 +65,7 @@ object HapticFeedBackPatch : BaseBytecodePatch(
var register = 0 var register = 0
if (name == "run") { if (name == "run") {
index = getTargetIndex(Opcode.SGET) index = getTargetIndexOrThrow(Opcode.SGET)
register = getInstruction<OneRegisterInstruction>(index).registerA register = getInstruction<OneRegisterInstruction>(index).registerA
} }

View File

@ -18,8 +18,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -84,7 +84,7 @@ object OverlayButtonsBytecodePatch : BytecodePatch(
PlayerButtonConstructorFingerprint.resultOrThrow().mutableMethod.apply { PlayerButtonConstructorFingerprint.resultOrThrow().mutableMethod.apply {
val registerResolver = implementation!!.registerCount - parameters.size - 1 + 6 // p6 val registerResolver = implementation!!.registerCount - parameters.size - 1 + 6 // p6
val invokerObjectIndex = indexOfFirstInstruction { val invokerObjectIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IPUT_OBJECT opcode == Opcode.IPUT_OBJECT
&& getReference<FieldReference>()?.definingClass == definingClass && getReference<FieldReference>()?.definingClass == definingClass
&& (this as TwoRegisterInstruction).registerA == registerResolver && (this as TwoRegisterInstruction).registerA == registerResolver
@ -93,7 +93,7 @@ object OverlayButtonsBytecodePatch : BytecodePatch(
getInstruction<ReferenceInstruction>(invokerObjectIndex).reference getInstruction<ReferenceInstruction>(invokerObjectIndex).reference
val onClickListenerReferenceIndex = val onClickListenerReferenceIndex =
getTargetIndexWithReference("<init>(Ljava/lang/Object;I[B)V") getTargetIndexWithReferenceOrThrow("<init>(Ljava/lang/Object;I[B)V")
val onClickListenerReference = val onClickListenerReference =
getInstruction<ReferenceInstruction>(onClickListenerReferenceIndex).reference getInstruction<ReferenceInstruction>(onClickListenerReferenceIndex).reference
val onClickListenerClass = val onClickListenerClass =
@ -103,7 +103,7 @@ object OverlayButtonsBytecodePatch : BytecodePatch(
onClickListenerClass.methods.find { method -> method.name == "onClick" } onClickListenerClass.methods.find { method -> method.name == "onClick" }
?.apply { ?.apply {
val invokeInterfaceIndex = val invokeInterfaceIndex =
getTargetIndexWithReference(invokerObjectReference.toString()) + 1 getTargetIndexWithReferenceOrThrow(invokerObjectReference.toString()) + 1
if (getInstruction(invokeInterfaceIndex).opcode != Opcode.INVOKE_INTERFACE) if (getInstruction(invokeInterfaceIndex).opcode != Opcode.INVOKE_INTERFACE)
throw PatchException("Opcode does not match") throw PatchException("Opcode does not match")
invokeInterfaceReference = invokeInterfaceReference =

View File

@ -29,8 +29,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelT
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
@ -132,10 +132,10 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
TotalTimeFingerprint.resultOrThrow().let { TotalTimeFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val charSequenceIndex = getTargetIndexWithMethodReferenceName("getString") + 1 val charSequenceIndex = getTargetIndexWithMethodReferenceNameOrThrow("getString") + 1
val charSequenceRegister = val charSequenceRegister =
getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA
val textViewIndex = getTargetIndexWithMethodReferenceName("getText") val textViewIndex = getTargetIndexWithMethodReferenceNameOrThrow("getText")
val textViewRegister = val textViewRegister =
getInstruction<FiveRegisterInstruction>(textViewIndex).registerC getInstruction<FiveRegisterInstruction>(textViewIndex).registerC
@ -204,7 +204,7 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
PlayerButtonsVisibilityFingerprint.resultOrThrow().let { PlayerButtonsVisibilityFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2 val freeRegister = implementation!!.registerCount - parameters.size - 2
val viewIndex = getTargetIndex(Opcode.INVOKE_INTERFACE) val viewIndex = getTargetIndexOrThrow(Opcode.INVOKE_INTERFACE)
val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD
addInstructionsWithLabels( addInstructionsWithLabels(

View File

@ -20,12 +20,12 @@ import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverla
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -102,7 +102,7 @@ object SpeedOverlayPatch : BytecodePatch(
// Used on YouTube 19.18.41~ // Used on YouTube 19.18.41~
NextGenWatchLayoutFingerprint.resultOrThrow().mutableMethod.apply { NextGenWatchLayoutFingerprint.resultOrThrow().mutableMethod.apply {
val booleanValueIndex = getTargetIndexWithMethodReferenceName("booleanValue") val booleanValueIndex = getTargetIndexWithMethodReferenceNameOrThrow("booleanValue")
val insertIndex = findIGetIndex(booleanValueIndex - 10, booleanValueIndex) val insertIndex = findIGetIndex(booleanValueIndex - 10, booleanValueIndex)
val insertInstruction = getInstruction<TwoRegisterInstruction>(insertIndex) val insertInstruction = getInstruction<TwoRegisterInstruction>(insertIndex)
@ -139,9 +139,9 @@ object SpeedOverlayPatch : BytecodePatch(
} }
slideToSeekBooleanMethod.apply { slideToSeekBooleanMethod.apply {
var insertIndex = getTargetIndex(Opcode.IGET_OBJECT) var insertIndex = getTargetIndexOrThrow(Opcode.IGET_OBJECT)
var insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA var insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
var jumpIndex = getTargetIndexReversed(Opcode.INVOKE_VIRTUAL) var jumpIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_VIRTUAL)
hook(insertIndex, insertRegister, jumpIndex) hook(insertIndex, insertRegister, jumpIndex)
@ -151,7 +151,7 @@ object SpeedOverlayPatch : BytecodePatch(
?: throw PatchException("Could not find constructor method") ?: throw PatchException("Could not find constructor method")
constructorMethod.apply { constructorMethod.apply {
val syntheticIndex = getTargetIndexReversed(Opcode.NEW_INSTANCE) val syntheticIndex = getTargetIndexReversedOrThrow(Opcode.NEW_INSTANCE)
val syntheticClass = val syntheticClass =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString() getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
@ -162,7 +162,7 @@ object SpeedOverlayPatch : BytecodePatch(
syntheticMethod.apply { syntheticMethod.apply {
val speedOverlayValueIndex = val speedOverlayValueIndex =
indexOfFirstInstruction { (this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits() } indexOfFirstInstructionOrThrow { (this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits() }
val speedOverlayValueRegister = val speedOverlayValueRegister =
getInstruction<OneRegisterInstruction>(speedOverlayValueIndex).registerA getInstruction<OneRegisterInstruction>(speedOverlayValueIndex).registerA
@ -173,13 +173,13 @@ object SpeedOverlayPatch : BytecodePatch(
""" """
) )
insertIndex = getTargetIndexWithMethodReferenceNameReversed( insertIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow(
speedOverlayValueIndex, speedOverlayValueIndex,
"removeCallbacks" "removeCallbacks"
) + 1 ) + 1
insertRegister = insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
jumpIndex = getTargetIndex(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1 jumpIndex = getTargetIndexOrThrow(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1
hook(insertIndex, insertRegister, jumpIndex) hook(insertIndex, insertRegister, jumpIndex)
} }
} }

View File

@ -34,9 +34,9 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelR
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
@ -96,7 +96,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
val constIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon) val constIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndex(constIndex, Opcode.CONST_CLASS) + 2 val jumpIndex = getTargetIndexOrThrow(constIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels( addInstructionsWithLabels(
constIndex + 1, """ constIndex + 1, """
@ -117,7 +117,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getWideLiteralInstructionIndex(ReelRightLikeIcon) val insertIndex = getWideLiteralInstructionIndex(ReelRightLikeIcon)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndex(insertIndex, Opcode.CONST_CLASS) + 2 val jumpIndex = getTargetIndexOrThrow(insertIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex + 1, """ insertIndex + 1, """
@ -139,8 +139,8 @@ object ShortsComponentPatch : BaseBytecodePatch(
val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton) val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val insertIndex = getTargetIndexReversed(targetIndex, Opcode.IF_EQZ) val insertIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.IF_EQZ)
val jumpIndex = getTargetIndex(targetIndex, Opcode.GOTO) val jumpIndex = getTargetIndexOrThrow(targetIndex, Opcode.GOTO)
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, """ insertIndex, """
@ -157,7 +157,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
(instruction.value as? WideLiteralInstruction)?.wideLiteral == ReelPivotButton (instruction.value as? WideLiteralInstruction)?.wideLiteral == ReelPivotButton
} }
val targetIndex = constCalls.elementAt(constCalls.size - 1).index val targetIndex = constCalls.elementAt(constCalls.size - 1).index
val insertIndex = getTargetIndexReversed(targetIndex, Opcode.INVOKE_STATIC) + 1 val insertIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.INVOKE_STATIC) + 1
if (insertIndex == 0) if (insertIndex == 0)
throw PatchException("insert index not found") throw PatchException("insert index not found")
@ -267,7 +267,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
TextComponentSpecFingerprint.resultOrThrow().let { TextComponentSpecFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = val insertIndex =
getTargetIndexWithReference("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;") getTargetIndexWithReferenceOrThrow("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;")
val charSequenceRegister = val charSequenceRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerC getInstruction<FiveRegisterInstruction>(insertIndex).registerC
@ -318,9 +318,9 @@ object ShortsComponentPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(id) val constIndex = getWideLiteralInstructionIndex(id)
val insertIndex = if (reversed) val insertIndex = if (reversed)
getTargetIndexReversed(constIndex, Opcode.CHECK_CAST) getTargetIndexReversedOrThrow(constIndex, Opcode.CHECK_CAST)
else else
getTargetIndex(constIndex, Opcode.CHECK_CAST) getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction( addInstruction(
@ -338,7 +338,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
resultOrThrow().let { resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(id) val constIndex = getWideLiteralInstructionIndex(id)
val insertIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) val insertIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
hideButtons(insertIndex, descriptor) hideButtons(insertIndex, descriptor)
} }

View File

@ -10,7 +10,7 @@ import app.revanced.patches.youtube.shorts.components.fingerprints.RenderBottomN
import app.revanced.patches.youtube.shorts.components.fingerprints.SetPivotBarFingerprint import app.revanced.patches.youtube.shorts.components.fingerprints.SetPivotBarFingerprint
import app.revanced.patches.youtube.utils.fingerprints.InitializeButtonsFingerprint import app.revanced.patches.youtube.utils.fingerprints.InitializeButtonsFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -51,7 +51,7 @@ object ShortsNavigationBarPatch : BytecodePatch(
BottomNavigationBarFingerprint.resultOrThrow().let { BottomNavigationBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceName("findViewById") + 1 val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("findViewById") + 1
val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructions( addInstructions(

View File

@ -13,7 +13,7 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.containsReferenceInstructionIndex import app.revanced.util.containsReferenceInstructionIndex
import app.revanced.util.findMutableMethodOf import app.revanced.util.findMutableMethodOf
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -45,7 +45,7 @@ object ShortsRepeatPatch : BaseBytecodePatch(
val endScreenStringIndex = val endScreenStringIndex =
getStringInstructionIndex("REEL_LOOP_BEHAVIOR_END_SCREEN") getStringInstructionIndex("REEL_LOOP_BEHAVIOR_END_SCREEN")
val endScreenReferenceIndex = val endScreenReferenceIndex =
getTargetIndex(endScreenStringIndex, Opcode.SPUT_OBJECT) getTargetIndexOrThrow(endScreenStringIndex, Opcode.SPUT_OBJECT)
val endScreenReference = val endScreenReference =
getInstruction<ReferenceInstruction>(endScreenReferenceIndex).reference.toString() getInstruction<ReferenceInstruction>(endScreenReferenceIndex).reference.toString()
@ -74,7 +74,7 @@ object ShortsRepeatPatch : BaseBytecodePatch(
fieldName: String fieldName: String
) { ) {
val stringIndex = getStringInstructionIndex(enumName) val stringIndex = getStringInstructionIndex(enumName)
val insertIndex = getTargetIndex(stringIndex, Opcode.SPUT_OBJECT) val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.SPUT_OBJECT)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction( addInstruction(

View File

@ -14,7 +14,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DE
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -70,12 +70,11 @@ object ResumingShortsOnStartupPatch : BaseBytecodePatch(
UserWasInShortsFingerprint.resultOrThrow().let { UserWasInShortsFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val listenableInstructionIndex = indexOfFirstInstruction { val listenableInstructionIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE && opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" && getReference<MethodReference>()?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" &&
getReference<MethodReference>()?.name == "isDone" getReference<MethodReference>()?.name == "isDone"
} }
if (listenableInstructionIndex < 0) throw PatchException("Could not find instruction index")
val originalInstructionRegister = val originalInstructionRegister =
getInstruction<FiveRegisterInstruction>(listenableInstructionIndex).registerC getInstruction<FiveRegisterInstruction>(listenableInstructionIndex).registerC
val freeRegister = val freeRegister =

View File

@ -17,7 +17,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.PATCH_STATUS_CL
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus import app.revanced.util.updatePatchStatus
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -64,7 +64,7 @@ object CastButtonPatch : BytecodePatch(
internal fun hookPlayerButton(context: BytecodeContext) { internal fun hookPlayerButton(context: BytecodeContext) {
playerButtonMethod.apply { playerButtonMethod.apply {
val index = getTargetIndexWithMethodReferenceName("setVisibility") val index = getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val instruction = getInstruction<FiveRegisterInstruction>(index) val instruction = getInstruction<FiveRegisterInstruction>(index)
val viewRegister = instruction.registerC val viewRegister = instruction.registerC
val visibilityRegister = instruction.registerD val visibilityRegister = instruction.registerD
@ -84,7 +84,7 @@ object CastButtonPatch : BytecodePatch(
internal fun hookToolBarButton(context: BytecodeContext) { internal fun hookToolBarButton(context: BytecodeContext) {
toolbarMenuItemInitializeMethod.apply { toolbarMenuItemInitializeMethod.apply {
val index = getTargetIndexWithMethodReferenceName("setShowAsAction") + 1 val index = getTargetIndexWithMethodReferenceNameOrThrow("setShowAsAction") + 1
addInstruction( addInstruction(
index, index,

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch
import app.revanced.patches.youtube.utils.fix.cairo.fingerprints.CarioFragmentConfigFingerprint import app.revanced.patches.youtube.utils.fix.cairo.fingerprints.CarioFragmentConfigFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -33,7 +33,7 @@ object CairoSettingsPatch : BytecodePatch(
CarioFragmentConfigFingerprint.result?.let { CarioFragmentConfigFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = val targetIndex =
getTargetIndex(getWideLiteralInstructionIndex(45532100), Opcode.MOVE_RESULT) getTargetIndexOrThrow(getWideLiteralInstructionIndex(45532100), Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fix.fullscreen.fingerprints.FullscreenButtonPositionFingerprint import app.revanced.patches.youtube.utils.fix.fullscreen.fingerprints.FullscreenButtonPositionFingerprint
import app.revanced.patches.youtube.utils.fix.fullscreen.fingerprints.FullscreenButtonViewStubFingerprint import app.revanced.patches.youtube.utils.fix.fullscreen.fingerprints.FullscreenButtonViewStubFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -33,7 +33,7 @@ object FullscreenButtonViewStubPatch : BytecodePatch(
).forEach { (fingerprint, literalValue) -> ).forEach { (fingerprint, literalValue) ->
fingerprint.result?.let { fingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndex( val targetIndex = getTargetIndexOrThrow(
getWideLiteralInstructionIndex(literalValue.toLong()), getWideLiteralInstructionIndex(literalValue.toLong()),
Opcode.MOVE_RESULT Opcode.MOVE_RESULT
) )

View File

@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fix.litho.fingerprints.ObfuscationConfigFingerprint import app.revanced.patches.youtube.utils.fix.litho.fingerprints.ObfuscationConfigFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -27,7 +27,7 @@ object ConversionContextObfuscationPatch : BytecodePatch(
ObfuscationConfigFingerprint.result?.let { ObfuscationConfigFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = val targetIndex =
getTargetIndex(getWideLiteralInstructionIndex(45631264), Opcode.MOVE_RESULT) getTargetIndexOrThrow(getWideLiteralInstructionIndex(45631264), Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fix.shortsplayback.fingerprints.ShortsPlaybackFingerprint import app.revanced.patches.youtube.utils.fix.shortsplayback.fingerprints.ShortsPlaybackFingerprint
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -28,7 +28,7 @@ object ShortsPlaybackPatch : BytecodePatch(
ShortsPlaybackFingerprint.result?.let { ShortsPlaybackFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = val targetIndex =
getTargetIndex(getWideLiteralInstructionIndex(45387052), Opcode.MOVE_RESULT) getTargetIndexOrThrow(getWideLiteralInstructionIndex(45387052), Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(

View File

@ -8,8 +8,8 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints.RemoveOnLayoutChangeListenerFingerprint import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints.RemoveOnLayoutChangeListenerFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -36,9 +36,9 @@ object SuggestedVideoEndScreenPatch : BytecodePatch(
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex)
walkerIndex.apply { walkerIndex.apply {
val invokeInterfaceIndex = getTargetIndex(Opcode.INVOKE_INTERFACE) val invokeInterfaceIndex = getTargetIndexOrThrow(Opcode.INVOKE_INTERFACE)
val iGetObjectIndex = val iGetObjectIndex =
getTargetIndexReversed(invokeInterfaceIndex, Opcode.IGET_OBJECT) getTargetIndexReversedOrThrow(invokeInterfaceIndex, Opcode.IGET_OBJECT)
val invokeInterfaceReference = val invokeInterfaceReference =
getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference

View File

@ -16,8 +16,8 @@ import app.revanced.patches.youtube.utils.playercontrols.fingerprints.MotionEven
import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityEntityModelFingerprint import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityEntityModelFingerprint
import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityFingerprint import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -56,7 +56,7 @@ object PlayerControlsPatch : BytecodePatch(
) )
PlayerButtonsVisibilityFingerprint.resultOrThrow().let { PlayerButtonsVisibilityFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val viewIndex = getTargetIndex(Opcode.INVOKE_INTERFACE) val viewIndex = getTargetIndexOrThrow(Opcode.INVOKE_INTERFACE)
val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD
addInstruction( addInstruction(
@ -88,7 +88,7 @@ object PlayerControlsPatch : BytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().mutableClass YouTubeControlsOverlayFingerprint.resultOrThrow().mutableClass
) )
MotionEventFingerprint.resultOrThrow().mutableMethod.apply { MotionEventFingerprint.resultOrThrow().mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceName("setTranslationY") + 1 val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("setTranslationY") + 1
addInstruction( addInstruction(
insertIndex, insertIndex,

View File

@ -9,7 +9,7 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityEntityModelFingerprint import app.revanced.patches.youtube.utils.playercontrols.fingerprints.PlayerControlsVisibilityEntityModelFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -31,7 +31,7 @@ object PlayerControlsVisibilityHookPatch : BytecodePatch(
val staticReference = getInstruction<ReferenceInstruction>(startIndex + 1).reference val staticReference = getInstruction<ReferenceInstruction>(startIndex + 1).reference
it.mutableClass.methods.find { method -> method.name == "<init>" }?.apply { it.mutableClass.methods.find { method -> method.name == "<init>" }?.apply {
val targetIndex = getTargetIndex(Opcode.IPUT_OBJECT) val targetIndex = getTargetIndexOrThrow(Opcode.IPUT_OBJECT)
val targetRegister = val targetRegister =
getInstruction<TwoRegisterInstruction>(targetIndex).registerA getInstruction<TwoRegisterInstruction>(targetIndex).registerA

View File

@ -17,8 +17,8 @@ import app.revanced.patches.youtube.utils.playertype.fingerprint.VideoStateFinge
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -90,7 +90,7 @@ object PlayerTypeHookPatch : BytecodePatch(
targetClass.methods.find { method -> method.name == "<init>" } targetClass.methods.find { method -> method.name == "<init>" }
?.apply { ?.apply {
val browseIdFieldIndex = getTargetIndex(Opcode.IPUT_OBJECT) val browseIdFieldIndex = getTargetIndexOrThrow(Opcode.IPUT_OBJECT)
val browseIdFieldName = val browseIdFieldName =
(getInstruction<ReferenceInstruction>(browseIdFieldIndex).reference as FieldReference).name (getInstruction<ReferenceInstruction>(browseIdFieldIndex).reference as FieldReference).name
@ -128,7 +128,7 @@ object PlayerTypeHookPatch : BytecodePatch(
// Insert before the first ViewGroup method call after inflating, // Insert before the first ViewGroup method call after inflating,
// so this works regardless which layout is used. // so this works regardless which layout is used.
ActionBarSearchResultsFingerprint.resultOrThrow().mutableMethod.apply { ActionBarSearchResultsFingerprint.resultOrThrow().mutableMethod.apply {
val instructionIndex = getTargetIndexWithMethodReferenceName("setLayoutDirection") val instructionIndex = getTargetIndexWithMethodReferenceNameOrThrow("setLayoutDirection")
val viewRegister = getInstruction<FiveRegisterInstruction>(instructionIndex).registerC val viewRegister = getInstruction<FiveRegisterInstruction>(instructionIndex).registerC
addInstruction( addInstruction(

View File

@ -18,7 +18,7 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.ReturnYouT
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.patches.youtube.video.videoid.VideoIdPatch import app.revanced.patches.youtube.video.videoid.VideoIdPatch
import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -71,12 +71,12 @@ object ReturnYouTubeDislikePatch : BaseBytecodePatch(
TextComponentContextFingerprint.resultOrThrow().let { TextComponentContextFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val conversionContextFieldIndex = val conversionContextFieldIndex =
getTargetIndexWithFieldReferenceType("Ljava/util/Map;") - 1 getTargetIndexWithFieldReferenceTypeOrThrow("Ljava/util/Map;") - 1
val conversionContextFieldReference = val conversionContextFieldReference =
getInstruction<ReferenceInstruction>(conversionContextFieldIndex).reference getInstruction<ReferenceInstruction>(conversionContextFieldIndex).reference
val charSequenceIndex = val charSequenceIndex =
getTargetIndexWithFieldReferenceType("Ljava/util/BitSet;") - 1 getTargetIndexWithFieldReferenceTypeOrThrow("Ljava/util/BitSet;") - 1
val charSequenceRegister = val charSequenceRegister =
getInstruction<TwoRegisterInstruction>(charSequenceIndex).registerA getInstruction<TwoRegisterInstruction>(charSequenceIndex).registerA
val freeRegister = val freeRegister =

View File

@ -17,8 +17,8 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fin
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberMeasureTextParentFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberMeasureTextParentFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberSetterFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberSetterFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -60,7 +60,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch(
rollingNumberClass.methods.find { method -> method.name == "<init>" } rollingNumberClass.methods.find { method -> method.name == "<init>" }
?.apply { ?.apply {
val rollingNumberFieldIndex = getTargetIndex(Opcode.IPUT_OBJECT) val rollingNumberFieldIndex = getTargetIndexOrThrow(Opcode.IPUT_OBJECT)
charSequenceFieldReference = charSequenceFieldReference =
getInstruction<ReferenceInstruction>(rollingNumberFieldIndex).reference getInstruction<ReferenceInstruction>(rollingNumberFieldIndex).reference
} ?: throw PatchException("RollingNumberClass not found!") } ?: throw PatchException("RollingNumberClass not found!")
@ -103,7 +103,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch(
""" """
) )
val ifGeIndex = getTargetIndex(Opcode.IF_GE) val ifGeIndex = getTargetIndexOrThrow(Opcode.IF_GE)
val ifGeInstruction = getInstruction<TwoRegisterInstruction>(ifGeIndex) val ifGeInstruction = getInstruction<TwoRegisterInstruction>(ifGeIndex)
removeInstruction(ifGeIndex) removeInstruction(ifGeIndex)
@ -153,7 +153,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch(
realTimeUpdateTextViewMethod realTimeUpdateTextViewMethod
).forEach { insertMethod -> ).forEach { insertMethod ->
insertMethod.apply { insertMethod.apply {
val setTextIndex = getTargetIndexWithMethodReferenceName("setText") val setTextIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val textViewRegister = val textViewRegister =
getInstruction<FiveRegisterInstruction>(setTextIndex).registerC getInstruction<FiveRegisterInstruction>(setTextIndex).registerC
val textSpanRegister = val textSpanRegister =

View File

@ -12,9 +12,9 @@ import app.revanced.patches.youtube.utils.fingerprints.TextComponentSpecFingerpr
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.ShortsTextViewFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.ShortsTextViewFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -36,8 +36,8 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val isDisLikesBooleanIndex = getTargetIndexReversed(startIndex, Opcode.IGET_BOOLEAN) val isDisLikesBooleanIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_BOOLEAN)
val textViewFieldIndex = getTargetIndexReversed(startIndex, Opcode.IGET_OBJECT) val textViewFieldIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_OBJECT)
// If the field is true, the TextView is for a dislike button. // If the field is true, the TextView is for a dislike button.
val isDisLikesBooleanReference = val isDisLikesBooleanReference =
@ -49,7 +49,7 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
// Check if the hooked TextView object is that of the dislike button. // Check if the hooked TextView object is that of the dislike button.
// If RYD is disabled, or the TextView object is not that of the dislike button, the execution flow is not interrupted. // If RYD is disabled, or the TextView object is not that of the dislike button, the execution flow is not interrupted.
// Otherwise, the TextView object is modified, and the execution flow is interrupted to prevent it from being changed afterward. // Otherwise, the TextView object is modified, and the execution flow is interrupted to prevent it from being changed afterward.
val insertIndex = getTargetIndex(Opcode.CHECK_CAST) + 1 val insertIndex = getTargetIndexOrThrow(Opcode.CHECK_CAST) + 1
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, """ insertIndex, """
@ -72,7 +72,7 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
TextComponentSpecFingerprint.resultOrThrow().let { TextComponentSpecFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = val insertIndex =
getTargetIndexWithReference("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;") getTargetIndexWithReferenceOrThrow("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;")
val charSequenceRegister = val charSequenceRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerC getInstruction<FiveRegisterInstruction>(insertIndex).registerC

View File

@ -19,10 +19,10 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Inset
import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.RectangleFieldInvalidatorFingerprint import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.RectangleFieldInvalidatorFingerprint
import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.SegmentPlaybackControllerFingerprint import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.SegmentPlaybackControllerFingerprint
import app.revanced.patches.youtube.video.information.VideoInformationPatch import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversed import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus import app.revanced.util.updatePatchStatus
@ -80,7 +80,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
SeekbarOnDrawFingerprint.resultOrThrow().mutableMethod.apply { SeekbarOnDrawFingerprint.resultOrThrow().mutableMethod.apply {
// Get left and right of seekbar rectangle // Get left and right of seekbar rectangle
val moveObjectIndex = getTargetIndex(Opcode.MOVE_OBJECT_FROM16) val moveObjectIndex = getTargetIndexOrThrow(Opcode.MOVE_OBJECT_FROM16)
addInstruction( addInstruction(
moveObjectIndex + 1, moveObjectIndex + 1,
@ -89,7 +89,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Set seekbar thickness // Set seekbar thickness
val roundIndex = getTargetIndexWithMethodReferenceName("round") + 1 val roundIndex = getTargetIndexWithMethodReferenceNameOrThrow("round") + 1
val roundRegister = getInstruction<OneRegisterInstruction>(roundIndex).registerA val roundRegister = getInstruction<OneRegisterInstruction>(roundIndex).registerA
addInstruction( addInstruction(
@ -99,7 +99,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
) )
// Draw segment // Draw segment
val drawCircleIndex = getTargetIndexWithMethodReferenceNameReversed("drawCircle") val drawCircleIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("drawCircle")
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex) val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction( addInstruction(
drawCircleIndex, drawCircleIndex,
@ -116,7 +116,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
// Append timestamp // Append timestamp
TotalTimeFingerprint.resultOrThrow().let { TotalTimeFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceName("getString") + 1 val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("getString") + 1
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructions( addInstructions(
@ -132,7 +132,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let { YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(InsetOverlayViewLayout) val targetIndex = getWideLiteralInstructionIndex(InsetOverlayViewLayout)
val checkCastIndex = getTargetIndex(targetIndex, Opcode.CHECK_CAST) val checkCastIndex = getTargetIndexOrThrow(targetIndex, Opcode.CHECK_CAST)
val targetRegister = val targetRegister =
getInstruction<OneRegisterInstruction>(checkCastIndex).registerA getInstruction<OneRegisterInstruction>(checkCastIndex).registerA
@ -146,8 +146,8 @@ object SponsorBlockBytecodePatch : BytecodePatch(
// Replace strings // Replace strings
RectangleFieldInvalidatorFingerprint.resultOrThrow().let { result -> RectangleFieldInvalidatorFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply { result.mutableMethod.apply {
val invalidateIndex = getTargetIndexWithMethodReferenceNameReversed("invalidate") val invalidateIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversed( val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversedOrThrow(
invalidateIndex + 1, invalidateIndex + 1,
"Landroid/graphics/Rect;" "Landroid/graphics/Rect;"
) )

View File

@ -34,10 +34,10 @@ import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHoo
import app.revanced.patches.youtube.video.videoid.VideoIdPatch import app.revanced.patches.youtube.video.videoid.VideoIdPatch
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getWalkerMethod import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -192,11 +192,10 @@ object VideoInformationPatch : BytecodePatch(
PlaybackInitializationFingerprint.resultOrThrow().let { PlaybackInitializationFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_DIRECT opcode == Opcode.INVOKE_DIRECT
&& getReference<MethodReference>()?.returnType == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR && getReference<MethodReference>()?.returnType == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
} + 1 } + 1
if (targetIndex == 0) throw PatchException("Could not find instruction index.")
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction( addInstruction(
@ -213,11 +212,10 @@ object VideoInformationPatch : BytecodePatch(
VideoIdFingerprintBackgroundPlay.resultOrThrow().let { VideoIdFingerprintBackgroundPlay.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE opcode == Opcode.INVOKE_INTERFACE
&& getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR && getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
} }
if (targetIndex < 0) throw PatchException("Could not find instruction index.")
val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC
addInstruction( addInstruction(
@ -232,11 +230,10 @@ object VideoInformationPatch : BytecodePatch(
VideoIdFingerprintShorts.resultOrThrow().let { VideoIdFingerprintShorts.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE opcode == Opcode.INVOKE_INTERFACE
&& getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR && getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
} }
if (targetIndex < 0) throw PatchException("Could not find instruction index.")
val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC
addInstruction( addInstruction(
@ -281,10 +278,10 @@ object VideoInformationPatch : BytecodePatch(
OnPlaybackSpeedItemClickFingerprint.resultOrThrow().let { OnPlaybackSpeedItemClickFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
speedSelectionInsertMethod = this speedSelectionInsertMethod = this
val speedSelectionValueInstructionIndex = getTargetIndex(Opcode.IGET) val speedSelectionValueInstructionIndex = getTargetIndexOrThrow(Opcode.IGET)
val setPlaybackSpeedContainerClassFieldIndex = val setPlaybackSpeedContainerClassFieldIndex =
getTargetIndexReversed(speedSelectionValueInstructionIndex, Opcode.IGET_OBJECT) getTargetIndexReversedOrThrow(speedSelectionValueInstructionIndex, Opcode.IGET_OBJECT)
val setPlaybackSpeedContainerClassFieldReference = val setPlaybackSpeedContainerClassFieldReference =
getInstruction<ReferenceInstruction>(setPlaybackSpeedContainerClassFieldIndex).reference.toString() getInstruction<ReferenceInstruction>(setPlaybackSpeedContainerClassFieldIndex).reference.toString()
@ -455,12 +452,11 @@ object VideoInformationPatch : BytecodePatch(
private fun MethodFingerprint.getMethodName(returnType: String): String { private fun MethodFingerprint.getMethodName(returnType: String): String {
resultOrThrow().mutableMethod.apply { resultOrThrow().mutableMethod.apply {
val targetIndex = indexOfFirstInstruction { val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE opcode == Opcode.INVOKE_INTERFACE
&& getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR && getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
&& getReference<MethodReference>()?.returnType == returnType && getReference<MethodReference>()?.returnType == returnType
} }
if (targetIndex < 0) throw PatchException("Could not find instruction index.")
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference
return "invoke-interface {v${REGISTER_PLAYER_RESPONSE_MODEL}}, $targetReference" return "invoke-interface {v${REGISTER_PLAYER_RESPONSE_MODEL}}, $targetReference"

View File

@ -34,7 +34,9 @@ import app.revanced.patches.youtube.video.videoid.VideoIdPatch
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus import app.revanced.util.updatePatchStatus
@ -133,7 +135,7 @@ object VideoPlaybackPatch : BaseBytecodePatch(
speedSelectionInsertMethod speedSelectionInsertMethod
).forEach { ).forEach {
it.apply { it.apply {
val speedSelectionValueInstructionIndex = getTargetIndex(Opcode.IGET) val speedSelectionValueInstructionIndex = getTargetIndexOrThrow(Opcode.IGET)
val speedSelectionValueRegister = val speedSelectionValueRegister =
getInstruction<TwoRegisterInstruction>(speedSelectionValueInstructionIndex).registerA getInstruction<TwoRegisterInstruction>(speedSelectionValueInstructionIndex).registerA
@ -206,7 +208,7 @@ object VideoPlaybackPatch : BaseBytecodePatch(
QualityMenuViewInflateFingerprint.resultOrThrow().let { QualityMenuViewInflateFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = getTargetIndex(Opcode.CHECK_CAST) val insertIndex = getTargetIndexOrThrow(Opcode.CHECK_CAST)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction( addInstruction(
@ -219,10 +221,10 @@ object VideoPlaybackPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method -> method.name == "onItemClick" } it.mutableClass.methods.find { method -> method.name == "onItemClick" }
onItemClickMethod?.apply { onItemClickMethod?.apply {
val insertIndex = getTargetIndex(Opcode.IGET_OBJECT) val insertIndex = getTargetIndexOrThrow(Opcode.IGET_OBJECT)
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val jumpIndex = indexOfFirstInstruction { val jumpIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET_OBJECT opcode == Opcode.IGET_OBJECT
&& this.getReference<FieldReference>()?.type == videoQualityClass && this.getReference<FieldReference>()?.type == videoQualityClass
} }

View File

@ -340,10 +340,81 @@ inline fun <reified T : Reference> Instruction.getReference() =
fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) = fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) =
this.implementation!!.instructions.indexOfFirst(predicate) this.implementation!!.instructions.indexOfFirst(predicate)
fun MutableMethod.getTargetIndex(opcode: Opcode) = getTargetIndex(0, opcode) fun MutableMethod.getTargetIndexOrThrow(opcode: Opcode) =
getTargetIndexOrThrow(0, opcode)
fun MutableMethod.getTargetIndexReversed(opcode: Opcode) = fun MutableMethod.getTargetIndexOrThrow(startIndex: Int, opcode: Opcode) =
getTargetIndexReversed(implementation!!.instructions.size - 1, opcode) checkIndex(getTargetIndex(startIndex, opcode), startIndex, opcode)
fun MutableMethod.getTargetIndexReversedOrThrow(opcode: Opcode) =
getTargetIndexReversedOrThrow(implementation!!.instructions.lastIndex, opcode)
fun MutableMethod.getTargetIndexReversedOrThrow(startIndex: Int, opcode: Opcode) =
checkIndex(getTargetIndexReversed(startIndex, opcode), startIndex, opcode)
fun Method.getTargetIndexWithFieldReferenceNameOrThrow(filedName: String) =
checkIndex(getTargetIndexWithFieldReferenceName(filedName), 0, filedName)
fun MutableMethod.getTargetIndexWithFieldReferenceNameOrThrow(startIndex: Int, filedName: String) =
checkIndex(getTargetIndexWithFieldReferenceName(startIndex, filedName), startIndex, filedName)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversedOrThrow(returnType: String) =
getTargetIndexWithFieldReferenceNameReversedOrThrow(implementation!!.instructions.lastIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversedOrThrow(startIndex: Int, returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceNameReversed(startIndex, returnType), startIndex, returnType)
fun Method.getTargetIndexWithFieldReferenceTypeOrThrow(returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceType(returnType), 0, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeOrThrow(startIndex: Int, returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceType(startIndex, returnType), startIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeReversedOrThrow(returnType: String) =
getTargetIndexWithFieldReferenceTypeReversedOrThrow(implementation!!.instructions.lastIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeReversedOrThrow(startIndex: Int, returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceTypeReversed(startIndex, returnType), startIndex, returnType)
fun Method.getTargetIndexWithMethodReferenceNameOrThrow(methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceName(methodName), 0, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameOrThrow(startIndex: Int, methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceName(startIndex, methodName), startIndex, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameReversedOrThrow(methodName: String) =
getTargetIndexWithMethodReferenceNameReversedOrThrow(implementation!!.instructions.lastIndex, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameReversedOrThrow(startIndex: Int, methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceNameReversed(startIndex, methodName), startIndex, methodName)
fun Method.getTargetIndexWithReferenceOrThrow(reference: String) =
checkIndex(getTargetIndexWithReference(reference), 0, reference)
fun MutableMethod.getTargetIndexWithReferenceOrThrow(startIndex: Int, reference: String) =
checkIndex(getTargetIndexWithReference(startIndex, reference), startIndex, reference)
fun MutableMethod.getTargetIndexWithReferenceReversedOrThrow(reference: String) =
getTargetIndexWithReferenceReversedOrThrow(implementation!!.instructions.lastIndex, reference)
fun MutableMethod.getTargetIndexWithReferenceReversedOrThrow(startIndex: Int, reference: String) =
checkIndex(getTargetIndexWithReferenceReversed(startIndex, reference), startIndex, reference)
fun checkIndex(index: Int, startIndex: Int, opcode: Opcode): Int {
if (index < 0) {
throw PatchException("Target index not found. startIndex: $startIndex, opcode: $opcode")
}
return index
}
fun checkIndex(index: Int, startIndex: Int, name: String): Int {
if (index < 0) {
throw PatchException("Target index not found. startIndex: $startIndex, name: $name")
}
return index
}
fun MutableMethod.getTargetIndex(opcode: Opcode) = getTargetIndex(0, opcode)
fun MutableMethod.getTargetIndex(startIndex: Int, opcode: Opcode) = fun MutableMethod.getTargetIndex(startIndex: Int, opcode: Opcode) =
implementation!!.instructions.let { implementation!!.instructions.let {
@ -352,6 +423,9 @@ fun MutableMethod.getTargetIndex(startIndex: Int, opcode: Opcode) =
} }
} }
fun MutableMethod.getTargetIndexReversed(opcode: Opcode) =
getTargetIndexReversed(implementation!!.instructions.size - 1, opcode)
fun MutableMethod.getTargetIndexReversed(startIndex: Int, opcode: Opcode): Int { fun MutableMethod.getTargetIndexReversed(startIndex: Int, opcode: Opcode): Int {
for (index in startIndex downTo 0) { for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode) if (getInstruction(index).opcode != opcode)
@ -368,16 +442,16 @@ fun Method.getTargetIndexWithFieldReferenceName(filedName: String) = implementat
} }
} ?: -1 } ?: -1
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(returnType: String) =
getTargetIndexWithFieldReferenceTypeReversed(implementation!!.instructions.size - 1, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceName(startIndex: Int, filedName: String) = fun MutableMethod.getTargetIndexWithFieldReferenceName(startIndex: Int, filedName: String) =
implementation!!.instructions.let { implementation!!.instructions.let {
startIndex + it.subList(startIndex, it.size - 1).indexOfFirst { instruction -> startIndex + it.subList(startIndex, it.lastIndex).indexOfFirst { instruction ->
instruction.getReference<FieldReference>()?.name == filedName instruction.getReference<FieldReference>()?.name == filedName
} }
} }
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(returnType: String) =
getTargetIndexWithFieldReferenceTypeReversed(implementation!!.instructions.lastIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed( fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(
startIndex: Int, startIndex: Int,
filedName: String filedName: String