refactor(BytecodeUtils): remove duplicate functions

This commit is contained in:
inotia00 2024-09-17 18:40:11 +09:00
parent 5e4b56cfbe
commit afd19dead4
135 changed files with 1349 additions and 1453 deletions

View File

@ -14,12 +14,14 @@ 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.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.reference.MethodReference
@Suppress("unused")
object AccountComponentsPatch : BaseBytecodePatch(
@ -43,8 +45,14 @@ object AccountComponentsPatch : BaseBytecodePatch(
MenuEntryFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val textIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val viewIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val textIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setText"
}
val viewIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "addView"
}
val textRegister = getInstruction<FiveRegisterInstruction>(textIndex).registerD
val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD
@ -64,9 +72,14 @@ object AccountComponentsPatch : BaseBytecodePatch(
AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val textColorIndex = getTargetIndexWithMethodReferenceNameOrThrow("setTextColor")
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow(textColorIndex, "setVisibility")
val textColorIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setTextColor"
}
val setVisibilityIndex = indexOfFirstInstructionOrThrow(textColorIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setVisibility"
}
val textViewInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)
@ -98,8 +111,12 @@ object AccountComponentsPatch : BaseBytecodePatch(
TermsOfServiceFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex =
getTargetIndexWithReferenceOrThrow("/PrivacyTosFooter;->setVisibility(I)V")
val insertIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.name == "setVisibility" &&
reference.definingClass.endsWith("/PrivacyTosFooter;")
}
val visibilityRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerD

View File

@ -15,10 +15,9 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.LikeDis
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -26,6 +25,7 @@ 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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import kotlin.math.min
@Suppress("unused")
@ -48,7 +48,10 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply {
// hook download button
val addViewIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val addViewIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "addView"
}
val addViewRegister =
getInstruction<FiveRegisterInstruction>(addViewIndex).registerD
@ -83,10 +86,15 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
removeInstruction(replaceIndex)
// hide action button
val hasNextIndex = getTargetIndexWithMethodReferenceNameOrThrow("hasNext")
val hasNextIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.name == "hasNext"
}
val freeRegister = min(implementation!!.registerCount - parameters.size - 2, 15)
val spannedIndex = getTargetIndexWithReferenceOrThrow(")Landroid/text/Spanned;")
val spannedIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.returnType == "Landroid/text/Spanned;"
}
val spannedRegister =
getInstruction<FiveRegisterInstruction>(spannedIndex).registerC
val spannedReference = getInstruction<ReferenceInstruction>(spannedIndex).reference
@ -124,7 +132,8 @@ object ActionBarComponentsPatch : BaseBytecodePatch(
LikeDislikeContainerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getWideLiteralInstructionIndex(LikeDislikeContainer) + 2
val insertIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(LikeDislikeContainer) + 2
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction(

View File

@ -22,19 +22,21 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ButtonContainer
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.FloatingLayout
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.InterstitialsContainer
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PrivacyTosFooter
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
@Suppress("unused")
object AdsPatch : BaseBytecodePatch(
@ -87,7 +89,7 @@ object AdsPatch : BaseBytecodePatch(
FloatingLayoutFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(FloatingLayout) + 2
val targetIndex = indexOfFirstWideLiteralInstructionValueOrThrow(FloatingLayout) + 2
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -103,7 +105,8 @@ object AdsPatch : BaseBytecodePatch(
NotifierShelfFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val linearLayoutIndex = getWideLiteralInstructionIndex(ButtonContainer) + 3
val linearLayoutIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(ButtonContainer) + 3
val linearLayoutRegister =
getInstruction<OneRegisterInstruction>(linearLayoutIndex).registerA
@ -135,16 +138,20 @@ object AdsPatch : BaseBytecodePatch(
AccountMenuFooterFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.PrivacyTosFooter)
val walkerIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL)
val viewIndex = getTargetIndexOrThrow(constIndex, Opcode.IGET_OBJECT)
indexOfFirstWideLiteralInstructionValueOrThrow(PrivacyTosFooter)
val walkerIndex =
indexOfFirstInstructionOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL)
val viewIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.IGET_OBJECT)
val viewReference =
getInstruction<ReferenceInstruction>(viewIndex).reference.toString()
val walkerMethod = getWalkerMethod(context, walkerIndex)
walkerMethod.apply {
val insertIndex = getTargetIndexWithReferenceOrThrow(viewReference)
val nullCheckIndex = getTargetIndexOrThrow(insertIndex - 1, Opcode.IF_NEZ)
val insertIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.toString() == viewReference
}
val nullCheckIndex =
indexOfFirstInstructionOrThrow(insertIndex - 1, Opcode.IF_NEZ)
val nullCheckRegister =
getInstruction<OneRegisterInstruction>(nullCheckIndex).registerA

View File

@ -4,14 +4,14 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ButtonContainer
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicNotifierShelf
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object NotifierShelfFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(MusicNotifierShelf)
&& methodDef.containsWideLiteralInstructionIndex(ButtonContainer)
methodDef.containsWideLiteralInstructionValue(MusicNotifierShelf)
&& methodDef.containsWideLiteralInstructionValue(ButtonContainer)
}
)

View File

@ -2,7 +2,7 @@ package app.revanced.patches.music.ads.general.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.SlidingDialogAnimation
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.Opcode
internal object ShowDialogCommandFingerprint : MethodFingerprint(
@ -16,7 +16,7 @@ internal object ShowDialogCommandFingerprint : MethodFingerprint(
// 6.26 and earlier has a different first parameter.
// Since this fingerprint is somewhat weak, work around by checking for both method parameter signatures.
customFingerprint = custom@{ methodDef, _ ->
if (!methodDef.containsWideLiteralInstructionIndex(SlidingDialogAnimation)) {
if (!methodDef.containsWideLiteralInstructionValue(SlidingDialogAnimation)) {
return@custom false
}
// 6.26 and earlier parameters are: "L", "L"

View File

@ -25,12 +25,11 @@ import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -88,7 +87,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
// region patch for enable trim silence
TrimSilenceConfigFingerprint.result?.let {
TrimSilenceConfigFingerprint.literalInstructionBooleanHook(
TrimSilenceConfigFingerprint.injectLiteralInstructionBooleanCall(
45619123,
"$FLYOUT_CLASS_DESCRIPTOR->enableTrimSilence(Z)Z"
)
@ -96,9 +95,9 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
TrimSilenceSwitchFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.TrimSilenceSwitch)
indexOfFirstWideLiteralInstructionValueOrThrow(SharedResourceIdPatch.TrimSilenceSwitch)
val onCheckedChangedListenerIndex =
getTargetIndexOrThrow(constIndex, Opcode.INVOKE_DIRECT)
indexOfFirstInstructionOrThrow(constIndex, Opcode.INVOKE_DIRECT)
val onCheckedChangedListenerReference =
getInstruction<ReferenceInstruction>(onCheckedChangedListenerIndex).reference
val onCheckedChangedListenerDefiningClass =
@ -118,7 +117,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
&& reference.parameterTypes[0] == "Z"
}
getWalkerMethod(context, walkerIndex).apply {
val insertIndex = getTargetIndexOrThrow(Opcode.MOVE_RESULT)
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT)
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
@ -142,7 +141,7 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
MenuItemFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val freeIndex = getTargetIndexOrThrow(Opcode.OR_INT_LIT16)
val freeIndex = indexOfFirstInstructionOrThrow(Opcode.OR_INT_LIT16)
val textViewIndex = it.scanResult.patternScanResult!!.startIndex
val imageViewIndex = it.scanResult.patternScanResult!!.endIndex
@ -175,8 +174,10 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
TouchOutsideFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setOnClickListener")
val setOnClickListenerIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val setOnClickListenerRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC
@ -189,8 +190,10 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
EndButtonsContainerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(EndButtonsContainer)
val targetIndex = getTargetIndexOrThrow(startIndex, Opcode.MOVE_RESULT_OBJECT)
val startIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(EndButtonsContainer)
val targetIndex =
indexOfFirstInstructionOrThrow(startIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -27,15 +27,17 @@ import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKA
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicTasteBuilderShelf
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerOverlayChip
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopBarMenuItemImageView
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.shared.settingmenu.SettingsMenuPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.alsoResolve
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -99,7 +101,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
PlayerOverlayChipFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.PlayerOverlayChip) + 2
indexOfFirstWideLiteralInstructionValueOrThrow(PlayerOverlayChip) + 2
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -176,8 +178,10 @@ object LayoutComponentsPatch : BaseBytecodePatch(
if (SettingsPatch.upward0642) {
TopBarMenuItemImageViewFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(TopBarMenuItemImageView)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val constIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(TopBarMenuItemImageView)
val targetIndex =
indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -193,7 +197,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
// region patch for hide sound search button
SoundSearchFingerprint.result?.let {
SoundSearchFingerprint.literalInstructionBooleanHook(
SoundSearchFingerprint.injectLiteralInstructionBooleanCall(
45625491,
"$GENERAL_CLASS_DESCRIPTOR->hideSoundSearchButton(Z)Z"
)
@ -227,8 +231,9 @@ object LayoutComponentsPatch : BaseBytecodePatch(
parentResult.mutableMethod.apply {
val constIndex =
getWideLiteralInstructionIndex(SharedResourceIdPatch.MusicTasteBuilderShelf)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
indexOfFirstWideLiteralInstructionValueOrThrow(MusicTasteBuilderShelf)
val targetIndex =
indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -263,14 +268,11 @@ object LayoutComponentsPatch : BaseBytecodePatch(
// region patch for hide voice search button
SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
)
SearchBarFingerprint.resultOrThrow().let {
SearchBarFingerprint.alsoResolve(
context, SearchBarParentFingerprint
).let {
it.mutableMethod.apply {
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityIndex = SearchBarFingerprint.indexOfVisibilityInstruction(this)
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

View File

@ -3,7 +3,7 @@ package app.revanced.patches.music.general.components.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.HistoryMenuItem
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -16,7 +16,7 @@ internal object HistoryMenuItemFingerprint : MethodFingerprint(
Opcode.RETURN_VOID
),
customFingerprint = { methodDef, classDef ->
methodDef.containsWideLiteralInstructionIndex(HistoryMenuItem)
methodDef.containsWideLiteralInstructionValue(HistoryMenuItem)
&& classDef.methods.count() == 5
}
)

View File

@ -4,7 +4,7 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.HistoryMenuItem
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.OfflineSettingsMenuItem
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -17,7 +17,7 @@ internal object HistoryMenuItemOfflineTabFingerprint : MethodFingerprint(
Opcode.RETURN_VOID
),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(HistoryMenuItem)
&& methodDef.containsWideLiteralInstructionIndex(OfflineSettingsMenuItem)
methodDef.containsWideLiteralInstructionValue(HistoryMenuItem)
&& methodDef.containsWideLiteralInstructionValue(OfflineSettingsMenuItem)
}
)

View File

@ -1,8 +1,22 @@
package app.revanced.patches.music.general.components.fingerprints
import app.revanced.util.fingerprint.MethodReferenceNameFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.general.components.fingerprints.SearchBarFingerprint.indexOfVisibilityInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
object SearchBarFingerprint : MethodReferenceNameFingerprint(
object SearchBarFingerprint : MethodFingerprint(
returnType = "V",
reference = { "setVisibility" }
)
customFingerprint = { methodDef, _ ->
indexOfVisibilityInstruction(methodDef) >= 0
}
) {
fun indexOfVisibilityInstruction(methodDef: Method) =
methodDef.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setVisibility"
}
}

View File

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

View File

@ -11,11 +11,11 @@ import app.revanced.patches.music.utils.fingerprints.PendingIntentReceiverFinger
import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -41,13 +41,14 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
PendingIntentReceiverFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getStringInstructionIndex("YTM Dislike")
val startIndex = indexOfFirstStringInstructionOrThrow("YTM Dislike")
val onClickRelayIndex =
getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
indexOfFirstInstructionReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickRelayMethod = getWalkerMethod(context, onClickRelayIndex)
onClickRelayMethod.apply {
val onClickMethodIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_DIRECT)
val onClickMethodIndex =
indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT)
val onClickMethod = getWalkerMethod(context, onClickMethodIndex)
onClickMethod.apply {
@ -70,7 +71,9 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
DislikeButtonOnClickListenerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val onClickIndex = getTargetIndexWithReferenceOrThrow(onClickReference.toString())
val onClickIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.toString() == onClickReference.toString()
}
injectCall(onClickIndex)
}
}
@ -84,7 +87,7 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
}
private fun MutableMethod.injectCall(onClickIndex: Int) {
val targetIndex = getTargetIndexReversedOrThrow(onClickIndex, Opcode.IF_EQZ)
val targetIndex = indexOfFirstInstructionReversedOrThrow(onClickIndex, Opcode.IF_EQZ)
val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructionsWithLabels(

View File

@ -2,7 +2,7 @@ package app.revanced.patches.music.general.redirection.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object DislikeButtonOnClickListenerFingerprint : MethodFingerprint(
@ -10,7 +10,7 @@ internal object DislikeButtonOnClickListenerFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/View;"),
customFingerprint = handler@{ methodDef, _ ->
if (!methodDef.containsWideLiteralInstructionIndex(53465))
if (!methodDef.containsWideLiteralInstructionValue(53465))
return@handler false
methodDef.name == "onClick"

View File

@ -10,15 +10,16 @@ import app.revanced.patches.music.misc.backgroundplayback.fingerprints.KidsBackg
import app.revanced.patches.music.misc.backgroundplayback.fingerprints.MusicBrowserServiceFingerprint
import app.revanced.patches.music.misc.backgroundplayback.fingerprints.PodCastConfigFingerprint
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.util.getStartsWithStringInstructionIndex
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object BackgroundPlaybackPatch : BaseBytecodePatch(
@ -51,26 +52,20 @@ object BackgroundPlaybackPatch : BaseBytecodePatch(
// don't play music video
MusicBrowserServiceFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex =
getStartsWithStringInstructionIndex("MBS: Return empty root for client: %s")
for (index in targetIndex downTo 0) {
if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) continue
val targetReference = getInstruction<ReferenceInstruction>(index).reference
if (!targetReference.toString().endsWith("()Z")) continue
val walkerMethod = getWalkerMethod(context, index)
walkerMethod.addInstructions(
0, """
const/4 v0, 0x1
return v0
"""
)
break
val stringIndex = MusicBrowserServiceFingerprint.indexOfMBSInstruction(this)
val targetIndex = indexOfFirstInstructionReversedOrThrow(stringIndex) {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "Z" &&
reference.parameterTypes.size == 0
}
getWalkerMethod(context, targetIndex).addInstructions(
0, """
const/4 v0, 0x1
return v0
"""
)
}
}
@ -97,7 +92,8 @@ object BackgroundPlaybackPatch : BaseBytecodePatch(
}
dataSavingSettingsFragmentFingerprintResult!!.mutableMethod.apply {
val insertIndex = getStringInstructionIndex("pref_key_dont_play_nma_video") + 4
val insertIndex =
indexOfFirstStringInstructionOrThrow("pref_key_dont_play_nma_video") + 4
val targetRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstruction(

View File

@ -2,8 +2,13 @@ package app.revanced.patches.music.misc.backgroundplayback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getStartsWithStringInstructionIndex
import app.revanced.patches.music.misc.backgroundplayback.fingerprints.MusicBrowserServiceFingerprint.indexOfMBSInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.StringReference
internal object MusicBrowserServiceFingerprint : MethodFingerprint(
returnType = "L",
@ -13,6 +18,12 @@ internal object MusicBrowserServiceFingerprint : MethodFingerprint(
if (!methodDef.definingClass.endsWith("/MusicBrowserService;"))
return@custom false
methodDef.getStartsWithStringInstructionIndex("MBS: Return empty root for client: %s") > 0
indexOfMBSInstruction(methodDef) >= 0
}
)
) {
fun indexOfMBSInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
opcode == Opcode.CONST_STRING &&
getReference<StringReference>()?.string?.startsWith("MBS: Return empty root for client: %s") == true
}
}

View File

@ -12,8 +12,8 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.BottomS
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -40,8 +40,8 @@ object ShareSheetPatch : BaseBytecodePatch(
override fun execute(context: BytecodeContext) {
BottomSheetRecyclerViewFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(BottomSheetRecyclerView)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(BottomSheetRecyclerView)
val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -8,7 +8,7 @@ import app.revanced.patches.music.misc.splash.fingerprints.CairoSplashAnimationC
import app.revanced.patches.music.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.injectLiteralInstructionBooleanCall
@Patch(
name = "Disable Cairo splash animation",
@ -31,7 +31,7 @@ object CairoSplashAnimationPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
CairoSplashAnimationConfigFingerprint.result?.let {
CairoSplashAnimationConfigFingerprint.literalInstructionBooleanHook(
CairoSplashAnimationConfigFingerprint.injectLiteralInstructionBooleanCall(
45635386,
"$MISC_PATH/CairoSplashAnimationPatch;->disableCairoSplashAnimation(Z)Z"
)

View File

@ -11,13 +11,12 @@ import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKA
import app.revanced.patches.music.utils.integrations.Constants.NAVIGATION_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ColorGrey
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.Text1
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.getReference
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -50,7 +49,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
* Enable black navigation bar
*/
TabLayoutFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(ColorGrey)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(ColorGrey)
val insertIndex = indexOfFirstInstructionOrThrow(constIndex) {
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.name == "setBackgroundColor"
@ -70,8 +69,9 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
*/
TabLayoutTextFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(SharedResourceIdPatch.Text1)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val constIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(Text1)
val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
@ -105,9 +105,12 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply {
val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
val insertEnumIndex = getTargetIndexOrThrow(Opcode.AND_INT_LIT8) - 2
val insertEnumIndex = indexOfFirstInstructionOrThrow(Opcode.AND_INT_LIT8) - 2
val pivotTabIndex = getTargetIndexWithMethodReferenceNameOrThrow("getVisibility")
val pivotTabIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "getVisibility"
}
val pivotTabRegister = getInstruction<Instruction35c>(pivotTabIndex).registerC
addInstruction(

View File

@ -60,16 +60,13 @@ import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionViewHook
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.injectLiteralInstructionViewCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import app.revanced.util.transformFields
@ -145,8 +142,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
PlayerViewPager to "disablePlayerGesture"
).forEach { (literal, methodName) ->
val viewPagerReference = playerViewPagerConstructorMethod.let {
val constIndex = it.getWideLiteralInstructionIndex(literal)
val targetIndex = it.getTargetIndexOrThrow(constIndex, Opcode.IPUT_OBJECT)
val constIndex = it.indexOfFirstWideLiteralInstructionValueOrThrow(literal)
val targetIndex = it.indexOfFirstInstructionOrThrow(constIndex, Opcode.IPUT_OBJECT)
it.getInstruction<ReferenceInstruction>(targetIndex).reference.toString()
}
@ -156,7 +153,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
&& getReference<FieldReference>()?.toString() == viewPagerReference
}
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndex(insertIndex, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex =
indexOfFirstInstructionOrThrow(insertIndex, Opcode.INVOKE_VIRTUAL) + 1
addInstructionsWithLabels(
insertIndex, """
@ -198,8 +196,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val relativeIndex = it.scanResult.patternScanResult!!.endIndex + 1
val invokeVirtualIndex =
getTargetIndexOrThrow(relativeIndex, Opcode.INVOKE_VIRTUAL)
val iGetIndex = getTargetIndexOrThrow(relativeIndex, Opcode.IGET)
indexOfFirstInstructionOrThrow(relativeIndex, Opcode.INVOKE_VIRTUAL)
val iGetIndex = indexOfFirstInstructionOrThrow(relativeIndex, Opcode.IGET)
colorMathPlayerInvokeVirtualReference =
getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference
@ -207,11 +205,11 @@ object PlayerComponentsPatch : BaseBytecodePatch(
getInstruction<ReferenceInstruction>(iGetIndex).reference
// black player background
val invokeDirectIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT)
val invokeDirectIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT)
val targetMethod = getWalkerMethod(context, invokeDirectIndex)
targetMethod.apply {
val insertIndex = getTargetIndexOrThrow(0, Opcode.IF_NE)
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IF_NE)
addInstructions(
insertIndex, """
@ -225,8 +223,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
}
parentResult.mutableMethod.apply {
val colorGreyIndex = getWideLiteralInstructionIndex(ColorGrey)
val iPutIndex = getTargetIndexOrThrow(colorGreyIndex, Opcode.IPUT)
val colorGreyIndex = indexOfFirstWideLiteralInstructionValueOrThrow(ColorGrey)
val iPutIndex = indexOfFirstInstructionOrThrow(colorGreyIndex, Opcode.IPUT)
colorMathPlayerIPutReference =
getInstruction<ReferenceInstruction>(iPutIndex).reference
@ -240,7 +238,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 3
val invokeDirectIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_DIRECT)
val invokeDirectIndex =
indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT)
val invokeDirectReference =
getInstruction<ReferenceInstruction>(invokeDirectIndex).reference
@ -401,9 +400,9 @@ object PlayerComponentsPatch : BaseBytecodePatch(
reversed: Boolean
): Reference {
val targetIndex = if (reversed)
getTargetIndexReversedOrThrow(swipeToDismissWidgetIndex, opcode)
indexOfFirstInstructionReversedOrThrow(swipeToDismissWidgetIndex, opcode)
else
getTargetIndexOrThrow(swipeToDismissWidgetIndex, opcode)
indexOfFirstInstructionOrThrow(swipeToDismissWidgetIndex, opcode)
return getInstruction<ReferenceInstruction>(targetIndex).reference
}
@ -411,7 +410,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
if (!SettingsPatch.upward0642) {
SwipeToCloseFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
val insertIndex = implementation!!.instructions.lastIndex
val targetRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
@ -430,8 +429,9 @@ object PlayerComponentsPatch : BaseBytecodePatch(
InteractionLoggingEnumFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val stringIndex =
getStringInstructionIndex("INTERACTION_LOGGING_GESTURE_TYPE_SWIPE")
val sPutObjectIndex = getTargetIndexOrThrow(stringIndex, Opcode.SPUT_OBJECT)
indexOfFirstStringInstructionOrThrow("INTERACTION_LOGGING_GESTURE_TYPE_SWIPE")
val sPutObjectIndex =
indexOfFirstInstructionOrThrow(stringIndex, Opcode.SPUT_OBJECT)
swipeToDismissSGetObjectReference =
getInstruction<ReferenceInstruction>(sPutObjectIndex).reference
@ -440,7 +440,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
MusicActivityWidgetFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
swipeToDismissWidgetIndex = getWideLiteralInstructionIndex(79500)
swipeToDismissWidgetIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(79500)
swipeToDismissIGetObjectReference =
getSwipeToDismissReference(Opcode.IGET_OBJECT, true)
@ -468,8 +469,9 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex)
dismissBehaviorMethod.apply {
val insertIndex =
getTargetIndexWithFieldReferenceTypeOrThrow("Ljava/util/concurrent/atomic/AtomicBoolean;")
val insertIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.type == "Ljava/util/concurrent/atomic/AtomicBoolean;"
}
val primaryRegister =
getInstruction<TwoRegisterInstruction>(insertIndex).registerB
val secondaryRegister = primaryRegister + 1
@ -592,7 +594,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
SwitchToggleColorFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val invokeDirectIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT)
val invokeDirectIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT)
val walkerMethod = getWalkerMethod(context, invokeDirectIndex)
walkerMethod.addInstructions(
@ -624,8 +626,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
// region patch for hide audio video switch toggle
AudioVideoSwitchToggleFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AudioVideoSwitchToggle)
val viewIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(AudioVideoSwitchToggle)
val viewIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA
addInstruction(
@ -667,7 +669,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
DarkBackground,
TapBloomView
).forEach { literal ->
QuickSeekOverlayFingerprint.literalInstructionViewHook(
QuickSeekOverlayFingerprint.injectLiteralInstructionViewCall(
literal,
smaliInstruction
)
@ -742,9 +744,10 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply {
rememberShuffleStateObjectClass = definingClass
val constIndex = getWideLiteralInstructionIndex(45468)
val iGetObjectIndex = getTargetIndexOrThrow(constIndex, Opcode.IGET_OBJECT)
val checkCastIndex = getTargetIndexOrThrow(iGetObjectIndex, Opcode.CHECK_CAST)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(45468)
val iGetObjectIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.IGET_OBJECT)
val checkCastIndex =
indexOfFirstInstructionOrThrow(iGetObjectIndex, Opcode.CHECK_CAST)
val ordinalIndex = indexOfOrdinalInstruction(this)
val imageViewIndex = indexOfImageViewInstruction(this)
@ -888,7 +891,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
// region patch for restore old comments popup panels
OldEngagementPanelFingerprint.result?.let {
OldEngagementPanelFingerprint.literalInstructionBooleanHook(
OldEngagementPanelFingerprint.injectLiteralInstructionBooleanCall(
45427672,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldCommentsPopUpPanels(Z)Z"
)
@ -905,7 +908,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
// region patch for restore old player background
OldPlayerBackgroundFingerprint.result?.let {
OldPlayerBackgroundFingerprint.literalInstructionBooleanHook(
OldPlayerBackgroundFingerprint.injectLiteralInstructionBooleanCall(
45415319,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldPlayerBackground(Z)Z"
)
@ -922,7 +925,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
// region patch for restore old player layout
OldPlayerLayoutFingerprint.result?.let {
OldPlayerLayoutFingerprint.literalInstructionBooleanHook(
OldPlayerLayoutFingerprint.injectLiteralInstructionBooleanCall(
45399578,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldPlayerLayout(Z)Z"
)
@ -943,11 +946,14 @@ object PlayerComponentsPatch : BaseBytecodePatch(
viewId: Long
) {
val miniPlayerPlayPauseReplayButtonIndex =
getWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
indexOfFirstWideLiteralInstructionValueOrThrow(MiniPlayerPlayPauseReplayButton)
val miniPlayerPlayPauseReplayButtonRegister =
getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA
val findViewByIdIndex =
getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL)
indexOfFirstInstructionOrThrow(
miniPlayerPlayPauseReplayButtonIndex,
Opcode.INVOKE_VIRTUAL
)
val parentViewRegister =
getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC
@ -966,11 +972,14 @@ object PlayerComponentsPatch : BaseBytecodePatch(
viewId: Long
) {
val miniPlayerPlayPauseReplayButtonIndex =
getWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
indexOfFirstWideLiteralInstructionValueOrThrow(MiniPlayerPlayPauseReplayButton)
val constRegister =
getInstruction<OneRegisterInstruction>(miniPlayerPlayPauseReplayButtonIndex).registerA
val findViewByIdIndex =
getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_VIRTUAL)
indexOfFirstInstructionOrThrow(
miniPlayerPlayPauseReplayButtonIndex,
Opcode.INVOKE_VIRTUAL
)
val findViewByIdRegister =
getInstruction<FiveRegisterInstruction>(findViewByIdIndex).registerC
@ -986,9 +995,12 @@ object PlayerComponentsPatch : BaseBytecodePatch(
private fun MutableMethod.setViewArray() {
val miniPlayerPlayPauseReplayButtonIndex =
getWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
indexOfFirstWideLiteralInstructionValueOrThrow(MiniPlayerPlayPauseReplayButton)
val invokeStaticIndex =
getTargetIndexOrThrow(miniPlayerPlayPauseReplayButtonIndex, Opcode.INVOKE_STATIC)
indexOfFirstInstructionOrThrow(
miniPlayerPlayPauseReplayButtonIndex,
Opcode.INVOKE_STATIC
)
val viewArrayRegister = getInstruction<FiveRegisterInstruction>(invokeStaticIndex).registerC
addInstructions(
@ -1005,8 +1017,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
methodName: String,
fieldName: String
) {
val startIndex = getStringInstructionIndex(intentString)
val onClickIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val startIndex = indexOfFirstStringInstructionOrThrow(intentString)
val onClickIndex = indexOfFirstInstructionReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickReference = getInstruction<ReferenceInstruction>(onClickIndex).reference
val onClickReferenceDefiningClass = (onClickReference as MethodReference).definingClass
@ -1016,7 +1028,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
onClickClass.methods.find { method -> method.name == "<init>" }
?.apply {
addInstruction(
implementation!!.instructions.size - 1,
implementation!!.instructions.lastIndex,
"sput-object p0, $PLAYER_CLASS_DESCRIPTOR->$fieldName:$onClickReferenceDefiningClass"
)
} ?: throw PatchException("onClickClass not found!")

View File

@ -3,13 +3,13 @@ package app.revanced.patches.music.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ColorGrey
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object MiniPlayerConstructorFingerprint : MethodFingerprint(
returnType = "V",
strings = listOf("sharedToggleMenuItemMutations"),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(ColorGrey)
&& methodDef.containsWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
methodDef.containsWideLiteralInstructionValue(ColorGrey)
&& methodDef.containsWideLiteralInstructionValue(MiniPlayerPlayPauseReplayButton)
}
)

View File

@ -2,7 +2,7 @@ package app.revanced.patches.music.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerPlayPauseReplayButton
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.Opcode
internal object MppWatchWhileLayoutFingerprint : MethodFingerprint(
@ -11,6 +11,6 @@ internal object MppWatchWhileLayoutFingerprint : MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/MppWatchWhileLayout;")
&& methodDef.name == "onFinishInflate"
&& methodDef.containsWideLiteralInstructionIndex(MiniPlayerPlayPauseReplayButton)
&& methodDef.containsWideLiteralInstructionValue(MiniPlayerPlayPauseReplayButton)
}
)

View File

@ -1,13 +1,13 @@
package app.revanced.patches.music.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object MusicActivityWidgetFingerprint : MethodFingerprint(
customFingerprint = handler@{ methodDef, _ ->
if (!methodDef.definingClass.endsWith("/MusicActivity;"))
return@handler false
methodDef.containsWideLiteralInstructionIndex(79500)
methodDef.containsWideLiteralInstructionValue(79500)
}
)

View File

@ -4,14 +4,14 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MiniPlayerViewPager
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerViewPager
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object PlayerViewPagerConstructorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(MiniPlayerViewPager)
&& methodDef.containsWideLiteralInstructionIndex(PlayerViewPager)
methodDef.containsWideLiteralInstructionValue(MiniPlayerViewPager)
&& methodDef.containsWideLiteralInstructionValue(PlayerViewPager)
},
)

View File

@ -3,13 +3,13 @@ package app.revanced.patches.music.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.DarkBackground
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TapBloomView
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object QuickSeekOverlayFingerprint : MethodFingerprint(
returnType = "V",
parameters = emptyList(),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(DarkBackground)
&& methodDef.containsWideLiteralInstructionIndex(TapBloomView)
methodDef.containsWideLiteralInstructionValue(DarkBackground)
&& methodDef.containsWideLiteralInstructionValue(TapBloomView)
},
)

View File

@ -4,7 +4,7 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.player.components.fingerprints.ShuffleClassReferenceFingerprint.indexOfImageViewInstruction
import app.revanced.patches.music.player.components.fingerprints.ShuffleClassReferenceFingerprint.indexOfOrdinalInstruction
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
@ -19,7 +19,7 @@ internal object ShuffleClassReferenceFingerprint : MethodFingerprint(
parameters = emptyList(),
strings = listOf("Unknown shuffle mode"),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(45468) &&
methodDef.containsWideLiteralInstructionValue(45468) &&
indexOfOrdinalInstruction(methodDef) >= 0 &&
indexOfImageViewInstruction(methodDef) >= 0
}

View File

@ -1,60 +0,0 @@
package app.revanced.patches.music.utils.fix.accessibility
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.music.utils.fix.accessibility.fingerprints.TouchExplorationHoverEventFingerprint
import app.revanced.util.containsMethodReferenceNameInstructionIndex
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
object AccessibilityNodeInfoPatch : BytecodePatch(
setOf(TouchExplorationHoverEventFingerprint)
) {
override fun execute(context: BytecodeContext) {
/**
* The "getTouchDelegateInfo" method has been implemented in YT Music v6.44.52.
* For some reason this method sometimes returns null, which throws [IllegalArgumentException].
* This is considered unimplemented code, so remove all methods associated with it.
*/
TouchExplorationHoverEventFingerprint.result?.let {
it.mutableMethod.apply {
// Target instruction is invoke-static, but can also be invoke-virtual.
// Therefore, the opcode is not checked.
val touchExplorationHoverEventMethodIndex =
implementation!!.instructions.indexOfFirst { instruction ->
val reference =
((instruction as? ReferenceInstruction)?.reference as? MethodReference)
((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.definingClass == definingClass
&& reference?.returnType == "Z"
}
// Doesn't raise an exception, even if the target instruction is not found in this method
val touchExplorationHoverEventMethodName =
if (touchExplorationHoverEventMethodIndex > -1)
(getInstruction<ReferenceInstruction>(touchExplorationHoverEventMethodIndex).reference as MethodReference).name
else
"UNDEFINED"
val methods = it.mutableClass.methods
methods.find { method ->
method.name == "getTouchDelegateInfo"
}?.apply {
if (!containsMethodReferenceNameInstructionIndex("isEmpty")) {
arrayOf(
"getTouchDelegateInfo",
name,
touchExplorationHoverEventMethodName
).forEach { methodName ->
methods.removeIf { method ->
method.name == methodName
}
}
}
}
}
} // If this method has not been added, there is no need to remove it, so it will not raise any exceptions.
}
}

View File

@ -1,8 +0,0 @@
package app.revanced.patches.music.utils.fix.accessibility.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
internal object TouchExplorationHoverEventFingerprint : MethodFingerprint(
returnType = "Z",
customFingerprint = { methodDef, _ -> methodDef.name == "onTouchExplorationHoverEvent" }
)

View File

@ -1,16 +1,11 @@
package app.revanced.patches.music.utils.fix.header
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.layout.header.ChangeHeaderPatch
import app.revanced.patches.music.utils.fix.header.fingerprints.HeaderSwitchConfigFingerprint
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import app.revanced.util.injectLiteralInstructionBooleanCall
@Patch(
description = "Fix the issues where new headers are used."
@ -31,19 +26,10 @@ object RestoreOldHeaderPatch : BytecodePatch(
* TODO: Add a new header image file to [ChangeHeaderPatch] later.
*/
HeaderSwitchConfigFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexOrThrow(
getWideLiteralInstructionIndex(45617851),
Opcode.MOVE_RESULT
)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
targetIndex + 1,
"const/4 v$targetRegister, 0x0"
)
}
HeaderSwitchConfigFingerprint.injectLiteralInstructionBooleanCall(
45617851,
"0x0"
)
}
}

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

View File

@ -3,7 +3,6 @@ package app.revanced.patches.music.utils.settings
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.fix.accessibility.AccessibilityNodeInfoPatch
import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceCategory
import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceWithIntent
import app.revanced.patches.music.utils.settings.ResourceUtils.addRVXSettingsPreference
@ -22,10 +21,7 @@ import java.util.concurrent.TimeUnit
object SettingsPatch : BaseResourcePatch(
name = "Settings for YouTube Music",
description = "Applies mandatory patches to implement ReVanced Extended settings into the application.",
dependencies = setOf(
AccessibilityNodeInfoPatch::class,
SettingsBytecodePatch::class
),
dependencies = setOf(SettingsBytecodePatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
requiresIntegrations = true
), Closeable {

View File

@ -14,13 +14,17 @@ import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackC
import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.alsoResolve
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch(
dependencies = [
@ -55,10 +59,9 @@ object SponsorBlockBytecodePatch : BytecodePatch(
/**
* Responsible for seekbar in fullscreen
*/
val seekBarClass = SeekBarConstructorFingerprint.resultOrThrow().mutableClass
SeekbarOnDrawFingerprint.resolve(context, seekBarClass)
SeekbarOnDrawFingerprint.resultOrThrow().let {
SeekbarOnDrawFingerprint.alsoResolve(
context, SeekBarConstructorFingerprint
).let {
it.mutableMethod.apply {
// Initialize seekbar method
addInstructions(
@ -70,7 +73,9 @@ object SponsorBlockBytecodePatch : BytecodePatch(
)
// Set seekbar thickness
val roundIndex = getTargetIndexWithMethodReferenceNameOrThrow("round") + 1
val roundIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "round"
} + 1
val roundRegister = getInstruction<OneRegisterInstruction>(roundIndex).registerA
addInstruction(
roundIndex + 1,
@ -79,8 +84,9 @@ object SponsorBlockBytecodePatch : BytecodePatch(
)
// Draw segment
val drawCircleIndex =
getTargetIndexWithMethodReferenceNameReversedOrThrow("drawCircle")
val drawCircleIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "drawCircle"
}
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction(
drawCircleIndex,
@ -115,7 +121,10 @@ object SponsorBlockBytecodePatch : BytecodePatch(
)
// Draw segment
val drawCircleIndex = getTargetIndexWithMethodReferenceNameOrThrow("drawCircle")
val drawCircleIndex = indexOfFirstInstructionReversedOrThrow {
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.name == "drawCircle"
}
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction(
drawCircleIndex,

View File

@ -26,10 +26,9 @@ import app.revanced.patches.music.video.videoid.VideoIdPatch
import app.revanced.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getReference
import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -216,12 +215,10 @@ object VideoInformationPatch : BytecodePatch(
)
VideoLengthFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val invalidateIndex =
getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversedOrThrow(
invalidateIndex + 1,
"Landroid/graphics/Rect;"
)
val invalidateIndex = VideoLengthFingerprint.indexOfInvalidateInstruction(this)
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
rectangleFieldName =
(getInstruction<ReferenceInstruction>(rectangleIndex).reference as FieldReference).name

View File

@ -1,9 +1,14 @@
package app.revanced.patches.music.video.information.fingerprints
import app.revanced.util.fingerprint.MethodReferenceNameFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint.indexOfInvalidateInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object VideoLengthFingerprint : MethodReferenceNameFingerprint(
internal object VideoLengthFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_WIDE,
@ -12,5 +17,12 @@ internal object VideoLengthFingerprint : MethodReferenceNameFingerprint(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_WIDE
),
reference = { "invalidate" }
)
customFingerprint = { methodDef, _ ->
indexOfInvalidateInstruction(methodDef) >= 0
}
) {
fun indexOfInvalidateInstruction(methodDef: Method) =
methodDef.indexOfFirstInstructionReversed {
getReference<MethodReference>()?.name == "invalidate"
}
}

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

View File

@ -12,12 +12,15 @@ 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.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithFieldReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object AdsPatch : BaseBytecodePatch(
@ -42,7 +45,9 @@ object AdsPatch : BaseBytecodePatch(
// region Filter promoted ads (does not work in popular or latest feed)
AdPostFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getTargetIndexWithFieldReferenceNameOrThrow("children")
val targetIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.name == "children"
}
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
addInstructions(
@ -59,7 +64,10 @@ object AdsPatch : BaseBytecodePatch(
// By removing the appending instruction no ad posts gets appended to the feed.
NewAdPostFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("add")
val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.toString() == "Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z"
}
val targetInstruction = getInstruction<FiveRegisterInstruction>(targetIndex)
replaceInstruction(

View File

@ -9,15 +9,15 @@ 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.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.Reference
@Suppress("unused")
@ -40,20 +40,31 @@ object RecentlyVisitedShelfPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method -> method.name == "<init>" }
?.apply {
val recentlyVisitedFieldIndex =
getTargetIndexWithFieldReferenceNameOrThrow("RECENTLY_VISITED")
val recentlyVisitedFieldIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.name == "RECENTLY_VISITED"
}
val recentlyVisitedObjectIndex =
getTargetIndexOrThrow(recentlyVisitedFieldIndex, Opcode.IPUT_OBJECT)
indexOfFirstInstructionOrThrow(
recentlyVisitedFieldIndex,
Opcode.IPUT_OBJECT
)
recentlyVisitedReference =
getInstruction<ReferenceInstruction>(recentlyVisitedObjectIndex).reference
} ?: throw PatchException("Constructor method not found!")
it.mutableMethod.apply {
val recentlyVisitedObjectIndex =
getTargetIndexWithReferenceOrThrow(recentlyVisitedReference.toString())
val recentlyVisitedObjectIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.toString() == recentlyVisitedReference.toString()
}
arrayOf(
getTargetIndexOrThrow(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC),
getTargetIndexReversedOrThrow(recentlyVisitedObjectIndex, Opcode.INVOKE_STATIC)
indexOfFirstInstructionOrThrow(
recentlyVisitedObjectIndex,
Opcode.INVOKE_STATIC
),
indexOfFirstInstructionReversedOrThrow(
recentlyVisitedObjectIndex,
Opcode.INVOKE_STATIC
)
).forEach { staticIndex ->
val insertRegister =
getInstruction<OneRegisterInstruction>(staticIndex + 1).registerA

View File

@ -3,14 +3,14 @@ package app.revanced.patches.reddit.layout.screenshotpopup.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.ScreenShotShareBanner
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object ScreenshotTakenBannerFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, classDef ->
methodDef.containsWideLiteralInstructionIndex(ScreenShotShareBanner)
methodDef.containsWideLiteralInstructionValue(ScreenShotShareBanner)
&& classDef.sourceFile == "ScreenshotTakenBanner.kt"
}
)

View File

@ -12,7 +12,7 @@ import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.Cancel
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.TextAppearanceRedditBaseOldButtonColored
import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -39,7 +39,8 @@ object SubRedditDialogPatch : BaseBytecodePatch(
FrequentUpdatesSheetScreenFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val cancelButtonViewIndex = getWideLiteralInstructionIndex(CancelButton) + 2
val cancelButtonViewIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(CancelButton) + 2
val cancelButtonViewRegister =
getInstruction<OneRegisterInstruction>(cancelButtonViewIndex).registerA
@ -53,7 +54,9 @@ object SubRedditDialogPatch : BaseBytecodePatch(
RedditAlertDialogsFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex =
getWideLiteralInstructionIndex(TextAppearanceRedditBaseOldButtonColored) + 1
indexOfFirstWideLiteralInstructionValueOrThrow(
TextAppearanceRedditBaseOldButtonColored
) + 1
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerC
addInstruction(

View File

@ -3,14 +3,14 @@ package app.revanced.patches.reddit.layout.subredditdialog.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.CancelButton
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object FrequentUpdatesSheetScreenFingerprint : MethodFingerprint(
returnType = "Landroid/view/View;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, classDef ->
methodDef.containsWideLiteralInstructionIndex(CancelButton)
methodDef.containsWideLiteralInstructionValue(CancelButton)
&& classDef.sourceFile == "FrequentUpdatesSheetScreen.kt"
}
)

View File

@ -3,14 +3,14 @@ package app.revanced.patches.reddit.layout.subredditdialog.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.TextAppearanceRedditBaseOldButtonColored
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object RedditAlertDialogsFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, classDef ->
methodDef.containsWideLiteralInstructionIndex(TextAppearanceRedditBaseOldButtonColored)
methodDef.containsWideLiteralInstructionValue(TextAppearanceRedditBaseOldButtonColored)
&& classDef.sourceFile == "RedditAlertDialogs.kt"
}
)

View File

@ -10,7 +10,7 @@ import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.ToolBarNavSearchCtaContainer
import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -35,7 +35,7 @@ object ToolBarButtonPatch : BaseBytecodePatch(
HomePagerScreenFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex =
getWideLiteralInstructionIndex(ToolBarNavSearchCtaContainer) + 3
indexOfFirstWideLiteralInstructionValueOrThrow(ToolBarNavSearchCtaContainer) + 3
val targetRegister =
getInstruction<OneRegisterInstruction>(targetIndex - 1).registerA

View File

@ -3,7 +3,7 @@ package app.revanced.patches.reddit.layout.toolbar.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.ToolBarNavSearchCtaContainer
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object HomePagerScreenFingerprint : MethodFingerprint(
@ -12,6 +12,6 @@ internal object HomePagerScreenFingerprint : MethodFingerprint(
parameters = listOf("Landroid/view/LayoutInflater;", "Landroid/view/ViewGroup;"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/HomePagerScreen;")
&& methodDef.containsWideLiteralInstructionIndex(ToolBarNavSearchCtaContainer)
&& methodDef.containsWideLiteralInstructionValue(ToolBarNavSearchCtaContainer)
}
)

View File

@ -9,7 +9,7 @@ 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.settings.SettingsBytecodePatch.updateSettingsStatus
import app.revanced.patches.reddit.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
@ -27,7 +27,7 @@ object OpenLinksExternallyPatch : BaseBytecodePatch(
override fun execute(context: BytecodeContext) {
ScreenNavigatorFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getStringInstructionIndex("uri") + 2
val insertIndex = indexOfFirstStringInstructionOrThrow("uri") + 2
addInstructionsWithLabels(
insertIndex, """

View File

@ -15,8 +15,8 @@ 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.SettingsStatusLoadFingerprint
import app.revanced.patches.shared.fingerprints.SharedSettingFingerprint
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -39,7 +39,7 @@ object SettingsBytecodePatch : BytecodePatch(
internal fun updateSettingsLabel(label: String) =
acknowledgementsLabelBuilderMethod.apply {
val insertIndex =
getWideLiteralInstructionIndex(LabelAcknowledgements) + 3
indexOfFirstWideLiteralInstructionValueOrThrow(LabelAcknowledgements) + 3
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA
@ -62,7 +62,7 @@ object SettingsBytecodePatch : BytecodePatch(
*/
SharedSettingFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val stringIndex = getTargetIndexOrThrow(Opcode.CONST_STRING)
val stringIndex = indexOfFirstInstructionOrThrow(Opcode.CONST_STRING)
val stringRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA
replaceInstruction(

View File

@ -3,7 +3,7 @@ package app.revanced.patches.reddit.utils.settings.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.LabelAcknowledgements
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object AcknowledgementsLabelBuilderFingerprint : MethodFingerprint(
@ -12,6 +12,6 @@ internal object AcknowledgementsLabelBuilderFingerprint : MethodFingerprint(
parameters = listOf("Landroidx/preference/Preference;"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.startsWith("Lcom/reddit/screen/settings/preferences/")
&& methodDef.containsWideLiteralInstructionIndex(LabelAcknowledgements)
&& methodDef.containsWideLiteralInstructionValue(LabelAcknowledgements)
}
)

View File

@ -14,8 +14,8 @@ import app.revanced.patches.shared.ads.fingerprints.VideoAdsFingerprint
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -75,7 +75,7 @@ abstract class BaseAdsPatch(
internal fun MethodFingerprintResult.hookNonLithoFullscreenAds(literal: Long) {
mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(literal) + 2
val targetIndex = indexOfFirstWideLiteralInstructionValueOrThrow(literal) + 2
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -8,14 +8,14 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.shared.customspeed.fingerprints.SpeedArrayGeneratorFingerprint
import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFallBackFingerprint
import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFingerprint
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
abstract class BaseCustomPlaybackSpeedPatch(
private val descriptor: String,
@ -39,7 +39,9 @@ abstract class BaseCustomPlaybackSpeedPatch(
"""
)
val sizeIndex = getTargetIndexWithMethodReferenceNameOrThrow("size") + 1
val sizeIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "size"
} + 1
val sizeRegister = getInstruction<OneRegisterInstruction>(sizeIndex).registerA
addInstructions(
@ -49,7 +51,9 @@ abstract class BaseCustomPlaybackSpeedPatch(
"""
)
val arrayIndex = getTargetIndexWithFieldReferenceTypeOrThrow("[F")
val arrayIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.type == "[F"
}
val arrayRegister = getInstruction<OneRegisterInstruction>(arrayIndex).registerA
addInstructions(
@ -73,7 +77,7 @@ abstract class BaseCustomPlaybackSpeedPatch(
val limiterMinConstIndex =
indexOfFirstInstructionOrThrow { (this as? NarrowLiteralInstruction)?.narrowLiteral == 0.25f.toRawBits() }
val limiterMaxConstIndex =
getTargetIndexOrThrow(limiterMinConstIndex + 1, Opcode.CONST_HIGH16)
indexOfFirstInstructionOrThrow(limiterMinConstIndex + 1, Opcode.CONST_HIGH16)
val limiterMinConstDestination =
getInstruction<OneRegisterInstruction>(limiterMinConstIndex).registerA

View File

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

View File

@ -6,9 +6,11 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.drawable.fingerprints.DrawableFingerprint
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
object DrawableColorPatch : BytecodePatch(
setOf(DrawableFingerprint)
@ -17,26 +19,26 @@ object DrawableColorPatch : BytecodePatch(
DrawableFingerprint.resultOrThrow().mutableMethod.apply {
insertMethod = this
insertIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("setColor")
insertIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "setColor"
}
insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
}
}
private var offset = 0
private lateinit var insertMethod: MutableMethod
private var insertIndex: Int = 0
private var insertRegister: Int = 0
private lateinit var insertMethod: MutableMethod
private var offset = 0
fun injectCall(
methodDescriptor: String
) {
insertMethod.addInstructions(
insertIndex + offset, """
invoke-static {v$insertRegister}, $methodDescriptor
move-result v$insertRegister
"""
invoke-static {v$insertRegister}, $methodDescriptor
move-result v$insertRegister
"""
)
offset += 2
}

View File

@ -18,14 +18,12 @@ import app.revanced.patches.shared.gms.fingerprints.CastContextFetchFingerprint
import app.revanced.patches.shared.gms.fingerprints.CastDynamiteModuleFingerprint
import app.revanced.patches.shared.gms.fingerprints.CastDynamiteModuleV2Fingerprint
import app.revanced.patches.shared.gms.fingerprints.CertificateFingerprint
import app.revanced.patches.shared.gms.fingerprints.CertificateFingerprint.GET_PACKAGE_NAME_METHOD_REFERENCE
import app.revanced.patches.shared.gms.fingerprints.GmsCoreSupportFingerprint
import app.revanced.patches.shared.gms.fingerprints.GooglePlayUtilityFingerprint
import app.revanced.patches.shared.gms.fingerprints.PrimeMethodFingerprint
import app.revanced.patches.shared.gms.fingerprints.ServiceCheckFingerprint
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.util.getReference
import app.revanced.util.getTargetIndexWithReference
import app.revanced.util.resultOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.Opcode
@ -178,7 +176,7 @@ abstract class BaseGmsCoreSupportPatch(
CertificateFingerprint.result?.mutableClass?.methods?.forEach { mutableMethod ->
mutableMethod.apply {
val getPackageNameIndex =
getTargetIndexWithReference(GET_PACKAGE_NAME_METHOD_REFERENCE)
CertificateFingerprint.indexOfGetPackageNameInstruction(this)
if (getPackageNameIndex > -1) {
val targetRegister =

View File

@ -1,20 +1,28 @@
package app.revanced.patches.shared.gms.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.shared.gms.fingerprints.CertificateFingerprint.GET_PACKAGE_NAME_METHOD_REFERENCE
import app.revanced.util.fingerprint.ReferenceFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.shared.gms.fingerprints.CertificateFingerprint.indexOfGetPackageNameInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
/**
* Method which the package name is used to check the app signature.
*/
internal object CertificateFingerprint : ReferenceFingerprint(
internal object CertificateFingerprint : MethodFingerprint(
returnType = "Ljava/lang/String;",
accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = emptyList(),
strings = listOf("X.509", "user", "S"),
reference = { GET_PACKAGE_NAME_METHOD_REFERENCE }
customFingerprint = { methodDef, _ ->
indexOfGetPackageNameInstruction(methodDef) >= 0
}
) {
const val GET_PACKAGE_NAME_METHOD_REFERENCE =
"Landroid/content/Context;->getPackageName()Ljava/lang/String;"
fun indexOfGetPackageNameInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
getReference<MethodReference>()?.toString() == "Landroid/content/Context;->getPackageName()Ljava/lang/String;"
}
}

View File

@ -16,9 +16,9 @@ import app.revanced.patches.shared.litho.fingerprints.ByteBufferFingerprint
import app.revanced.patches.shared.litho.fingerprints.EmptyComponentsFingerprint
import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
@ -127,7 +127,7 @@ object LithoFilterPatch : BytecodePatch(
val stringBuilderRegister =
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
val emptyStringIndex = getStringInstructionIndex("")
val emptyStringIndex = indexOfFirstStringInstructionOrThrow("")
val identifierRegister = getInstruction<TwoRegisterInstruction>(
indexOfFirstInstructionReversedOrThrow(emptyStringIndex) {
opcode == Opcode.IPUT_OBJECT

View File

@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import kotlin.properties.Delegates
@ -38,7 +38,8 @@ abstract class BaseMainActivityResolvePatch(
// set onBackPressed method
onBackPressedMethod = getMethod("onBackPressed")
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndexOrThrow(Opcode.RETURN_VOID)
onBackPressedMethodIndex =
onBackPressedMethod.indexOfFirstInstructionOrThrow(Opcode.RETURN_VOID)
// set onConfigurationChanged method
onConfigurationChangedMethod = getMethod("onConfigurationChanged")

View File

@ -7,11 +7,13 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.opus.fingerprints.CodecReferenceFingerprint
import app.revanced.patches.shared.opus.fingerprints.CodecSelectorFingerprint
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.reference.Reference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
/**
* This patch is generally not required for the latest versions of YouTube and YouTube Music.
@ -25,15 +27,14 @@ abstract class BaseOpusCodecsPatch(
CodecSelectorFingerprint
)
) {
private lateinit var opusCodecReference: Reference
override fun execute(context: BytecodeContext) {
CodecReferenceFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getTargetIndexWithReferenceOrThrow("Ljava/util/Set;")
opusCodecReference = getInstruction<ReferenceInstruction>(targetIndex).reference
val opusCodecReference = with(CodecReferenceFingerprint.resultOrThrow().mutableMethod) {
val codecIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_STATIC &&
getReference<MethodReference>()?.returnType == "Ljava/util/Set;"
}
getInstruction<ReferenceInstruction>(codecIndex).reference
}
CodecSelectorFingerprint.resultOrThrow().let {

View File

@ -8,9 +8,11 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.patches.shared.settingmenu.fingerprints.SettingsMenuFingerprint
import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
@Patch(
description = "Hide the settings menu for YouTube or YouTube Music.",
@ -25,8 +27,9 @@ object SettingsMenuPatch : BytecodePatch(
override fun execute(context: BytecodeContext) {
SettingsMenuFingerprint.resultOrThrow().mutableMethod.apply {
val insertIndex =
getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;")
val insertIndex = indexOfFirstInstructionOrThrow {
getReference<FieldReference>()?.type == "Landroid/support/v7/widget/RecyclerView;"
}
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
addInstruction(

View File

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

View File

@ -2,7 +2,7 @@ package app.revanced.patches.youtube.ads.general.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SlidingDialogAnimation
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.Opcode
internal object ShowDialogCommandFingerprint : MethodFingerprint(
@ -16,7 +16,7 @@ internal object ShowDialogCommandFingerprint : MethodFingerprint(
// 18.43 and earlier has a different first parameter.
// Since this fingerprint is somewhat weak, work around by checking for both method parameter signatures.
customFingerprint = custom@{ methodDef, _ ->
if (!methodDef.containsWideLiteralInstructionIndex(SlidingDialogAnimation)) {
if (!methodDef.containsWideLiteralInstructionValue(SlidingDialogAnimation)) {
return@custom false
}
// 18.43 and earlier parameters are: "L", "L"

View File

@ -33,11 +33,10 @@ import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CaptionToggleContainer
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -113,8 +112,8 @@ object FeedComponentsPatch : BaseBytecodePatch(
// region patch for hide caption button
CaptionsButtonFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer)
val insertIndex = getTargetIndexReversedOrThrow(constIndex, Opcode.IF_EQZ)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(CaptionToggleContainer)
val insertIndex = indexOfFirstInstructionReversedOrThrow(constIndex, Opcode.IF_EQZ)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
@ -126,8 +125,8 @@ object FeedComponentsPatch : BaseBytecodePatch(
}
CaptionsButtonSyntheticFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(CaptionToggleContainer)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(CaptionToggleContainer)
val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.MOVE_RESULT_OBJECT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -198,7 +197,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
&& reference.returnType.startsWith("L")
}
val objectIndex = getTargetIndexOrThrow(Opcode.MOVE_OBJECT)
val objectIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_OBJECT)
val objectRegister = getInstruction<TwoRegisterInstruction>(objectIndex).registerA
val jumpIndex = it.scanResult.patternScanResult!!.startIndex
@ -253,7 +252,9 @@ object FeedComponentsPatch : BaseBytecodePatch(
ChannelTabRendererFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val iteratorIndex = getTargetIndexWithMethodReferenceName("hasNext")
val iteratorIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "hasNext"
}
val iteratorRegister =
getInstruction<FiveRegisterInstruction>(iteratorIndex).registerC
@ -265,7 +266,8 @@ object FeedComponentsPatch : BaseBytecodePatch(
&& reference.parameterTypes == channelTabBuilderMethod.parameterTypes
}
val objectIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.IGET_OBJECT)
val objectIndex =
indexOfFirstInstructionReversedOrThrow(targetIndex, Opcode.IGET_OBJECT)
val objectInstruction = getInstruction<TwoRegisterInstruction>(objectIndex)
val objectReference = getInstruction<ReferenceInstruction>(objectIndex).reference

View File

@ -7,7 +7,7 @@ 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.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
@ -15,6 +15,7 @@ import com.android.tools.smali.dexlib2.Opcode
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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object AudioTracksPatch : BaseBytecodePatch(
@ -32,15 +33,14 @@ object AudioTracksPatch : BaseBytecodePatch(
opcode == Opcode.CHECK_CAST
&& (this as ReferenceInstruction).reference.toString() == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;"
}
val arrayListIndex = getTargetIndexWithReferenceOrThrow(
formatStreamModelIndex,
"Ljava/util/List;->add(Ljava/lang/Object;)Z"
)
val insertIndex =
getTargetIndexWithReferenceOrThrow(
arrayListIndex,
"Ljava/util/List;->isEmpty()Z"
) + 2
val arrayListIndex = indexOfFirstInstructionOrThrow(formatStreamModelIndex) {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.toString() == "Ljava/util/List;->add(Ljava/lang/Object;)Z"
}
val insertIndex = indexOfFirstInstructionOrThrow(arrayListIndex) {
opcode == Opcode.INVOKE_INTERFACE &&
getReference<MethodReference>()?.toString() == "Ljava/util/List;->isEmpty()Z"
} + 2
val formatStreamModelRegister =
getInstruction<OneRegisterInstruction>(formatStreamModelIndex).registerA

View File

@ -27,9 +27,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_D
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceName
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -37,6 +37,7 @@ 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.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
@Suppress("unused")
@ -171,10 +172,13 @@ object LayoutComponentsPatch : BaseBytecodePatch(
AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AccountSwitcherAccessibility)
val insertIndex = getTargetIndexOrThrow(constIndex, Opcode.IF_EQZ)
val setVisibilityIndex =
getTargetIndexWithMethodReferenceName(insertIndex, "setVisibility")
val constIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(AccountSwitcherAccessibility)
val insertIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.IF_EQZ)
val setVisibilityIndex = indexOfFirstInstructionOrThrow(insertIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setVisibility"
}
val visibilityRegister =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex).registerD
@ -209,8 +213,8 @@ object LayoutComponentsPatch : BaseBytecodePatch(
// region patch for hide tooltip content
TooltipContentFullscreenFingerprint.resultOrThrow().mutableMethod.apply {
val literalIndex = getWideLiteralInstructionIndex(45384061)
val targetIndex = getTargetIndexOrThrow(literalIndex, Opcode.MOVE_RESULT)
val literalIndex = indexOfFirstWideLiteralInstructionValueOrThrow(45384061)
val targetIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

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

View File

@ -6,7 +6,7 @@ import app.revanced.patches.youtube.general.loadingscreen.fingerprints.GradientL
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.settings.SettingsPatch
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
@Suppress("unused")
@ -29,7 +29,7 @@ object GradientLoadingScreenPatch : BaseBytecodePatch(
GradientLoadingScreenPrimaryFingerprint to 45412406,
GradientLoadingScreenSecondaryFingerprint to 45418917
).forEach { (fingerprint, literal) ->
fingerprint.literalInstructionBooleanHook(
fingerprint.injectLiteralInstructionBooleanCall(
literal,
"$GENERAL_CLASS_DESCRIPTOR->enableGradientLoadingScreen()Z"
)

View File

@ -44,8 +44,8 @@ import app.revanced.util.fingerprint.LiteralValueFingerprint
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfWideLiteralInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.AccessFlags
@ -170,7 +170,7 @@ object MiniplayerPatch : BaseBytecodePatch(
}
if (SettingsPatch.upward1925) {
MiniplayerModernEnabledFingerprint.literalInstructionBooleanHook(
MiniplayerModernEnabledFingerprint.injectLiteralInstructionBooleanCall(
45622882,
"$INTEGRATIONS_CLASS_DESCRIPTOR->getModernMiniplayerOverride(Z)Z"
)
@ -181,11 +181,11 @@ object MiniplayerPatch : BaseBytecodePatch(
// region Enable double tap action.
if (SettingsPatch.upward1925) {
MiniplayerModernConstructorFingerprint.literalInstructionBooleanHook(
MiniplayerModernConstructorFingerprint.injectLiteralInstructionBooleanCall(
45628823,
"$INTEGRATIONS_CLASS_DESCRIPTOR->enableMiniplayerDoubleTapAction()Z"
)
MiniplayerModernConstructorFingerprint.literalInstructionBooleanHook(
MiniplayerModernConstructorFingerprint.injectLiteralInstructionBooleanCall(
45630429,
"$INTEGRATIONS_CLASS_DESCRIPTOR->getModernMiniplayerOverride(Z)Z"
)
@ -211,7 +211,8 @@ object MiniplayerPatch : BaseBytecodePatch(
YtOutlinePictureInPictureWhite to YtOutlineXWhite,
YtOutlineXWhite to YtOutlinePictureInPictureWhite,
).forEach { (originalResource, replacementResource) ->
val imageResourceIndex = indexOfWideLiteralInstructionOrThrow(originalResource)
val imageResourceIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(originalResource)
val register =
getInstruction<OneRegisterInstruction>(imageResourceIndex).registerA
@ -321,7 +322,7 @@ object MiniplayerPatch : BaseBytecodePatch(
// region Enable drag and drop.
if (SettingsPatch.upward1923) {
MiniplayerModernDragAndDropFingerprint.literalInstructionBooleanHook(
MiniplayerModernDragAndDropFingerprint.injectLiteralInstructionBooleanCall(
45628752,
"$INTEGRATIONS_CLASS_DESCRIPTOR->enableMiniplayerDragAndDrop()Z"
)
@ -388,7 +389,7 @@ object MiniplayerPatch : BaseBytecodePatch(
) {
resultOrThrow().mutableMethod.apply {
val imageViewIndex = indexOfFirstInstructionOrThrow(
indexOfWideLiteralInstructionOrThrow(literalValue)
indexOfFirstWideLiteralInstructionValueOrThrow(literalValue)
) {
opcode == Opcode.CHECK_CAST && getReference<TypeReference>()?.type == hookedClassType
}

View File

@ -4,7 +4,7 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.general.miniplayer.fingerprints.MiniplayerModernConstructorFingerprint.constructorMethodCount
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.util.MethodUtil
@ -13,7 +13,7 @@ internal object MiniplayerModernConstructorFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf("L"),
customFingerprint = custom@{ methodDef, classDef ->
if (!methodDef.containsWideLiteralInstructionIndex(45623000)) // Magic number found in the constructor.
if (!methodDef.containsWideLiteralInstructionValue(45623000)) // Magic number found in the constructor.
return@custom false
classDef.methods.forEach {
@ -24,8 +24,8 @@ internal object MiniplayerModernConstructorFingerprint : MethodFingerprint(
return@custom true
// Double tap action (Used in YouTube 19.25.39+).
methodDef.containsWideLiteralInstructionIndex(45628823)
&& methodDef.containsWideLiteralInstructionIndex(45630429)
methodDef.containsWideLiteralInstructionValue(45628823)
&& methodDef.containsWideLiteralInstructionValue(45630429)
}
) {
private var constructorMethodCount = 0

View File

@ -13,13 +13,16 @@ import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PAC
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.reference.MethodReference
@Suppress("unused")
object NavigationBarComponentsPatch : BaseBytecodePatch(
@ -48,7 +51,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
// region patch for enable translucent navigation bar
if (SettingsPatch.upward1923) {
TranslucentNavigationBarFingerprint.literalInstructionBooleanHook(
TranslucentNavigationBarFingerprint.injectLiteralInstructionBooleanCall(
45630927,
"$GENERAL_CLASS_DESCRIPTOR->enableTranslucentNavigationBar()Z"
)
@ -85,7 +88,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
AutoMotiveFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getStringInstructionIndex("Android Automotive") - 1
val insertIndex = indexOfFirstStringInstructionOrThrow("Android Automotive") - 1
val register = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
@ -103,7 +106,10 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
PivotBarSetTextFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setText"
}
val targetRegister = getInstruction<FiveRegisterInstruction>(targetIndex).registerC
addInstruction(

View File

@ -2,13 +2,13 @@ package app.revanced.patches.youtube.general.splashanimation.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.DarkSplashAnimation
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object SplashAnimationFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Landroid/os/Bundle;"),
customFingerprint = { methodDef, _ ->
methodDef.name == "onCreate"
&& methodDef.containsWideLiteralInstructionIndex(DarkSplashAnimation)
&& methodDef.containsWideLiteralInstructionValue(DarkSplashAnimation)
}
)

View File

@ -2,7 +2,7 @@ package app.revanced.patches.youtube.general.splashanimation.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object StartUpResourceIdFingerprint : MethodFingerprint(
@ -10,7 +10,7 @@ internal object StartUpResourceIdFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("I"),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(3)
&& methodDef.containsWideLiteralInstructionIndex(4)
methodDef.containsWideLiteralInstructionValue(3)
&& methodDef.containsWideLiteralInstructionValue(4)
}
)

View File

@ -39,16 +39,16 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.alsoResolve
import app.revanced.util.doRecursively
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getTargetIndexWithReferenceReversedOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionHook
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.replaceLiteralInstructionCall
import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus
import com.android.tools.smali.dexlib2.Opcode
@ -106,7 +106,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
YtPremiumWordMarkHeader,
YtWordMarkHeader
).forEach { literal ->
context.literalInstructionHook(literal, smaliInstruction)
context.replaceLiteralInstructionCall(literal, smaliInstruction)
}
// YouTube's headers have the form of AttributeSet, which is decoded from YouTube's built-in classes.
@ -125,13 +125,11 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
)
// The sidebar's header is lithoView. Add a listener to change it.
DrawerContentViewFingerprint.resolve(
context,
DrawerContentViewConstructorFingerprint.resultOrThrow().classDef
)
DrawerContentViewFingerprint.resultOrThrow().let {
DrawerContentViewFingerprint.alsoResolve(
context, DrawerContentViewConstructorFingerprint
).let {
it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val insertIndex = DrawerContentViewFingerprint.indexOfAddViewInstruction(this)
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstruction(
@ -147,7 +145,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
setActionBarRingoMutableClass.methods.first { method ->
MethodUtil.isConstructor(method)
}.apply {
val insertIndex = getTargetIndexOrThrow(Opcode.IPUT_BOOLEAN)
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IPUT_BOOLEAN)
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
addInstruction(
@ -172,7 +170,8 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
ActionBarRingoBackgroundFingerprint.resultOrThrow().let {
ActionBarRingoTextFingerprint.resolve(context, it.classDef)
it.mutableMethod.apply {
val viewIndex = getWideLiteralInstructionIndex(ActionBarRingoBackground) + 2
val viewIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(ActionBarRingoBackground) + 2
val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA
addInstructions(
@ -281,16 +280,16 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
CreateSearchSuggestionsFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val relativeIndex = getWideLiteralInstructionIndex(40)
val replaceIndex = getTargetIndexWithReferenceReversedOrThrow(
relativeIndex,
"Landroid/widget/ImageView;->setVisibility(I)V"
) - 1
val relativeIndex = indexOfFirstWideLiteralInstructionValueOrThrow(40)
val replaceIndex = indexOfFirstInstructionReversedOrThrow(relativeIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == "Landroid/widget/ImageView;->setVisibility(I)V"
} - 1
val jumpIndex = getTargetIndexWithReferenceOrThrow(
relativeIndex,
"Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;"
) + 4
val jumpIndex = indexOfFirstInstructionOrThrow(relativeIndex) {
opcode == Opcode.INVOKE_STATIC &&
getReference<MethodReference>()?.toString() == "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;"
} + 4
val replaceIndexInstruction = getInstruction<TwoRegisterInstruction>(replaceIndex)
val replaceIndexReference =
@ -313,7 +312,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
// region patch for hide voice search button
if (SettingsPatch.upward1928) {
ImageSearchButtonConfigFingerprint.literalInstructionBooleanHook(
ImageSearchButtonConfigFingerprint.injectLiteralInstructionBooleanCall(
45617544,
"$GENERAL_CLASS_DESCRIPTOR->hideImageSearchButton(Z)Z"
)
@ -327,15 +326,15 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
// region patch for hide voice search button
SearchBarFingerprint.resolve(
context,
SearchBarParentFingerprint.resultOrThrow().classDef
)
SearchBarFingerprint.resultOrThrow().let {
SearchBarFingerprint.alsoResolve(
context, SearchBarParentFingerprint
).let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setVisibility")
val setVisibilityIndex = indexOfFirstInstructionOrThrow(startIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setVisibility"
}
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)
@ -349,12 +348,11 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
SearchResultFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(VoiceSearch)
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow(
startIndex,
"setOnClickListener"
)
val startIndex = indexOfFirstWideLiteralInstructionValueOrThrow(VoiceSearch)
val setOnClickListenerIndex = indexOfFirstInstructionOrThrow(startIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC
@ -370,7 +368,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
// region patch for replace create button
CreateButtonDrawableFingerprint.resultOrThrow().mutableMethod.apply {
val index = getWideLiteralInstructionIndex(YtOutlineVideoCamera)
val index = indexOfFirstWideLiteralInstructionValueOrThrow(YtOutlineVideoCamera)
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(

View File

@ -3,7 +3,7 @@ package app.revanced.patches.youtube.general.toolbar.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoBackgroundFingerprint.indexOfStaticInstruction
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ActionBarRingoBackground
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
@ -13,7 +13,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object ActionBarRingoBackgroundFingerprint : MethodFingerprint(
returnType = "Landroid/view/View;",
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(ActionBarRingoBackground) &&
methodDef.containsWideLiteralInstructionValue(ActionBarRingoBackground) &&
indexOfStaticInstruction(methodDef) >= 0
}
) {

View File

@ -1,9 +1,14 @@
package app.revanced.patches.youtube.general.toolbar.fingerprints
import app.revanced.util.fingerprint.MethodReferenceNameFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.DrawerContentViewFingerprint.indexOfAddViewInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object DrawerContentViewFingerprint : MethodReferenceNameFingerprint(
internal object DrawerContentViewFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L"),
opcodes = listOf(
@ -12,5 +17,13 @@ internal object DrawerContentViewFingerprint : MethodReferenceNameFingerprint(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
),
reference = { "addView" }
)
customFingerprint = { methodDef, _ ->
indexOfAddViewInstruction(methodDef) >= 0
}
) {
fun indexOfAddViewInstruction(methodDef: Method) =
methodDef.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "addView"
}
}

View File

@ -1,9 +1,12 @@
package app.revanced.patches.youtube.general.toolbar.fingerprints
import app.revanced.util.fingerprint.MethodReferenceNameFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
object SearchBarFingerprint : MethodReferenceNameFingerprint(
object SearchBarFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Ljava/lang/String;"),
opcodes = listOf(
@ -12,5 +15,9 @@ object SearchBarFingerprint : MethodReferenceNameFingerprint(
Opcode.IGET_BOOLEAN,
Opcode.IF_EQZ
),
reference = { "isEmpty" }
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstructionReversed {
getReference<MethodReference>()?.name == "isEmpty"
} >= 0
}
)

View File

@ -17,8 +17,24 @@ object TranslationsPatch : BaseResourcePatch(
) {
// Array of supported translations, each represented by its language code.
private val TRANSLATIONS = arrayOf(
"ar", "bg-rBG", "de-rDE", "el-rGR", "es-rES", "fr-rFR", "hu-rHU", "it-rIT", "ja-rJP", "ko-rKR",
"pl-rPL", "pt-rBR", "ru-rRU", "tr-rTR", "uk-rUA", "vi-rVN", "zh-rCN", "zh-rTW"
"ar",
"bg-rBG",
"de-rDE",
"el-rGR",
"es-rES",
"fr-rFR",
"hu-rHU",
"it-rIT",
"ja-rJP",
"ko-rKR",
"pl-rPL",
"pt-rBR",
"ru-rRU",
"tr-rTR",
"uk-rUA",
"vi-rVN",
"zh-rCN",
"zh-rTW"
)
private var CustomTranslations by stringPatchOption(

View File

@ -144,7 +144,8 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
else -> null
}
if (drawableName == EMPTY_ICON &&
ApplyToAll == false) return@loop
ApplyToAll == false
) return@loop
drawableName?.let {
node.setAttribute("android:icon", "@drawable/$it")

View File

@ -8,10 +8,13 @@ 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.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object OpenLinksDirectlyPatch : BaseBytecodePatch(
@ -32,7 +35,10 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch(
).forEach { fingerprint ->
fingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("parse")
val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_STATIC &&
getReference<MethodReference>()?.name == "parse"
}
val insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerC

View File

@ -13,8 +13,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -46,8 +46,8 @@ object ShareSheetPatch : BaseBytecodePatch(
// Detects that the Share sheet panel has been invoked.
BottomSheetRecyclerViewFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(BottomSheetRecyclerView)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(BottomSheetRecyclerView)
val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -10,10 +10,10 @@ import app.revanced.patches.youtube.player.ambientmode.fingerprints.PowerSaveMod
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.settings.SettingsPatch
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -46,12 +46,12 @@ object AmbientModeSwitchPatch : BaseBytecodePatch(
).forEach { (fingerprint, reversed) ->
fingerprint.resultOrThrow().mutableMethod.apply {
val stringIndex =
getStringInstructionIndex("android.os.action.POWER_SAVE_MODE_CHANGED")
indexOfFirstStringInstructionOrThrow("android.os.action.POWER_SAVE_MODE_CHANGED")
val targetIndex =
if (reversed)
getTargetIndexReversedOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
indexOfFirstInstructionReversedOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
else
getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
indexOfFirstInstructionOrThrow(stringIndex, Opcode.INVOKE_DIRECT)
val targetClass =
(getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference).definingClass
@ -87,7 +87,7 @@ object AmbientModeSwitchPatch : BaseBytecodePatch(
// region patch for disable ambient mode in fullscreen
AmbientModeInFullscreenFingerprint.literalInstructionBooleanHook(
AmbientModeInFullscreenFingerprint.injectLiteralInstructionBooleanCall(
45389368,
"$PLAYER_CLASS_DESCRIPTOR->disableAmbientModeInFullscreen()Z"
)

View File

@ -24,8 +24,8 @@ 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.TitleAnchor
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -63,9 +63,10 @@ object PlayerButtonsPatch : BaseBytecodePatch(
LayoutConstructorFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AutoNavToggle)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(AutoNavToggle)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex =
indexOfFirstInstructionOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
addInstructionsWithLabels(
constIndex, """
@ -124,9 +125,9 @@ object PlayerButtonsPatch : BaseBytecodePatch(
// region patch for hide collapse button
TitleAnchorFingerprint.resultOrThrow().mutableMethod.apply {
val titleAnchorConstIndex = getWideLiteralInstructionIndex(TitleAnchor)
val titleAnchorConstIndex = indexOfFirstWideLiteralInstructionValueOrThrow(TitleAnchor)
val titleAnchorIndex =
getTargetIndexOrThrow(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
indexOfFirstInstructionOrThrow(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
val titleAnchorRegister =
getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA
@ -136,9 +137,9 @@ object PlayerButtonsPatch : BaseBytecodePatch(
)
val playerCollapseButtonConstIndex =
getWideLiteralInstructionIndex(PlayerCollapseButton)
indexOfFirstWideLiteralInstructionValueOrThrow(PlayerCollapseButton)
val playerCollapseButtonIndex =
getTargetIndexOrThrow(playerCollapseButtonConstIndex, Opcode.CHECK_CAST)
indexOfFirstInstructionOrThrow(playerCollapseButtonConstIndex, Opcode.CHECK_CAST)
val playerCollapseButtonRegister =
getInstruction<OneRegisterInstruction>(playerCollapseButtonIndex).registerA
@ -159,7 +160,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
(instruction.value as? WideLiteralInstruction)?.wideLiteral == FullScreenButton
}
val constIndex = buttonCalls.elementAt(buttonCalls.size - 1).index
val castIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val castIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val insertIndex = castIndex + 1
val insertRegister = getInstruction<OneRegisterInstruction>(castIndex).registerA
@ -180,7 +181,7 @@ object PlayerButtonsPatch : BaseBytecodePatch(
PlayerControlsVisibilityModelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val callIndex = getTargetIndexOrThrow(Opcode.INVOKE_DIRECT_RANGE)
val callIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT_RANGE)
val callInstruction = getInstruction<Instruction3rc>(callIndex)
val hasNextParameterRegister = callInstruction.startRegister + HAS_NEXT

View File

@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CfFullscreenButton
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FadeDurationFast
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullScreenButton
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object FullScreenButtonFingerprint : MethodFingerprint(
@ -13,10 +13,10 @@ internal object FullScreenButtonFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/View;"),
customFingerprint = handler@{ methodDef, _ ->
if (!methodDef.containsWideLiteralInstructionIndex(FullScreenButton))
if (!methodDef.containsWideLiteralInstructionValue(FullScreenButton))
return@handler false
methodDef.containsWideLiteralInstructionIndex(FadeDurationFast) // YouTube 18.29.38 ~ YouTube 19.18.41
|| methodDef.containsWideLiteralInstructionIndex(CfFullscreenButton) // YouTube 19.19.39 ~
methodDef.containsWideLiteralInstructionValue(FadeDurationFast) // YouTube 18.29.38 ~ YouTube 19.18.41
|| methodDef.containsWideLiteralInstructionValue(CfFullscreenButton) // YouTube 19.19.39 ~
},
)

View File

@ -3,12 +3,12 @@ package app.revanced.patches.youtube.player.buttons.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.PlayerCollapseButton
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TitleAnchor
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object TitleAnchorFingerprint : MethodFingerprint(
returnType = "V",
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(PlayerCollapseButton)
&& methodDef.containsWideLiteralInstructionIndex(TitleAnchor)
methodDef.containsWideLiteralInstructionValue(PlayerCollapseButton)
&& methodDef.containsWideLiteralInstructionValue(TitleAnchor)
}
)

View File

@ -12,9 +12,9 @@ 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.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -56,14 +56,15 @@ object CommentsComponentPatch : BaseBytecodePatch(
ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492)
val emojiPickerEndpointIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(126326492)
val emojiPickerOnClickListenerIndex =
getTargetIndexOrThrow(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
indexOfFirstInstructionOrThrow(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
val emojiPickerOnClickListenerMethod =
getWalkerMethod(context, emojiPickerOnClickListenerIndex)
emojiPickerOnClickListenerMethod.apply {
val insertIndex = getTargetIndexOrThrow(Opcode.IF_EQZ)
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IF_EQZ)
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA

View File

@ -48,11 +48,11 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TapBl
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionViewHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionViewCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -61,6 +61,7 @@ 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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object PlayerComponentsPatch : BaseBytecodePatch(
@ -107,8 +108,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(ScrimOverlay)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(ScrimOverlay)
val targetIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val targetParameter = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
@ -144,7 +145,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
if (fingerprint == StartVideoInformerFingerprint) {
hookInitVideoPanel(1)
} else {
val syntheticIndex = getTargetIndexOrThrow(Opcode.NEW_INSTANCE)
val syntheticIndex =
indexOfFirstInstructionOrThrow(opcode = Opcode.NEW_INSTANCE)
val syntheticReference =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
val syntheticClass =
@ -228,7 +230,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
DarkBackground,
TapBloomView
).forEach { literal ->
QuickSeekOverlayFingerprint.literalInstructionViewHook(
QuickSeekOverlayFingerprint.injectLiteralInstructionViewCall(
literal,
smaliInstruction
)
@ -273,10 +275,10 @@ object PlayerComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(FadeDurationFast)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(FadeDurationFast)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val insertIndex =
getTargetIndexReversedOrThrow(constIndex, Opcode.INVOKE_VIRTUAL) + 1
indexOfFirstInstructionReversedOrThrow(constIndex, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex = implementation!!.instructions.let { instruction ->
insertIndex + instruction.subList(insertIndex, instruction.size - 1)
.indexOfFirst { instructions ->
@ -341,11 +343,14 @@ object PlayerComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val insertIndex = getWideLiteralInstructionIndex(SeekUndoEduOverlayStub)
val insertIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(SeekUndoEduOverlayStub)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val onClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow(insertIndex, "setOnClickListener")
val onClickListenerIndex = indexOfFirstInstructionOrThrow(insertIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val constComponent = getConstComponent(insertIndex, onClickListenerIndex - 1)
if (constComponent.isNotEmpty()) {
@ -390,8 +395,10 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method ->
method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;")
}?.apply {
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setOnClickListener")
val setOnClickListenerIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val setOnClickListenerRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

View File

@ -3,13 +3,13 @@ package app.revanced.patches.youtube.player.components.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.DarkBackground
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TapBloomView
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
internal object QuickSeekOverlayFingerprint : MethodFingerprint(
returnType = "V",
parameters = emptyList(),
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(DarkBackground)
&& methodDef.containsWideLiteralInstructionIndex(TapBloomView)
methodDef.containsWideLiteralInstructionValue(DarkBackground)
&& methodDef.containsWideLiteralInstructionValue(TapBloomView)
},
)

View File

@ -20,10 +20,14 @@ import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.alsoResolve
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object DescriptionComponentsPatch : BaseBytecodePatch(
@ -54,23 +58,23 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
// In order to maintain compatibility with YouTube v18.48.39 or previous versions,
// This patch is applied only to the version after YouTube v18.49.37.
if (SettingsPatch.upward1849) {
RollingNumberTextViewAnimationUpdateFingerprint.resolve(
context,
RollingNumberTextViewFingerprint.resultOrThrow().classDef
)
RollingNumberTextViewAnimationUpdateFingerprint.resultOrThrow().let {
RollingNumberTextViewAnimationUpdateFingerprint.alsoResolve(
context, RollingNumberTextViewFingerprint
).let {
it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2
val imageSpanIndex = it.scanResult.patternScanResult!!.startIndex
val setTextIndex = getTargetIndexWithMethodReferenceNameOrThrow("setText")
val setTextIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setText"
}
addInstruction(setTextIndex, "nop")
addInstructionsWithLabels(
imageSpanIndex, """
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->disableRollingNumberAnimations()Z
move-result v$freeRegister
if-nez v$freeRegister, :disable_animations
""", ExternalLabel("disable_animations", getInstruction(setTextIndex))
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->disableRollingNumberAnimations()Z
move-result v$freeRegister
if-nez v$freeRegister, :disable_animations
""", ExternalLabel("disable_animations", getInstruction(setTextIndex))
)
}
}
@ -106,13 +110,11 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
}
}
EngagementPanelTitleFingerprint.resolve(
context,
EngagementPanelTitleParentFingerprint.resultOrThrow().classDef
)
EngagementPanelTitleFingerprint.resultOrThrow().mutableMethod.apply {
val contentDescriptionIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setContentDescription")
EngagementPanelTitleFingerprint.alsoResolve(
context, EngagementPanelTitleParentFingerprint
).mutableMethod.apply {
val contentDescriptionIndex = EngagementPanelTitleFingerprint
.indexOfContentDescriptionInstruction(this)
val contentDescriptionRegister =
getInstruction<FiveRegisterInstruction>(contentDescriptionIndex).registerD

View File

@ -1,8 +1,22 @@
package app.revanced.patches.youtube.player.descriptions.fingerprints
import app.revanced.util.fingerprint.MethodReferenceNameFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.player.descriptions.fingerprints.EngagementPanelTitleFingerprint.indexOfContentDescriptionInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object EngagementPanelTitleFingerprint : MethodReferenceNameFingerprint(
internal object EngagementPanelTitleFingerprint : MethodFingerprint(
strings = listOf(". "),
reference = { "setContentDescription" }
)
customFingerprint = { methodDef, _ ->
indexOfContentDescriptionInstruction(methodDef) >= 0
}
) {
fun indexOfContentDescriptionInstruction(methodDef: Method) =
methodDef.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setContentDescription"
}
}

View File

@ -16,12 +16,15 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetFooterText
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.literalInstructionViewHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.injectLiteralInstructionViewCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object PlayerFlyoutMenuPatch : BaseBytecodePatch(
@ -56,7 +59,7 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(
val smaliInstruction = """
invoke-static {v$REGISTER_TEMPLATE_REPLACEMENT}, $PLAYER_CLASS_DESCRIPTOR->$name(Landroid/view/View;)V
"""
fingerprint.literalInstructionViewHook(BottomSheetFooterText, smaliInstruction)
fingerprint.injectLiteralInstructionViewCall(BottomSheetFooterText, smaliInstruction)
}
arrayOf(
@ -64,15 +67,17 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(
QualityMenuViewInflateFingerprint
).forEach { fingerprint ->
fingerprint.resultOrThrow().mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addHeaderView")
val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "addHeaderView"
}
val insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerD
addInstructions(
insertIndex,
"""
invoke-static {v$insertRegister}, $PLAYER_CLASS_DESCRIPTOR->hidePlayerFlyoutMenuQualityHeader(Landroid/view/View;)Landroid/view/View;
move-result-object v$insertRegister
"""
insertIndex, """
invoke-static {v$insertRegister}, $PLAYER_CLASS_DESCRIPTOR->hidePlayerFlyoutMenuQualityHeader(Landroid/view/View;)Landroid/view/View;
move-result-object v$insertRegister
"""
)
}
}
@ -95,7 +100,7 @@ object PlayerFlyoutMenuPatch : BaseBytecodePatch(
SettingsPatch.updatePatchStatus(this)
if (SettingsPatch.upward1839) {
PiPModeConfigFingerprint.literalInstructionBooleanHook(
PiPModeConfigFingerprint.injectLiteralInstructionBooleanCall(
45427407,
"$PLAYER_CLASS_DESCRIPTOR->hidePiPModeMenu(Z)Z"
)

View File

@ -4,13 +4,13 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetFooterText
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SubtitleMenuSettingsFooterInfo
import app.revanced.util.containsWideLiteralInstructionIndex
import app.revanced.util.containsWideLiteralInstructionValue
import com.android.tools.smali.dexlib2.AccessFlags
internal object CaptionsBottomSheetFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, _ ->
methodDef.containsWideLiteralInstructionIndex(BottomSheetFooterText)
&& methodDef.containsWideLiteralInstructionIndex(SubtitleMenuSettingsFooterInfo)
methodDef.containsWideLiteralInstructionValue(BottomSheetFooterText)
&& methodDef.containsWideLiteralInstructionValue(SubtitleMenuSettingsFooterInfo)
}
)

View File

@ -17,11 +17,10 @@ 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.settings.SettingsPatch
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -139,13 +138,15 @@ object ChangeTogglePatch : BaseBytecodePatch(
}
val classRegister = getInstruction<TwoRegisterInstruction>(iGetIndex).registerB
val stringIndex = getStringInstructionIndex("menu_item_cinematic_lighting")
val stringIndex =
indexOfFirstStringInstructionOrThrow("menu_item_cinematic_lighting")
val checkCastIndex = getTargetIndexReversedOrThrow(stringIndex, Opcode.CHECK_CAST)
val checkCastIndex =
indexOfFirstInstructionReversedOrThrow(stringIndex, Opcode.CHECK_CAST)
val iGetObjectPrimaryIndex =
getTargetIndexReversedOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
indexOfFirstInstructionReversedOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectSecondaryIndex =
getTargetIndexOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
indexOfFirstInstructionOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val checkCastReference =
getInstruction<ReferenceInstruction>(checkCastIndex).reference
@ -154,14 +155,15 @@ object ChangeTogglePatch : BaseBytecodePatch(
val iGetObjectSecondaryReference =
getInstruction<ReferenceInstruction>(iGetObjectSecondaryIndex).reference
val invokeVirtualIndex = getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_VIRTUAL)
val invokeVirtualIndex =
indexOfFirstInstructionOrThrow(stringIndex, Opcode.INVOKE_VIRTUAL)
val invokeVirtualInstruction =
getInstruction<FiveRegisterInstruction>(invokeVirtualIndex)
val freeRegisterC = invokeVirtualInstruction.registerC
val freeRegisterD = invokeVirtualInstruction.registerD
val freeRegisterE = invokeVirtualInstruction.registerE
val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.RETURN_VOID)
val insertIndex = indexOfFirstInstructionOrThrow(stringIndex, Opcode.RETURN_VOID)
addInstructionsWithLabels(
insertIndex, """

View File

@ -30,12 +30,10 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullS
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QuickActionsElementContainer
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import app.revanced.util.updatePatchStatus
@ -80,8 +78,9 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
EngagementPanelFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val literalIndex = getWideLiteralInstructionIndex(FullScreenEngagementPanel)
val targetIndex = getTargetIndexOrThrow(literalIndex, Opcode.CHECK_CAST)
val literalIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(FullScreenEngagementPanel)
val targetIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.CHECK_CAST)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
@ -94,7 +93,10 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
PlayerTitleViewFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("addView")
val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "addView"
}
val insertReference =
getInstruction<ReferenceInstruction>(insertIndex).reference.toString()
if (!insertReference.startsWith("Landroid/widget/FrameLayout;"))
@ -115,9 +117,10 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
LayoutConstructorFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(AutoNavPreviewStub)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(AutoNavPreviewStub)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndexOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex =
indexOfFirstInstructionOrThrow(constIndex + 2, Opcode.INVOKE_VIRTUAL) + 1
addInstructionsWithLabels(
constIndex, """
@ -159,7 +162,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
}
val constIndex = containerCalls.elementAt(containerCalls.size - 1).index
val checkCastIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val checkCastIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val insertRegister =
getInstruction<OneRegisterInstruction>(checkCastIndex).registerA
@ -183,9 +186,11 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setFocusableInTouchMode")
val walkerIndex = getTargetIndexOrThrow(targetIndex, Opcode.INVOKE_STATIC)
val targetIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setFocusableInTouchMode"
}
val walkerIndex = indexOfFirstInstructionOrThrow(targetIndex, Opcode.INVOKE_STATIC)
val walkerMethod = getWalkerMethod(context, walkerIndex)
walkerMethod.apply {
@ -209,14 +214,14 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
ClientSettingEndpointFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val getActivityIndex = getStringInstructionIndex("watch") + 2
val getActivityIndex = indexOfFirstStringInstructionOrThrow("watch") + 2
val getActivityReference =
getInstruction<ReferenceInstruction>(getActivityIndex).reference
val classRegister =
getInstruction<TwoRegisterInstruction>(getActivityIndex).registerB
val watchDescriptorMethodIndex =
getStringInstructionIndex("start_watch_minimized") - 1
indexOfFirstStringInstructionOrThrow("start_watch_minimized") - 1
val watchDescriptorRegister =
getInstruction<FiveRegisterInstruction>(watchDescriptorMethodIndex).registerD
@ -228,7 +233,7 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
)
// hooks Activity.
val insertIndex = getStringInstructionIndex("force_fullscreen")
val insertIndex = indexOfFirstStringInstructionOrThrow("force_fullscreen")
val freeRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
@ -244,9 +249,10 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
VideoPortraitParentFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val stringIndex =
getStringInstructionIndex("Acquiring NetLatencyActionLogger failed. taskId=")
val invokeIndex = getTargetIndexOrThrow(stringIndex, Opcode.INVOKE_INTERFACE)
val targetIndex = getTargetIndexOrThrow(invokeIndex, Opcode.CHECK_CAST)
indexOfFirstStringInstructionOrThrow("Acquiring NetLatencyActionLogger failed. taskId=")
val invokeIndex =
indexOfFirstInstructionOrThrow(stringIndex, Opcode.INVOKE_INTERFACE)
val targetIndex = indexOfFirstInstructionOrThrow(invokeIndex, Opcode.CHECK_CAST)
val targetClass = context
.findClass(getInstruction<ReferenceInstruction>(targetIndex).reference.toString())!!
.mutableClass
@ -328,8 +334,9 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
BroadcastReceiverFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val stringIndex =
getStringInstructionIndex("android.intent.action.SCREEN_ON")
val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.IF_EQZ) + 1
indexOfFirstStringInstructionOrThrow("android.intent.action.SCREEN_ON")
val insertIndex =
indexOfFirstInstructionOrThrow(stringIndex, Opcode.IF_EQZ) + 1
addInstruction(
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.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -65,7 +65,7 @@ object HapticFeedBackPatch : BaseBytecodePatch(
var register = 0
if (name == "run") {
index = getTargetIndexOrThrow(Opcode.SGET)
index = indexOfFirstInstructionOrThrow(Opcode.SGET)
register = getInstruction<OneRegisterInstruction>(index).registerA
}

View File

@ -30,11 +30,11 @@ 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.contexts
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -44,6 +44,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import org.w3c.dom.Element
@Suppress("DEPRECATION", "unused")
@ -139,11 +140,14 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
TotalTimeFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val charSequenceIndex =
getTargetIndexWithMethodReferenceNameOrThrow("getString") + 1
val charSequenceIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "getString"
} + 1
val charSequenceRegister =
getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA
val textViewIndex = getTargetIndexWithMethodReferenceNameOrThrow("getText")
val textViewIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "getText"
}
val textViewRegister =
getInstruction<FiveRegisterInstruction>(textViewIndex).registerC
@ -162,12 +166,12 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
// region patch for seekbar color
PlayerSeekbarColorFingerprint.resultOrThrow().mutableMethod.apply {
hook(getWideLiteralInstructionIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2)
hook(getWideLiteralInstructionIndex(InlineTimeBarPlayedNotHighlightedColor) + 2)
hook(InlineTimeBarColorizedBarPlayedColorDark)
hook(InlineTimeBarPlayedNotHighlightedColor)
}
ShortsSeekbarColorFingerprint.resultOrThrow().mutableMethod.apply {
hook(getWideLiteralInstructionIndex(ReelTimeBarPlayedColor) + 2)
hook(ReelTimeBarPlayedColor)
}
ControlsOverlayStyleFingerprint.resultOrThrow().let {
@ -212,7 +216,7 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
PlayerButtonsVisibilityFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2
val viewIndex = getTargetIndexOrThrow(Opcode.INVOKE_INTERFACE)
val viewIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_INTERFACE)
val viewRegister = getInstruction<FiveRegisterInstruction>(viewIndex).registerD
addInstructionsWithLabels(
@ -271,7 +275,7 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
// region patch for restore old seekbar thumbnails
ThumbnailPreviewConfigFingerprint.result?.let {
ThumbnailPreviewConfigFingerprint.literalInstructionBooleanHook(
ThumbnailPreviewConfigFingerprint.injectLiteralInstructionBooleanCall(
45398577,
"$PLAYER_CLASS_DESCRIPTOR->restoreOldSeekbarThumbnails()Z"
)
@ -285,7 +289,7 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
// region patch for enable cairo seekbar
if (SettingsPatch.upward1923) {
CairoSeekbarConfigFingerprint.literalInstructionBooleanHook(
CairoSeekbarConfigFingerprint.injectLiteralInstructionBooleanCall(
45617850,
"$PLAYER_CLASS_DESCRIPTOR->enableCairoSeekbar()Z"
)
@ -303,7 +307,8 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
SettingsPatch.updatePatchStatus(this)
}
private fun MutableMethod.hook(insertIndex: Int) {
private fun MutableMethod.hook(literal: Long) {
val insertIndex = indexOfFirstWideLiteralInstructionValueOrThrow(literal) + 2
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(

View File

@ -15,18 +15,15 @@ import app.revanced.patches.youtube.player.speedoverlay.fingerprints.NextGenWatc
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.RestoreSlideToSeekBehaviorFingerprint
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SlideToSeekMotionEventFingerprint
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayFingerprint
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayFloatValueFingerprint
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayTextValueFingerprint
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayValueFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.alsoResolve
import app.revanced.util.getReference
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameReversedOrThrow
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.literalInstructionBooleanHook
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.injectLiteralInstructionBooleanCall
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -35,6 +32,8 @@ 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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
@Patch(dependencies = [SharedResourceIdPatch::class])
object SpeedOverlayPatch : BytecodePatch(
@ -43,8 +42,8 @@ object SpeedOverlayPatch : BytecodePatch(
NextGenWatchLayoutFingerprint,
RestoreSlideToSeekBehaviorFingerprint,
SpeedOverlayFingerprint,
SpeedOverlayFloatValueFingerprint,
SpeedOverlayTextValueFingerprint,
SpeedOverlayValueFingerprint,
)
) {
override fun execute(context: BytecodeContext) {
@ -52,36 +51,33 @@ object SpeedOverlayPatch : BytecodePatch(
val restoreSlideToSeekBehaviorFingerprintResult =
RestoreSlideToSeekBehaviorFingerprint.result
val speedOverlayFingerprintResult = SpeedOverlayFingerprint.result
val speedOverlayValueFingerprintResult = SpeedOverlayValueFingerprint.result
val speedOverlayFloatValueFingerprintResult = SpeedOverlayFloatValueFingerprint.result
val resolvable =
restoreSlideToSeekBehaviorFingerprintResult != null
&& speedOverlayFingerprintResult != null
&& speedOverlayValueFingerprintResult != null
&& speedOverlayFloatValueFingerprintResult != null
if (resolvable) {
// Legacy method.
// Used on YouTube 18.29.38 ~ YouTube 19.17.41
// region patch for disable speed overlay
// region patch for Disable speed overlay (Enable slide to seek)
mapOf(
RestoreSlideToSeekBehaviorFingerprint to 45411329,
SpeedOverlayFingerprint to 45411330
).forEach { (fingerprint, literal) ->
fingerprint.result!!.let {
fingerprint.literalInstructionBooleanHook(
literal,
"$PLAYER_CLASS_DESCRIPTOR->disableSpeedOverlay(Z)Z"
)
}
fingerprint.injectLiteralInstructionBooleanCall(
literal,
"$PLAYER_CLASS_DESCRIPTOR->disableSpeedOverlay(Z)Z"
)
}
// endregion
// region patch for custom speed overlay value
// region patch for Custom speed overlay float value
speedOverlayValueFingerprintResult!!.let {
speedOverlayFloatValueFingerprintResult!!.let {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.startIndex
val register = getInstruction<TwoRegisterInstruction>(index).registerA
@ -98,13 +94,18 @@ object SpeedOverlayPatch : BytecodePatch(
// endregion
} else {
// New method.
// Used on YouTube 19.18.41~
NextGenWatchLayoutFingerprint.resultOrThrow().mutableMethod.apply {
val booleanValueIndex = getTargetIndexWithMethodReferenceNameOrThrow("booleanValue")
// region patch for Disable speed overlay (Enable slide to seek)
val insertIndex = findIGetIndex(booleanValueIndex - 10, booleanValueIndex)
NextGenWatchLayoutFingerprint.resultOrThrow().mutableMethod.apply {
val booleanValueIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "booleanValue"
}
val insertIndex = indexOfFirstInstructionOrThrow(booleanValueIndex - 10) {
opcode == Opcode.IGET_OBJECT
&& getReference<FieldReference>()?.definingClass == definingClass
}
val insertInstruction = getInstruction<TwoRegisterInstruction>(insertIndex)
val insertReference = getInstruction<ReferenceInstruction>(insertIndex).reference
@ -113,77 +114,107 @@ object SpeedOverlayPatch : BytecodePatch(
"iget-object v${insertInstruction.registerA}, v${insertInstruction.registerB}, $insertReference"
)
val jumpIndex = findIGetIndex(booleanValueIndex, booleanValueIndex + 10)
val jumpIndex = indexOfFirstInstructionOrThrow(booleanValueIndex) {
opcode == Opcode.IGET_OBJECT
&& getReference<FieldReference>()?.definingClass == definingClass
}
hook(insertIndex + 1, insertInstruction.registerA, jumpIndex)
}
SlideToSeekMotionEventFingerprint.resolve(
context,
HorizontalTouchOffsetConstructorFingerprint.resultOrThrow().classDef
)
SlideToSeekMotionEventFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val scanResult = it.scanResult.patternScanResult!!
val (slideToSeekBooleanMethod, slideToSeekSyntheticMethod) =
SlideToSeekMotionEventFingerprint.alsoResolve(
context, HorizontalTouchOffsetConstructorFingerprint
).let {
with(it.mutableMethod) {
val scanResult = it.scanResult.patternScanResult!!
val jumpIndex = scanResult.endIndex + 1
val insertIndex = scanResult.endIndex - 1
val insertRegister =
getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val slideToSeekBooleanIndex = scanResult.startIndex + 1
slideToSeekBooleanMethod = getWalkerMethod(context, slideToSeekBooleanIndex)
val jumpIndex = scanResult.endIndex + 1
val insertIndex = scanResult.endIndex - 1
val insertRegister =
getInstruction<TwoRegisterInstruction>(insertIndex).registerA
hook(insertIndex, insertRegister, jumpIndex)
}
}
slideToSeekBooleanMethod.apply {
var insertIndex = getTargetIndexOrThrow(Opcode.IGET_OBJECT)
var insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
var jumpIndex = getTargetIndexReversedOrThrow(Opcode.INVOKE_VIRTUAL)
hook(insertIndex, insertRegister, jumpIndex)
val constructorMethod =
context.findClass(definingClass)?.mutableClass
?.methods?.find { method -> method.name == "<init>" }
?: throw PatchException("Could not find constructor method")
constructorMethod.apply {
val syntheticIndex = getTargetIndexReversedOrThrow(Opcode.NEW_INSTANCE)
val syntheticClass =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
val syntheticMethod =
context.findClass(syntheticClass)?.mutableClass
?.methods?.find { method -> method.name == "run" }
?: throw PatchException("Could not find synthetic method")
syntheticMethod.apply {
val speedOverlayValueIndex =
indexOfFirstInstructionOrThrow { (this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits() }
val speedOverlayValueRegister =
getInstruction<OneRegisterInstruction>(speedOverlayValueIndex).registerA
addInstructions(
speedOverlayValueIndex + 1, """
invoke-static {v$speedOverlayValueRegister}, $PLAYER_CLASS_DESCRIPTOR->speedOverlayValue(F)F
move-result v$speedOverlayValueRegister
"""
)
insertIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow(
speedOverlayValueIndex,
"removeCallbacks"
) + 1
insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
jumpIndex =
getTargetIndexOrThrow(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1
hook(insertIndex, insertRegister, jumpIndex)
val slideToSeekBooleanMethod = context.toMethodWalker(it.mutableMethod)
.nextMethod(scanResult.startIndex + 1, true)
.getMethod() as MutableMethod
val slideToSeekConstructorMethod =
context.findClass { classDef -> classDef.type == slideToSeekBooleanMethod.definingClass }
?.mutableClass
?.methods
?.find { method -> MethodUtil.isConstructor(method) }
?: throw PatchException("Could not find constructor method")
val slideToSeekSyntheticIndex = slideToSeekConstructorMethod
.indexOfFirstInstructionReversedOrThrow {
opcode == Opcode.NEW_INSTANCE
}
val slideToSeekSyntheticClass = slideToSeekConstructorMethod
.getInstruction<ReferenceInstruction>(slideToSeekSyntheticIndex)
.reference
.toString()
val slideToSeekSyntheticMethod =
context.findClass { classDef -> classDef.type == slideToSeekSyntheticClass }
?.mutableClass
?.methods
?.find { method -> method.name == "run" }
?: throw PatchException("Could not find synthetic method")
Pair(slideToSeekBooleanMethod, slideToSeekSyntheticMethod)
}
}
slideToSeekBooleanMethod.apply {
val insertIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.IGET_OBJECT
}
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val jumpIndex = indexOfFirstInstructionReversedOrThrow {
opcode == Opcode.INVOKE_VIRTUAL
}
hook(insertIndex, insertRegister, jumpIndex)
}
slideToSeekSyntheticMethod.apply {
val speedOverlayFloatValueIndex = indexOfFirstInstructionOrThrow {
(this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits()
}
val insertIndex =
indexOfFirstInstructionReversedOrThrow(speedOverlayFloatValueIndex) {
getReference<MethodReference>()?.name == "removeCallbacks"
} + 1
val insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
val jumpIndex =
indexOfFirstInstructionOrThrow(
speedOverlayFloatValueIndex,
Opcode.RETURN_VOID
) + 1
hook(insertIndex, insertRegister, jumpIndex)
}
// endregion
// region patch for Custom speed overlay float value
slideToSeekSyntheticMethod.apply {
val speedOverlayFloatValueIndex = indexOfFirstInstructionOrThrow {
(this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits()
}
val speedOverlayFloatValueRegister =
getInstruction<OneRegisterInstruction>(speedOverlayFloatValueIndex).registerA
addInstructions(
speedOverlayFloatValueIndex + 1, """
invoke-static {v$speedOverlayFloatValueRegister}, $PLAYER_CLASS_DESCRIPTOR->speedOverlayValue(F)F
move-result v$speedOverlayFloatValueRegister
"""
)
}
SpeedOverlayTextValueFingerprint.resultOrThrow().let {
@ -200,11 +231,12 @@ object SpeedOverlayPatch : BytecodePatch(
)
}
}
// endregion
}
}
private lateinit var slideToSeekBooleanMethod: MutableMethod
// restore slide to seek
private fun MutableMethod.hook(
insertIndex: Int,
@ -220,14 +252,4 @@ object SpeedOverlayPatch : BytecodePatch(
""", ExternalLabel("disable", getInstruction(jumpIndex))
)
}
private fun MutableMethod.findIGetIndex(
startIndex: Int,
endIndex: Int
): Int = implementation!!.instructions.let { instruction ->
startIndex + instruction.subList(startIndex, endIndex).indexOfFirst {
it.opcode == Opcode.IGET_OBJECT
&& it.getReference<FieldReference>()?.definingClass == definingClass
}
}
}

View File

@ -2,8 +2,10 @@ package app.revanced.patches.youtube.player.speedoverlay.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.containsMethodReferenceNameInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object NextGenWatchLayoutFingerprint : MethodFingerprint(
returnType = "Z",
@ -13,6 +15,8 @@ internal object NextGenWatchLayoutFingerprint : MethodFingerprint(
if (methodDef.definingClass != "Lcom/google/android/apps/youtube/app/watch/nextgenwatch/ui/NextGenWatchLayout;")
return@handler false
methodDef.containsMethodReferenceNameInstructionIndex("booleanValue")
methodDef.indexOfFirstInstruction {
getReference<MethodReference>()?.name == "booleanValue"
} >= 0
}
)

View File

@ -5,6 +5,7 @@ import com.android.tools.smali.dexlib2.Opcode
/**
* This value restores the 'Slide to seek' behavior.
* Deprecated in YouTube v19.18.41+.
*/
internal object RestoreSlideToSeekBehaviorFingerprint : LiteralValueFingerprint(
returnType = "Z",

View File

@ -5,6 +5,7 @@ import com.android.tools.smali.dexlib2.Opcode
/**
* This value disables 'Playing at 2x speed' while holding down.
* Deprecated in YouTube v19.18.41+.
*/
internal object SpeedOverlayFingerprint : LiteralValueFingerprint(
returnType = "Z",

View File

@ -7,8 +7,9 @@ import com.android.tools.smali.dexlib2.Opcode
/**
* This value is the key for the playback speed overlay value.
* Deprecated in YouTube v19.18.41+.
*/
internal object SpeedOverlayValueFingerprint : LiteralValueFingerprint(
internal object SpeedOverlayFloatValueFingerprint : LiteralValueFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
opcodes = listOf(Opcode.DOUBLE_TO_FLOAT),

View File

@ -1,14 +1,21 @@
package app.revanced.patches.youtube.player.speedoverlay.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.util.fingerprint.ReferenceFingerprint
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object SpeedOverlayTextValueFingerprint : ReferenceFingerprint(
internal object SpeedOverlayTextValueFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
parameters = emptyList(),
opcodes = listOf(Opcode.CONST_WIDE_HIGH16),
reference = { "Ljava/math/BigDecimal;->signum()I" }
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstruction {
getReference<MethodReference>()?.toString() == "Ljava/math/BigDecimal;->signum()I"
} >= 0
}
)

View File

@ -15,8 +15,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelF
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts
import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -38,7 +38,7 @@ object ShortsAnimationPatch : BytecodePatch(
ReelFeedbackPause to "setShortsPauseFeedback",
ReelFeedbackPlay to "setShortsPlayFeedback",
).forEach { (literal, methodName) ->
val literalIndex = getWideLiteralInstructionIndex(literal)
val literalIndex = indexOfFirstWideLiteralInstructionValueOrThrow(literal)
val viewIndex = indexOfFirstInstructionOrThrow(literalIndex) {
opcode == Opcode.CHECK_CAST
&& (this as? ReferenceInstruction)?.reference?.toString() == LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR

View File

@ -35,12 +35,12 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Right
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionHook
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.replaceLiteralInstructionCall
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -48,6 +48,7 @@ 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.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Suppress("unused")
object ShortsComponentPatch : BaseBytecodePatch(
@ -106,10 +107,11 @@ object ShortsComponentPatch : BaseBytecodePatch(
ShortsButtonFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon)
val constIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(ReelRightDislikeIcon)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val jumpIndex = getTargetIndexOrThrow(constIndex, Opcode.CONST_CLASS) + 2
val jumpIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels(
constIndex + 1, """
@ -128,9 +130,9 @@ object ShortsComponentPatch : BaseBytecodePatch(
ShortsButtonFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getWideLiteralInstructionIndex(ReelRightLikeIcon)
val insertIndex = indexOfFirstWideLiteralInstructionValueOrThrow(ReelRightLikeIcon)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndexOrThrow(insertIndex, Opcode.CONST_CLASS) + 2
val jumpIndex = indexOfFirstInstructionOrThrow(insertIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels(
insertIndex + 1, """
@ -152,11 +154,12 @@ object ShortsComponentPatch : BaseBytecodePatch(
if (shortsPivotLegacyFingerprintResult != null) {
// Legacy method.
shortsPivotLegacyFingerprintResult.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton)
val targetIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(ReelForcedMuteButton)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val insertIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.IF_EQZ)
val jumpIndex = getTargetIndexOrThrow(targetIndex, Opcode.GOTO)
val insertIndex = indexOfFirstInstructionReversedOrThrow(targetIndex, Opcode.IF_EQZ)
val jumpIndex = indexOfFirstInstructionOrThrow(targetIndex, Opcode.GOTO)
addInstructionsWithLabels(
insertIndex, """
@ -173,7 +176,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
move-result v$REGISTER_TEMPLATE_REPLACEMENT
"""
context.literalInstructionHook(
context.replaceLiteralInstructionCall(
ReelPlayerRightPivotV2Size,
smaliInstruction
)
@ -242,7 +245,8 @@ object ShortsComponentPatch : BaseBytecodePatch(
lateinit var subscriptionFieldReference: FieldReference
parentResult.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(ReelPlayerFooter) - 1
val targetIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(ReelPlayerFooter) - 1
subscriptionFieldReference =
(getInstruction<ReferenceInstruction>(targetIndex)).reference as FieldReference
}
@ -297,9 +301,9 @@ object ShortsComponentPatch : BaseBytecodePatch(
TextComponentSpecFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex =
getTargetIndexWithReferenceOrThrow("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;")
val insertIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.toString() == "Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;"
}
val charSequenceRegister =
getInstruction<FiveRegisterInstruction>(insertIndex).registerC
val conversionContextRegister =
@ -342,11 +346,11 @@ object ShortsComponentPatch : BaseBytecodePatch(
) {
resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(id)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(id)
val insertIndex = if (reversed)
getTargetIndexReversedOrThrow(constIndex, Opcode.CHECK_CAST)
indexOfFirstInstructionReversedOrThrow(constIndex, Opcode.CHECK_CAST)
else
getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction(
@ -363,8 +367,8 @@ object ShortsComponentPatch : BaseBytecodePatch(
) {
resultOrThrow().let {
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(id)
val insertIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val constIndex = indexOfFirstWideLiteralInstructionValueOrThrow(id)
val insertIndex = indexOfFirstInstructionOrThrow(constIndex, Opcode.CHECK_CAST)
hideButtons(insertIndex, descriptor)
}

View File

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

View File

@ -9,14 +9,18 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.shorts.components.fingerprints.ReelEnumConstructorFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ReelEnumStaticFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR
import app.revanced.util.containsReferenceInstructionIndex
import app.revanced.util.findMutableMethodOf
import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
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.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.util.MethodUtil
object ShortsRepeatPatch : BytecodePatch(
setOf(ReelEnumConstructorFingerprint)
@ -36,16 +40,15 @@ object ShortsRepeatPatch : BytecodePatch(
}
val endScreenStringIndex =
getStringInstructionIndex("REEL_LOOP_BEHAVIOR_END_SCREEN")
indexOfFirstStringInstructionOrThrow("REEL_LOOP_BEHAVIOR_END_SCREEN")
val endScreenReferenceIndex =
getTargetIndexOrThrow(endScreenStringIndex, Opcode.SPUT_OBJECT)
indexOfFirstInstructionOrThrow(endScreenStringIndex, Opcode.SPUT_OBJECT)
val endScreenReference =
getInstruction<ReferenceInstruction>(endScreenReferenceIndex).reference.toString()
val enumMethodName = ReelEnumStaticFingerprint.resultOrThrow().mutableMethod.name
val enumMethodCall = "$definingClass->$enumMethodName(I)$definingClass"
val enumMethod = ReelEnumStaticFingerprint.resultOrThrow().mutableMethod
context.injectHook(endScreenReference, enumMethodCall)
context.injectHook(endScreenReference, enumMethod)
}
}
}
@ -54,8 +57,8 @@ object ShortsRepeatPatch : BytecodePatch(
enumName: String,
fieldName: String
) {
val stringIndex = getStringInstructionIndex(enumName)
val insertIndex = getTargetIndexOrThrow(stringIndex, Opcode.SPUT_OBJECT)
val stringIndex = indexOfFirstStringInstructionOrThrow(enumName)
val insertIndex = indexOfFirstInstructionOrThrow(stringIndex, Opcode.SPUT_OBJECT)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction(
@ -66,35 +69,41 @@ object ShortsRepeatPatch : BytecodePatch(
private fun BytecodeContext.injectHook(
endScreenReference: String,
enumMethodCall: String
enumMethod: MutableMethod
) {
classes.forEach { classDef ->
classDef.methods.filter { method ->
method.parameters.size == 1
&& method.parameters[0].startsWith("L")
&& method.returnType == "V"
&& method.containsReferenceInstructionIndex(endScreenReference)
&& method.indexOfFirstInstruction {
getReference<FieldReference>()?.toString() == endScreenReference
} >= 0
}.forEach { targetMethod ->
proxy(classDef)
.mutableClass
.findMutableMethodOf(targetMethod)
.apply {
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_STATIC)
continue
if ((instruction as ReferenceInstruction).reference.toString() != enumMethodCall)
continue
implementation!!.instructions
.withIndex()
.filter { (_, instruction) ->
val reference = (instruction as? ReferenceInstruction)?.reference
reference is MethodReference &&
MethodUtil.methodSignaturesMatch(enumMethod, reference)
}
.map { (index, _) -> index }
.reversed()
.forEach { index ->
val register =
getInstruction<OneRegisterInstruction>(index + 1).registerA
val register =
getInstruction<OneRegisterInstruction>(index + 1).registerA
addInstructions(
index + 2, """
invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->changeShortsRepeatState(Ljava/lang/Enum;)Ljava/lang/Enum;
move-result-object v$register
"""
)
}
addInstructions(
index + 2, """
invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->changeShortsRepeatState(Ljava/lang/Enum;)Ljava/lang/Enum;
move-result-object v$register
"""
)
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More