chore: lint code

This commit is contained in:
inotia00
2024-01-26 03:35:21 +09:00
parent e783f18df0
commit aa6d8106c5
11 changed files with 85 additions and 163 deletions

View File

@ -12,6 +12,7 @@ import app.revanced.patches.music.misc.tastebuilder.fingerprints.TasteBuilderSyn
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch 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.MusicTastebuilderShelf
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getTargetIndex
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -49,11 +50,7 @@ object TasteBuilderPatch : BytecodePatch(
parentResult.mutableMethod.apply { parentResult.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2 val freeRegister = implementation!!.registerCount - parameters.size - 2
val constIndex = getWideLiteralInstructionIndex(MusicTastebuilderShelf) val constIndex = getWideLiteralInstructionIndex(MusicTastebuilderShelf)
val targetIndex = implementation!!.instructions.let { val targetIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT)
constIndex + it.subList(constIndex, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.MOVE_RESULT_OBJECT
}
}
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructions( addInstructions(

View File

@ -4,15 +4,16 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getEmptyStringInstructionIndex import app.revanced.util.getEmptyStringInstructionIndex
import app.revanced.util.getReference
import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexReversed
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction 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.FieldReference
@ -34,12 +35,11 @@ object ComponentParserPatch : BytecodePatch(
internal fun generalHook(descriptor: String) { internal fun generalHook(descriptor: String) {
insertMethod.apply { insertMethod.apply {
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, insertIndex, """
""" invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z move-result v$stringBuilderRegister
move-result v$stringBuilderRegister if-eqz v$stringBuilderRegister, :filter
if-eqz v$stringBuilderRegister, :filter """ + emptyComponentLabel,
""" + emptyComponentLabel,
ExternalLabel("filter", getInstruction(insertIndex)) ExternalLabel("filter", getInstruction(insertIndex))
) )
} }
@ -48,39 +48,25 @@ object ComponentParserPatch : BytecodePatch(
internal fun pathBuilderHook(descriptor: String) { internal fun pathBuilderHook(descriptor: String) {
insertMethod.apply { insertMethod.apply {
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, insertIndex, """
""" invoke-static {v$stringBuilderRegister}, $descriptor(Ljava/lang/StringBuilder;)Z
invoke-static {v$stringBuilderRegister}, $descriptor(Ljava/lang/StringBuilder;)Z move-result v$stringBuilderRegister
move-result v$stringBuilderRegister if-eqz v$stringBuilderRegister, :filter
if-eqz v$stringBuilderRegister, :filter """ + emptyComponentLabel,
""" + emptyComponentLabel,
ExternalLabel("filter", getInstruction(insertIndex)) ExternalLabel("filter", getInstruction(insertIndex))
) )
} }
} }
private fun MutableMethod.getTargetIndexDownTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
throw PatchException("Failed to find hook method")
}
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
/** /**
* Shared fingerprint * Shared fingerprint
*/ */
EmptyComponentBuilderFingerprint.result?.let { result -> EmptyComponentBuilderFingerprint.result?.let {
result.mutableMethod.apply { it.mutableMethod.apply {
insertMethod = this insertMethod = this
emptyComponentIndex = result.scanResult.patternScanResult!!.startIndex + 1 emptyComponentIndex = it.scanResult.patternScanResult!!.startIndex + 1
val builderMethodDescriptor = val builderMethodDescriptor =
getInstruction<ReferenceInstruction>(emptyComponentIndex).reference getInstruction<ReferenceInstruction>(emptyComponentIndex).reference
@ -97,9 +83,7 @@ object ComponentParserPatch : BytecodePatch(
val stringBuilderIndex = val stringBuilderIndex =
implementation!!.instructions.indexOfFirst { instruction -> implementation!!.instructions.indexOfFirst { instruction ->
val fieldReference = instruction.getReference<FieldReference>()?.type == "Ljava/lang/StringBuilder;"
(instruction as? ReferenceInstruction)?.reference as? FieldReference
fieldReference?.let { reference -> reference.type == "Ljava/lang/StringBuilder;" } == true
} }
stringBuilderRegister = stringBuilderRegister =
@ -108,15 +92,11 @@ object ComponentParserPatch : BytecodePatch(
insertIndex = stringBuilderIndex + 1 insertIndex = stringBuilderIndex + 1
val emptyStringIndex = getEmptyStringInstructionIndex() val emptyStringIndex = getEmptyStringInstructionIndex()
val identifierIndex = getTargetIndexDownTo(emptyStringIndex, Opcode.IPUT_OBJECT) val identifierIndex = getTargetIndexReversed(emptyStringIndex, Opcode.IPUT_OBJECT)
identifierRegister = identifierRegister =
getInstruction<TwoRegisterInstruction>(identifierIndex).registerA getInstruction<TwoRegisterInstruction>(identifierIndex).registerA
val objectIndex = implementation!!.instructions.let { val objectIndex = getTargetIndex(emptyStringIndex, Opcode.INVOKE_VIRTUAL)
emptyStringIndex + it.subList(emptyStringIndex, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_VIRTUAL
}
}
objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC
} }
} ?: throw EmptyComponentBuilderFingerprint.exception } ?: throw EmptyComponentBuilderFingerprint.exception

View File

@ -17,6 +17,7 @@ import app.revanced.patches.youtube.utils.litho.LithoFilterPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getTargetIndex
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
@ -86,11 +87,7 @@ object CommentComponentPatch : BytecodePatch(
ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.result?.let { parentResult -> ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.result?.let { parentResult ->
parentResult.mutableMethod.apply { parentResult.mutableMethod.apply {
val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492) val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492)
val emojiPickerOnClickListenerIndex = implementation!!.instructions.let { val emojiPickerOnClickListenerIndex = getTargetIndex(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
emojiPickerEndpointIndex + it.subList(emojiPickerEndpointIndex, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_DIRECT
}
}
val emojiPickerOnClickListenerMethod = val emojiPickerOnClickListenerMethod =
context.toMethodWalker(this) context.toMethodWalker(this)
.nextMethod(emojiPickerOnClickListenerIndex, true) .nextMethod(emojiPickerOnClickListenerIndex, true)

View File

@ -14,6 +14,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -63,11 +64,7 @@ object KeepLandScapeModePatch : BytecodePatch(
BroadcastReceiverFingerprint.result?.let { result -> BroadcastReceiverFingerprint.result?.let { result ->
result.mutableMethod.apply { result.mutableMethod.apply {
val stringIndex = getStringInstructionIndex("android.intent.action.SCREEN_ON") val stringIndex = getStringInstructionIndex("android.intent.action.SCREEN_ON")
val insertIndex = implementation!!.instructions.let { val insertIndex = getTargetIndex(stringIndex, Opcode.IF_EQZ) + 1
stringIndex + it.subList(stringIndex, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.IF_EQZ
} + 1
}
addInstruction( addInstruction(
insertIndex, insertIndex,

View File

@ -18,6 +18,7 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Image
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndex
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.Opcode.MOVE_RESULT_OBJECT import com.android.tools.smali.dexlib2.Opcode.MOVE_RESULT_OBJECT
@ -108,13 +109,8 @@ object NavigationButtonsPatch : BytecodePatch(
* Create Button * Create Button
*/ */
parentResult.mutableMethod.apply { parentResult.mutableMethod.apply {
val insertIndex = implementation!!.instructions.let { val constIndex = getWideLiteralInstructionIndex(ImageOnlyTab)
val scanStart = getWideLiteralInstructionIndex(ImageOnlyTab) val insertIndex = getTargetIndex(constIndex, Opcode.INVOKE_VIRTUAL) + 2
scanStart + it.subList(scanStart, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_VIRTUAL
}
} + 2
injectHook(CREATE_BUTTON_HOOK, insertIndex) injectHook(CREATE_BUTTON_HOOK, insertIndex)
} }

View File

@ -15,6 +15,7 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Total
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.getTargetIndex
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -68,14 +69,10 @@ object AppendTimeStampInformationPatch : BytecodePatch(
setOf(TotalTimeFingerprint) setOf(TotalTimeFingerprint)
) { ) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
TotalTimeFingerprint.result?.let { result -> TotalTimeFingerprint.result?.let {
result.mutableMethod.apply { it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(TotalTime) val constIndex = getWideLiteralInstructionIndex(TotalTime)
val charSequenceIndex = implementation!!.instructions.let { val charSequenceIndex = getTargetIndex(constIndex, Opcode.MOVE_RESULT_OBJECT)
constIndex + it.subList(constIndex, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.MOVE_RESULT_OBJECT
}
}
val charSequenceRegister = getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA val charSequenceRegister = getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA
val textViewIndex = indexOfFirstInstruction { val textViewIndex = indexOfFirstInstruction {
getReference<MethodReference>()?.name == "getText" getReference<MethodReference>()?.name == "getText"

View File

@ -36,6 +36,8 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelR
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexReversed
import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -118,7 +120,7 @@ object ShortsComponentPatch : BytecodePatch(
val insertIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon) val insertIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndexUpTo(insertIndex, Opcode.CONST_CLASS) + 2 val jumpIndex = getTargetIndex(insertIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex + 1, """ insertIndex + 1, """
@ -155,7 +157,7 @@ object ShortsComponentPatch : BytecodePatch(
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val jumpIndex = getTargetIndexUpTo(insertIndex, Opcode.CONST_CLASS) + 2 val jumpIndex = getTargetIndex(insertIndex, Opcode.CONST_CLASS) + 2
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex + 1, """ insertIndex + 1, """
@ -210,8 +212,8 @@ object ShortsComponentPatch : BytecodePatch(
val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton) val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val insertIndex = getTargetIndexDownTo(targetIndex, Opcode.IF_EQZ) val insertIndex = getTargetIndexReversed(targetIndex, Opcode.IF_EQZ)
val jumpIndex = getTargetIndexUpTo(targetIndex, Opcode.GOTO) val jumpIndex = getTargetIndex(targetIndex, Opcode.GOTO)
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, """ insertIndex, """
@ -224,7 +226,7 @@ object ShortsComponentPatch : BytecodePatch(
} ?: ShortsPivotFingerprint.result?.let { } ?: ShortsPivotFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(ReelPivotButton) val targetIndex = getWideLiteralInstructionIndex(ReelPivotButton)
val insertIndex = getTargetIndexDownTo(targetIndex, Opcode.INVOKE_STATIC) + 2 val insertIndex = getTargetIndexReversed(targetIndex, Opcode.INVOKE_STATIC) + 2
hideButtons( hideButtons(
insertIndex, insertIndex,
@ -301,30 +303,4 @@ object ShortsComponentPatch : BytecodePatch(
""" """
) )
} }
private fun MutableMethod.getTargetIndexDownTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
throw PatchException("Failed to find hook method")
}
private fun MutableMethod.getTargetIndexUpTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex until implementation!!.instructions.size) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
throw PatchException("Failed to find hook method")
}
} }

View File

@ -3,15 +3,19 @@ package app.revanced.patches.youtube.shorts.startupshortsreset
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints.UserWasInShortsFingerprint import app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints.UserWasInShortsFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import app.revanced.util.getTargetIndexReversed
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch( @Patch(
name = "Disable shorts on startup", name = "Disable shorts on startup",
@ -57,19 +61,26 @@ object DisableShortsOnStartupPatch : BytecodePatch(
UserWasInShortsFingerprint.result?.let { UserWasInShortsFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA val targetIndex = getTargetIndexReversed(startIndex, Opcode.RETURN_VOID) + 1
if (getInstruction(targetIndex).opcode != Opcode.IGET_OBJECT)
throw PatchException("Failed to find insert index")
val replaceReference = getInstruction<ReferenceInstruction>(targetIndex).reference
val replaceInstruction = getInstruction<TwoRegisterInstruction>(targetIndex)
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, targetIndex + 1,
""" """
invoke-static { }, $SHORTS->disableStartupShortsPlayer()Z invoke-static { }, $SHORTS->disableStartupShortsPlayer()Z
move-result v$insertRegister move-result v${replaceInstruction.registerA}
if-eqz v$insertRegister, :show_startup_shorts_player if-eqz v${replaceInstruction.registerA}, :show_startup_shorts_player
return-void return-void
""", :show_startup_shorts_player
ExternalLabel("show_startup_shorts_player", getInstruction(insertIndex)) iget-object v${replaceInstruction.registerA}, v${replaceInstruction.registerB}, $replaceReference
"""
) )
removeInstruction(targetIndex)
} }
} ?: throw UserWasInShortsFingerprint.exception } ?: throw UserWasInShortsFingerprint.exception

View File

@ -9,6 +9,10 @@ object UserWasInShortsFingerprint : MethodFingerprint(
returnType = "V", returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Ljava/lang/Object;"), parameters = listOf("Ljava/lang/Object;"),
opcodes = listOf(Opcode.CONST_WIDE_32), opcodes = listOf(
null,
Opcode.RETURN_VOID,
Opcode.MOVE_EXCEPTION
),
strings = listOf("Failed to read user_was_in_shorts proto after successful warmup") strings = listOf("Failed to read user_was_in_shorts proto after successful warmup")
) )

View File

@ -7,9 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.IncognitoFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.IncognitoFingerprint
@ -17,6 +15,7 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprin
import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.TextComponentSpecFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.TextComponentSpecFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getTargetIndexReversed
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -30,13 +29,16 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
TextComponentSpecFingerprint TextComponentSpecFingerprint
) )
) { ) {
private const val INTEGRATIONS_RYD_CLASS_DESCRIPTOR =
"$UTILS_PATH/ReturnYouTubeDislikePatch;"
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
ShortsTextViewFingerprint.result?.let { ShortsTextViewFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val isDisLikesBooleanIndex = getTargetIndexDownTo(startIndex, Opcode.IGET_BOOLEAN) val isDisLikesBooleanIndex = getTargetIndexReversed(startIndex, Opcode.IGET_BOOLEAN)
val textViewFieldIndex = getTargetIndexDownTo(startIndex, Opcode.IGET_OBJECT) val textViewFieldIndex = getTargetIndexReversed(startIndex, Opcode.IGET_OBJECT)
// If the field is true, the TextView is for a dislike button. // If the field is true, the TextView is for a dislike button.
val isDisLikesBooleanReference = val isDisLikesBooleanReference =
@ -103,20 +105,4 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
} ?: throw IncognitoFingerprint.exception } ?: throw IncognitoFingerprint.exception
} }
} }
private fun MutableMethod.getTargetIndexDownTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
throw PatchException("Failed to find target method")
}
private const val INTEGRATIONS_RYD_CLASS_DESCRIPTOR =
"$UTILS_PATH/ReturnYouTubeDislikePatch;"
} }

View File

@ -2,7 +2,7 @@ package app.revanced.util
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.PatchException
@ -145,40 +145,21 @@ inline fun <reified T : Reference> Instruction.getReference() =
fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) = fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) =
this.implementation!!.instructions.indexOfFirst(predicate) this.implementation!!.instructions.indexOfFirst(predicate)
/** fun MutableMethod.getTargetIndex(startIndex: Int, opcode: Opcode) =
* Get the index of the last [Instruction] that matches the predicate. implementation!!.instructions.let {
* startIndex + it.subList(startIndex, it.size - 1).indexOfFirst { instruction ->
* @param predicate The predicate to match. instruction.opcode == opcode
* @return The index of the first [Instruction] that matches the predicate. }
*/
fun Method.indexOfLastInstruction(predicate: Instruction.() -> Boolean) =
this.implementation!!.instructions.indexOfFirst(predicate)
/**
* Return the resolved methods of [MethodFingerprint]s early.
*/
fun List<MethodFingerprint>.returnEarly(bool: Boolean = false) {
val const = if (bool) "0x1" else "0x0"
this.forEach { fingerprint ->
fingerprint.result?.let { result ->
val stringInstructions = when (result.method.returnType.first()) {
'L' -> """
const/4 v0, $const
return-object v0
"""
'V' -> "return-void"
'I', 'Z' -> """
const/4 v0, $const
return v0
"""
else -> throw Exception("This case should never happen.")
}
result.mutableMethod.addInstructions(0, stringInstructions)
} ?: throw fingerprint.exception
} }
fun MutableMethod.getTargetIndexReversed(startIndex: Int, opcode: Opcode): Int {
for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
throw PatchException("Failed to find target index")
} }
fun BytecodeContext.updatePatchStatus( fun BytecodeContext.updatePatchStatus(