From 5b476eca3399d09f5c8327f0759820965b18a362 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 20 Jun 2023 14:39:35 +0900 Subject: [PATCH] feat(litho-filter): change to abstract patch --- .../buttonshelf/patch/HideButtonShelfPatch.kt | 2 +- .../patch/HideCarouselShelfPatch.kt | 2 +- .../patch/NewPlaylistButtonPatch.kt | 3 +- .../patch/HidePlaylistCardPatch.kt | 2 +- .../misc/litho/patch/MusicLithoFilterPatch.kt | 71 -------- .../litho/patch/MusicLithoFilterPatch.kt | 26 +++ .../fingerprints/ByteBufferHookFingerprint.kt | 13 ++ ...ingerprint.kt => IdentifierFingerprint.kt} | 5 +- .../fingerprints/LithoBufferFingerprint.kt | 18 -- .../fingerprints/LithoObjectFingerprint.kt | 16 -- .../patch/litho/ComponentParserPatch.kt | 172 ++++++++++++++++++ .../fingerprint/OnBackPressedFingerprint.kt | 9 - .../fingerprint/ScrollPositionFingerprint.kt | 19 -- .../fingerprint/ScrollTopFingerprint.kt | 21 --- .../fingerprint/ScrollTopParentFingerprint.kt | 25 --- .../patch/DoubleBackToClosePatch.kt | 92 ---------- .../bytecode/patch/GeneralAdsBytecodePatch.kt | 2 +- .../general/resource/patch/GeneralAdsPatch.kt | 10 +- .../gestures/PredictiveBackGesturePatch.kt | 35 ---- .../SwipeRefreshLayoutFingerprint.kt | 19 -- .../swiperefresh/patch/SwipeRefreshPatch.kt | 40 ---- .../patch/ButtonContainerPatch.kt | 7 +- .../layout/theme/patch/GeneralThemePatch.kt | 2 +- .../misc/litho/patch/ByteBufferFilterPatch.kt | 50 ----- .../misc/litho/patch/LithoFilterPatch.kt | 116 ------------ .../patch/SuggestedActionsPatch.kt | 2 +- .../bytecode/patch/SeekbarColorPatch.kt | 10 +- .../fingerprints/ByteBufferFingerprint.kt | 25 +++ .../fingerprints/LithoThemeFingerprint.kt | 2 +- .../utils/litho/patch/LithoFilterPatch.kt | 46 +++++ .../litho/patch/LithoThemePatch.kt | 4 +- .../youtube/doubleback/host/values/arrays.xml | 15 ++ 32 files changed, 329 insertions(+), 552 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/music/misc/litho/patch/MusicLithoFilterPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/litho/patch/MusicLithoFilterPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/ByteBufferHookFingerprint.kt rename src/main/kotlin/app/revanced/patches/shared/fingerprints/{LithoFingerprint.kt => IdentifierFingerprint.kt} (80%) delete mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoBufferFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoObjectFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/OnBackPressedFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollPositionFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/patch/DoubleBackToClosePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/gestures/PredictiveBackGesturePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/fingerprint/SwipeRefreshLayoutFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/patch/SwipeRefreshPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/ByteBufferFilterPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoFilterPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/{misc => utils}/litho/fingerprints/LithoThemeFingerprint.kt (90%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt rename src/main/kotlin/app/revanced/patches/youtube/{misc => utils}/litho/patch/LithoThemePatch.kt (94%) create mode 100644 src/main/resources/youtube/doubleback/host/values/arrays.xml diff --git a/src/main/kotlin/app/revanced/patches/music/layout/buttonshelf/patch/HideButtonShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/buttonshelf/patch/HideButtonShelfPatch.kt index d26f23207..adef62d01 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/buttonshelf/patch/HideButtonShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/buttonshelf/patch/HideButtonShelfPatch.kt @@ -9,7 +9,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.misc.litho.patch.MusicLithoFilterPatch +import app.revanced.patches.music.utils.litho.patch.MusicLithoFilterPatch import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.util.enum.CategoryType diff --git a/src/main/kotlin/app/revanced/patches/music/layout/carouselshelf/patch/HideCarouselShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/carouselshelf/patch/HideCarouselShelfPatch.kt index 7fbb5f184..da098b562 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/carouselshelf/patch/HideCarouselShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/carouselshelf/patch/HideCarouselShelfPatch.kt @@ -9,7 +9,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.misc.litho.patch.MusicLithoFilterPatch +import app.revanced.patches.music.utils.litho.patch.MusicLithoFilterPatch import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.util.enum.CategoryType diff --git a/src/main/kotlin/app/revanced/patches/music/layout/floatingbutton/patch/NewPlaylistButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/floatingbutton/patch/NewPlaylistButtonPatch.kt index 989787fef..128d48316 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/floatingbutton/patch/NewPlaylistButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/floatingbutton/patch/NewPlaylistButtonPatch.kt @@ -14,7 +14,8 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.music.layout.floatingbutton.fingerprints.* +import app.revanced.patches.music.layout.floatingbutton.fingerprints.FloatingButtonFingerprint +import app.revanced.patches.music.layout.floatingbutton.fingerprints.FloatingButtonParentFingerprint import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility diff --git a/src/main/kotlin/app/revanced/patches/music/layout/playlistcard/patch/HidePlaylistCardPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/playlistcard/patch/HidePlaylistCardPatch.kt index b1fb5f70b..d35ecfd4d 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/playlistcard/patch/HidePlaylistCardPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/playlistcard/patch/HidePlaylistCardPatch.kt @@ -9,7 +9,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.misc.litho.patch.MusicLithoFilterPatch +import app.revanced.patches.music.utils.litho.patch.MusicLithoFilterPatch import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.util.enum.CategoryType diff --git a/src/main/kotlin/app/revanced/patches/music/misc/litho/patch/MusicLithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/litho/patch/MusicLithoFilterPatch.kt deleted file mode 100644 index a7b9d9fc8..000000000 --- a/src/main/kotlin/app/revanced/patches/music/misc/litho/patch/MusicLithoFilterPatch.kt +++ /dev/null @@ -1,71 +0,0 @@ -package app.revanced.patches.music.misc.litho.patch - -import app.revanced.extensions.toErrorResult -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility -import app.revanced.patches.shared.fingerprints.LithoFingerprint -import app.revanced.util.bytecode.getNarrowLiteralIndex -import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction -import org.jf.dexlib2.iface.reference.FieldReference -import org.jf.dexlib2.iface.reference.MethodReference - -@YouTubeMusicCompatibility -@Version("0.0.1") -class MusicLithoFilterPatch : BytecodePatch( - listOf(LithoFingerprint) -) { - override fun execute(context: BytecodeContext): PatchResult { - LithoFingerprint.result?.let { - it.mutableMethod.apply { - val targetInstruction = implementation!!.instructions - - val endIndex = it.scanResult.patternScanResult!!.endIndex - val bufferIndex = getNarrowLiteralIndex(168777401) - val bufferRegister = getInstruction(bufferIndex).registerA - val targetIndex = targetInstruction.indexOfFirst { instruction -> - instruction.opcode == Opcode.CONST_STRING && - (instruction as BuilderInstruction21c).reference.toString() == "Element missing type extension" - } + 2 - - val builderMethodDescriptor = (getInstruction(targetIndex) as ReferenceInstruction).reference as MethodReference - val emptyComponentFieldDescriptor = (getInstruction(targetIndex + 2) as ReferenceInstruction).reference as FieldReference - val identifierRegister = getInstruction(endIndex).registerA - - targetInstruction.filter { instruction -> - val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference - fieldReference?.let { reference -> reference.type == "Ljava/lang/StringBuilder;" } == true - }.forEach { instruction -> - val insertIndex = targetInstruction.indexOf(instruction) - val stringBuilderRegister = getInstruction(insertIndex).registerA - - addInstructionsWithLabels( - insertIndex, """ - invoke-static {v$stringBuilderRegister, v$identifierRegister}, $MUSIC_ADS_PATH/MusicLithoFilterPatch;->filter(Ljava/lang/StringBuilder;Ljava/lang/String;)Z - move-result v$bufferRegister - if-eqz v$bufferRegister, :not_an_ad - move-object/from16 v$identifierRegister, p1 - invoke-static {v$identifierRegister}, $builderMethodDescriptor - move-result-object v0 - iget-object v0, v0, $emptyComponentFieldDescriptor - return-object v0 - """, ExternalLabel("not_an_ad", getInstruction(insertIndex)) - ) - } - } - } ?: return LithoFingerprint.toErrorResult() - - return PatchResultSuccess() - } -} diff --git a/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/MusicLithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/MusicLithoFilterPatch.kt new file mode 100644 index 000000000..1c1752774 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/litho/patch/MusicLithoFilterPatch.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.music.utils.litho.patch + +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.patches.shared.fingerprints.IdentifierFingerprint +import app.revanced.patches.shared.patch.litho.ComponentParserPatch +import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.identifierHook +import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH + +@DependsOn([ComponentParserPatch::class]) +@YouTubeMusicCompatibility +@Version("0.0.1") +class MusicLithoFilterPatch : BytecodePatch( + listOf(IdentifierFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + identifierHook("$MUSIC_ADS_PATH/MusicLithoFilterPatch;->filter") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/ByteBufferHookFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/ByteBufferHookFingerprint.kt new file mode 100644 index 000000000..fb7d87241 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/ByteBufferHookFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.shared.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object ByteBufferHookFingerprint : MethodFingerprint( + returnType = "L", + opcodes = listOf( + Opcode.ADD_INT_2ADDR, + Opcode.INVOKE_VIRTUAL + ), + strings = listOf("Unssuported TextDecorator adjustment. Extension: %s") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/IdentifierFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/IdentifierFingerprint.kt index 78ff2bde0..14d634486 100644 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/IdentifierFingerprint.kt @@ -5,12 +5,13 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -object LithoFingerprint : MethodFingerprint( +object IdentifierFingerprint : MethodFingerprint( returnType = "L", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, opcodes = listOf( Opcode.INVOKE_VIRTUAL, - Opcode.IF_EQZ + Opcode.IF_EQZ, + Opcode.IPUT_OBJECT ), strings = listOf("Element missing type extension") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoBufferFingerprint.kt deleted file mode 100644 index 4e4f895e1..000000000 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoBufferFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.shared.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object LithoBufferFingerprint : MethodFingerprint( - returnType = "L", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.CHECK_CAST, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.GOTO - ), - strings = listOf("Element missing type extension") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoObjectFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoObjectFingerprint.kt deleted file mode 100644 index e02308632..000000000 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LithoObjectFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.shared.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object LithoObjectFingerprint : MethodFingerprint( - returnType = "L", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.CONST_STRING, - Opcode.INVOKE_VIRTUAL - ), - strings = listOf("Element missing type extension") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt b/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt new file mode 100644 index 000000000..711150257 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/patch/litho/ComponentParserPatch.kt @@ -0,0 +1,172 @@ +package app.revanced.patches.shared.patch.litho + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.or +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.annotation.RVXCompatibility +import app.revanced.patches.shared.fingerprints.ByteBufferHookFingerprint +import app.revanced.patches.shared.fingerprints.EmptyComponentBuilderFingerprint +import app.revanced.patches.shared.fingerprints.IdentifierFingerprint +import app.revanced.util.bytecode.getStringIndex +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction +import org.jf.dexlib2.iface.reference.FieldReference +import org.jf.dexlib2.immutable.ImmutableField +import kotlin.properties.Delegates + +@Name("component-parser-patch") +@RVXCompatibility +@Version("0.0.1") +class ComponentParserPatch : BytecodePatch( + listOf( + ByteBufferHookFingerprint, + EmptyComponentBuilderFingerprint, + IdentifierFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + EmptyComponentBuilderFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getStringIndex("Failed to convert Element to Flatbuffers: %s") + 2 + val builderMethodDescriptor = getInstruction(targetIndex).reference + val emptyComponentFieldDescriptor = getInstruction(targetIndex + 2).reference + + emptyComponentLabel = """ + move-object/from16 v0, p1 + invoke-static {v0}, $builderMethodDescriptor + move-result-object v0 + iget-object v0, v0, $emptyComponentFieldDescriptor + return-object v0 + """ + + it.mutableClass.staticFields.add( + ImmutableField( + definingClass, + "buffer", + "Ljava/nio/ByteBuffer;", + AccessFlags.PUBLIC or AccessFlags.STATIC, + null, + null, + null + ).toMutable() + ) + } + } ?: return EmptyComponentBuilderFingerprint.toErrorResult() + + ByteBufferHookFingerprint.result?.let { + (context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ).apply { + val methodName = EmptyComponentBuilderFingerprint.result!!.mutableMethod.definingClass + + addInstruction( + 0, + "sput-object p2, $methodName->buffer:Ljava/nio/ByteBuffer;" + ) + } + } ?: return ByteBufferHookFingerprint.toErrorResult() + + IdentifierFingerprint.result?.let { + it.mutableMethod.apply { + insertMethod = this + + val stringBuilderIndex = + implementation!!.instructions.indexOfFirst { instruction -> + val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference + fieldReference?.let { reference -> reference.type == "Ljava/lang/StringBuilder;" } == true + } + + val identifierIndex = it.scanResult.patternScanResult!!.endIndex + val objectIndex = getStringIndex("") + 1 + val freeIndex = implementation!!.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.CONST + } + + stringBuilderRegister = getInstruction(stringBuilderIndex).registerA + identifierRegister = getInstruction(identifierIndex).registerA + objectRegister = getInstruction(objectIndex).registerC + freeRegister = getInstruction(freeIndex).registerA + + insertIndex = stringBuilderIndex + 1 + } + } ?: return IdentifierFingerprint.toErrorResult() + + return PatchResultSuccess() + } + + internal companion object { + lateinit var emptyComponentLabel: String + lateinit var insertMethod: MutableMethod + + var insertIndex by Delegates.notNull() + + var freeRegister by Delegates.notNull() + var identifierRegister by Delegates.notNull() + var objectRegister by Delegates.notNull() + var stringBuilderRegister by Delegates.notNull() + + fun generalHook( + descriptor: String + ) { + insertMethod.apply { + addInstructionsWithLabels( + insertIndex, """ + sget-object v$freeRegister, $definingClass->buffer:Ljava/nio/ByteBuffer; + invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$freeRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z + move-result v$freeRegister + if-eqz v$freeRegister, :not_an_ad + """ + emptyComponentLabel, ExternalLabel("not_an_ad", getInstruction(insertIndex)) + ) + } + } + + fun identifierHook( + descriptor: String + ) { + insertMethod.apply { + addInstructionsWithLabels( + insertIndex, """ + invoke-static {v$stringBuilderRegister, v$identifierRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;)Z + move-result v$freeRegister + if-eqz v$freeRegister, :not_an_ad + """ + emptyComponentLabel, ExternalLabel("not_an_ad", getInstruction(insertIndex)) + ) + } + } + + fun objectHook( + descriptor: String + ) { + insertMethod.apply { + addInstructionsWithLabels( + 0, """ + move-object/from16 v0, p2 + sget-object v1, $definingClass->buffer:Ljava/nio/ByteBuffer; + invoke-static {v0, v1}, $descriptor(Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z + move-result v0 + if-eqz v0, :not_an_ad + """ + emptyComponentLabel, ExternalLabel("not_an_ad", getInstruction(0)) + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/OnBackPressedFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/OnBackPressedFingerprint.kt deleted file mode 100644 index 80d986080..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/OnBackPressedFingerprint.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.Opcode - -object OnBackPressedFingerprint : MethodFingerprint( - opcodes = listOf(Opcode.RETURN_VOID), - customFingerprint = { it, _ -> it.definingClass.endsWith("WatchWhileActivity;") && it.name == "onBackPressed" } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollPositionFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollPositionFingerprint.kt deleted file mode 100644 index 57a0197fc..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollPositionFingerprint.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object ScrollPositionFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.IF_NEZ, - Opcode.INVOKE_DIRECT, - Opcode.RETURN_VOID - ), - strings = listOf("scroll_position") -) - diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopFingerprint.kt deleted file mode 100644 index d9ff3df58..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopFingerprint.kt +++ /dev/null @@ -1,21 +0,0 @@ -package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object ScrollTopFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf(), - opcodes = listOf( - Opcode.CHECK_CAST, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.GOTO, - Opcode.IGET_OBJECT, - Opcode.INVOKE_INTERFACE - ) -) - diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt deleted file mode 100644 index 366d69a72..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/fingerprint/ScrollTopParentFingerprint.kt +++ /dev/null @@ -1,25 +0,0 @@ -package app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object ScrollTopParentFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - opcodes = listOf( - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.CONST_16, - Opcode.INVOKE_VIRTUAL, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.RETURN_VOID - ), - customFingerprint = { it, _ -> it.name == ""} -) - diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/patch/DoubleBackToClosePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/patch/DoubleBackToClosePatch.kt deleted file mode 100644 index 764bfc3dc..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/doublebacktoclose/patch/DoubleBackToClosePatch.kt +++ /dev/null @@ -1,92 +0,0 @@ -package app.revanced.patches.youtube.ads.doublebacktoclose.patch - -import app.revanced.extensions.toErrorResult -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.data.toMethodWalker -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.ads.gestures.PredictiveBackGesturePatch -import app.revanced.patches.youtube.ads.doublebacktoclose.fingerprint.* -import app.revanced.util.integrations.Constants.UTILS_PATH - -@Name("double-back-to-close") -@DependsOn([PredictiveBackGesturePatch::class]) -@YouTubeCompatibility -@Version("0.0.1") -class DoubleBackToClosePatch : BytecodePatch( - listOf( - OnBackPressedFingerprint, - ScrollPositionFingerprint, - ScrollTopParentFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - - /** - * Hook onBackPressed method inside WatchWhileActivity - */ - OnBackPressedFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - - addInstruction( - insertIndex, - "invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR" + - "->" + - "closeActivityOnBackPressed(Landroid/app/Activity;)V" - ) - } - } ?: return OnBackPressedFingerprint.toErrorResult() - - - /** - * Inject the methods which start of ScrollView - */ - ScrollPositionFingerprint.result?.let { - val insertMethod = context.toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.startIndex + 1, true) - .getMethod() as MutableMethod - - val insertIndex = insertMethod.implementation!!.instructions.size - 1 - 1 - - insertMethod.injectScrollView(insertIndex, "onStartScrollView") - } ?: return ScrollPositionFingerprint.toErrorResult() - - - /**Inject the methods which stop of ScrollView - */ - ScrollTopParentFingerprint.result?.let { parentResult -> - ScrollTopFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - val insertMethod = it.mutableMethod - val insertIndex = it.scanResult.patternScanResult!!.endIndex - - insertMethod.injectScrollView(insertIndex, "onStopScrollView") - } ?: return ScrollTopFingerprint.toErrorResult() - } ?: return ScrollTopParentFingerprint.toErrorResult() - - return PatchResultSuccess() - } - - private companion object { - const val INTEGRATIONS_CLASS_DESCRIPTOR = - "$UTILS_PATH/DoubleBackToClosePatch;" - - fun MutableMethod.injectScrollView( - index: Int, - descriptor: String - ) { - addInstruction( - index, - "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->$descriptor()V" - ) - } - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/general/bytecode/patch/GeneralAdsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/general/bytecode/patch/GeneralAdsBytecodePatch.kt index 978d400ea..21f87ff63 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/general/bytecode/patch/GeneralAdsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/general/bytecode/patch/GeneralAdsBytecodePatch.kt @@ -32,7 +32,7 @@ class GeneralAdsBytecodePatch : BytecodePatch() { .mutableClass .findMutableMethodOf(method) .apply { - val insertIndex = method.getWideLiteralIndex(AdAttribution) + 1 + val insertIndex = getWideLiteralIndex(AdAttribution) + 1 if (getInstruction(insertIndex).opcode != org.jf.dexlib2.Opcode.INVOKE_VIRTUAL) return@forEach diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/general/resource/patch/GeneralAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/general/resource/patch/GeneralAdsPatch.kt index 3033aba2b..6801b215b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/general/resource/patch/GeneralAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/general/resource/patch/GeneralAdsPatch.kt @@ -14,8 +14,9 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.ads.general.bytecode.patch.GeneralAdsBytecodePatch import app.revanced.patches.youtube.ads.getpremium.patch.HideGetPremiumPatch -import app.revanced.patches.youtube.misc.litho.patch.ByteBufferFilterPatch +import app.revanced.patches.youtube.utils.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.resources.ResourceUtils.copyXmlNode import org.w3c.dom.Element @Patch @@ -23,9 +24,9 @@ import org.w3c.dom.Element @Description("Removes general ads.") @DependsOn( [ - ByteBufferFilterPatch::class, GeneralAdsBytecodePatch::class, HideGetPremiumPatch::class, + LithoFilterPatch::class, SettingsPatch::class ] ) @@ -84,6 +85,11 @@ class GeneralAdsPatch : ResourcePatch { } } + /** + * Copy arrays + */ + context.copyXmlNode("youtube/doubleback/host", "values/arrays.xml", "resources") + /* * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/gestures/PredictiveBackGesturePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/gestures/PredictiveBackGesturePatch.kt deleted file mode 100644 index 4a8d11809..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/gestures/PredictiveBackGesturePatch.kt +++ /dev/null @@ -1,35 +0,0 @@ -package app.revanced.patches.youtube.ads.gestures - -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch - -@Name("predictive-back-gesture") -@Description("Enables the predictive back gesture introduced on Android 13.") -@Version("0.0.1") -class PredictiveBackGesturePatch : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { - context.xmlEditor["AndroidManifest.xml"].use { editor -> - val document = editor.file - - with(document.getElementsByTagName("application").item(0)) { - if (attributes.getNamedItem(FLAG) != null) return@with - - document.createAttribute(FLAG) - .apply { value = "false" } - .let(attributes::setNamedItem) - - } - } - - return PatchResultSuccess() - } - - private companion object { - const val FLAG = "android:enableOnBackInvokedCallback" - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/fingerprint/SwipeRefreshLayoutFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/fingerprint/SwipeRefreshLayoutFingerprint.kt deleted file mode 100644 index 86118cf30..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/fingerprint/SwipeRefreshLayoutFingerprint.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patches.youtube.ads.swiperefresh.fingerprint - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object SwipeRefreshLayoutFingerprint : MethodFingerprint( - returnType = "Z", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf(), - opcodes = listOf( - Opcode.RETURN, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.RETURN - ), - customFingerprint = { it, _ -> it.definingClass.endsWith("SwipeRefreshLayout;") } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/patch/SwipeRefreshPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/patch/SwipeRefreshPatch.kt deleted file mode 100644 index f82bd0001..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/swiperefresh/patch/SwipeRefreshPatch.kt +++ /dev/null @@ -1,40 +0,0 @@ -package app.revanced.patches.youtube.ads.swiperefresh.patch - -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -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.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.youtube.ads.swiperefresh.fingerprint.SwipeRefreshLayoutFingerprint -import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.extensions.toErrorResult -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction - -@Name("enable-swipe-refresh") -@Description("Enable swipe refresh.") -@YouTubeCompatibility -@Version("0.0.1") -class SwipeRefreshPatch : BytecodePatch( - listOf(SwipeRefreshLayoutFingerprint) -) { - override fun execute(context: BytecodeContext): PatchResult { - - SwipeRefreshLayoutFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = getInstruction(insertIndex).registerA - - addInstruction( - insertIndex, - "const/4 v$register, 0x0" - ) - } - } ?: return SwipeRefreshLayoutFingerprint.toErrorResult() - - return PatchResultSuccess() - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt index 045b38780..642a15b00 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt @@ -10,7 +10,8 @@ import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.misc.litho.patch.ByteBufferFilterPatch +import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.objectHook +import app.revanced.patches.youtube.utils.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.BOTTOM_PLAYER @@ -19,7 +20,7 @@ import app.revanced.util.integrations.Constants.BOTTOM_PLAYER @Description("Adds the options to hide action buttons under a video.") @DependsOn( [ - ByteBufferFilterPatch::class, + LithoFilterPatch::class, SettingsPatch::class ] ) @@ -28,7 +29,7 @@ import app.revanced.util.integrations.Constants.BOTTOM_PLAYER class ButtonContainerPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - ByteBufferFilterPatch.inject("$BOTTOM_PLAYER->hideActionButtons") + objectHook("$BOTTOM_PLAYER->hideActionButton") /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/GeneralThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/GeneralThemePatch.kt index 7d775fd06..81349340e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/GeneralThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/GeneralThemePatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch +import app.revanced.patches.youtube.utils.litho.patch.LithoThemePatch import app.revanced.util.integrations.Constants.UTILS_PATH import org.w3c.dom.Element diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/ByteBufferFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/ByteBufferFilterPatch.kt deleted file mode 100644 index 20a720d3f..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/ByteBufferFilterPatch.kt +++ /dev/null @@ -1,50 +0,0 @@ -package app.revanced.patches.youtube.misc.litho.patch - -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.utils.playertype.patch.PlayerTypeHookPatch - -@DependsOn( - [ - LithoFilterPatch::class, - PlayerTypeHookPatch::class - ] -) -@YouTubeCompatibility -@Version("0.0.1") -class ByteBufferFilterPatch : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { - return PatchResultSuccess() - } - - companion object{ - fun inject(descriptor: String){ - LithoFilterPatch.lithoMethod.addInstructionsWithLabels( - 0, """ - move-object/from16 v10, p3 - iget-object v10, v10, ${LithoFilterPatch.objectReference} - if-eqz v10, :do_not_block - check-cast v10, ${LithoFilterPatch.bufferReference} - iget-object v10, v10, ${LithoFilterPatch.bufferReference}->b:Ljava/nio/ByteBuffer; - move-object/from16 v3, p2 - invoke-static {v3, v10}, $descriptor(Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z - move-result v10 - if-eqz v10, :do_not_block - move-object/from16 v15, p1 - invoke-static {v15}, ${LithoFilterPatch.builderMethodDescriptor} - move-result-object v0 - iget-object v0, v0, ${LithoFilterPatch.emptyComponentFieldDescriptor} - return-object v0 - """, ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.getInstruction(0)) - ) - } - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoFilterPatch.kt deleted file mode 100644 index 915fd0c61..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoFilterPatch.kt +++ /dev/null @@ -1,116 +0,0 @@ -package app.revanced.patches.youtube.misc.litho.patch - -import app.revanced.extensions.toErrorResult -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.shared.fingerprints.LithoBufferFingerprint -import app.revanced.patches.shared.fingerprints.LithoFingerprint -import app.revanced.patches.shared.fingerprints.LithoObjectFingerprint -import app.revanced.patches.youtube.ads.doublebacktoclose.patch.DoubleBackToClosePatch -import app.revanced.patches.youtube.ads.swiperefresh.patch.SwipeRefreshPatch -import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus -import app.revanced.util.bytecode.getNarrowLiteralIndex -import app.revanced.util.bytecode.getStringIndex -import app.revanced.util.integrations.Constants.ADS_PATH -import org.jf.dexlib2.builder.instruction.BuilderInstruction35c -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction -import org.jf.dexlib2.iface.reference.FieldReference -import org.jf.dexlib2.iface.reference.Reference -import kotlin.properties.Delegates - -@DependsOn( - [ - DoubleBackToClosePatch::class, - SwipeRefreshPatch::class - ] -) -@YouTubeCompatibility -@Version("0.0.1") -class LithoFilterPatch : BytecodePatch( - listOf( - LithoFingerprint, - LithoBufferFingerprint, - LithoObjectFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - - LithoBufferFingerprint.result?.let { - val startIndex = it.scanResult.patternScanResult!!.startIndex - bufferReference = it.mutableMethod.getInstruction(startIndex).reference - } ?: return LithoBufferFingerprint.toErrorResult() - - LithoObjectFingerprint.result?.let { - val endIndex = it.scanResult.patternScanResult!!.endIndex - objectRegister = it.mutableMethod.getInstruction(endIndex).registerC - } ?: return LithoObjectFingerprint.toErrorResult() - - LithoFingerprint.result?.let { result -> - val endIndex = result.scanResult.patternScanResult!!.endIndex - lithoMethod = result.mutableMethod - - lithoMethod.apply { - val bufferIndex = getNarrowLiteralIndex(168777401) - val bufferRegister = getInstruction(bufferIndex).registerA - val targetIndex = getStringIndex("Element missing type extension") + 2 - val identifierRegister = getInstruction(endIndex).registerA - - builderMethodDescriptor = getInstruction(targetIndex).reference - emptyComponentFieldDescriptor = getInstruction(targetIndex + 2).reference - implementation!!.instructions.apply { - filter { instruction -> - val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference - fieldReference?.let { it.type == "Ljava/lang/StringBuilder;" } == true - }.forEach { instruction -> - val insertIndex = indexOf(instruction) - val stringBuilderRegister = lithoMethod.getInstruction(insertIndex).registerA - - val objectIndex = lithoMethod.getStringIndex("") - 2 - objectReference = lithoMethod.getInstruction(objectIndex).reference - lithoMethod.addInstructionsWithLabels( - insertIndex + 1, """ - move-object/from16 v$bufferRegister, p3 - iget-object v$bufferRegister, v$bufferRegister, $objectReference - if-eqz v$bufferRegister, :not_an_ad - check-cast v$bufferRegister, $bufferReference - iget-object v$bufferRegister, v$bufferRegister, $bufferReference->b:Ljava/nio/ByteBuffer; - invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$bufferRegister}, $ADS_PATH/LithoFilterPatch;->filters(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z - move-result v$bufferRegister - if-eqz v$bufferRegister, :not_an_ad - move-object/from16 v$identifierRegister, p1 - invoke-static {v$identifierRegister}, $builderMethodDescriptor - move-result-object v0 - iget-object v0, v0, $emptyComponentFieldDescriptor - return-object v0 - """, ExternalLabel("not_an_ad", lithoMethod.getInstruction(insertIndex + 1)) - ) - } - } - } - } ?: return LithoFingerprint.toErrorResult() - - context.updatePatchStatus("ByteBuffer") - - return PatchResultSuccess() - } - internal companion object { - var objectRegister by Delegates.notNull() - - lateinit var lithoMethod: MutableMethod - lateinit var bufferReference: Reference - lateinit var builderMethodDescriptor: Reference - lateinit var emptyComponentFieldDescriptor: Reference - lateinit var objectReference: Reference - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/patch/SuggestedActionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/patch/SuggestedActionsPatch.kt index 82792ea1b..737225190 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/patch/SuggestedActionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/patch/SuggestedActionsPatch.kt @@ -14,7 +14,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.player.suggestactions.fingerprints.SuggestedActionsFingerprint -import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch +import app.revanced.patches.youtube.utils.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch import org.jf.dexlib2.iface.instruction.OneRegisterInstruction diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/seekbarcolor/bytecode/patch/SeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/seekbarcolor/bytecode/patch/SeekbarColorPatch.kt index 97630ecb7..3d29eba11 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/seekbarcolor/bytecode/patch/SeekbarColorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/seekbarcolor/bytecode/patch/SeekbarColorPatch.kt @@ -19,7 +19,7 @@ import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint import app.revanced.patches.youtube.seekbar.seekbarcolor.bytecode.fingerprints.ProgressColorFingerprint import app.revanced.patches.youtube.seekbar.seekbarcolor.bytecode.fingerprints.SeekbarColorFingerprint import app.revanced.patches.youtube.seekbar.seekbarcolor.resource.patch.SeekbarColorResourcePatch -import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch +import app.revanced.patches.youtube.utils.litho.patch.LithoThemePatch import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarColorizedBarPlayedColorDark import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarPlayedNotHighlightedColor @@ -48,9 +48,11 @@ class SeekbarColorPatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext): PatchResult { - SeekbarColorFingerprint.result?.mutableMethod?.let { - it.hook(it.getWideLiteralIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2) - it.hook(it.getWideLiteralIndex(InlineTimeBarPlayedNotHighlightedColor) + 2) + SeekbarColorFingerprint.result?.let { + it.mutableMethod.apply { + hook(getWideLiteralIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2) + hook(getWideLiteralIndex(InlineTimeBarPlayedNotHighlightedColor) + 2) + } } ?: return SeekbarColorFingerprint.toErrorResult() ControlsOverlayStyleFingerprint.result?.let { parentResult -> diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt new file mode 100644 index 000000000..93358a6a3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/ByteBufferFingerprint.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtube.utils.litho.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object ByteBufferFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("L","L"), + opcodes = listOf( + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.ADD_INT_2ADDR, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LithoThemeFingerprint.kt similarity index 90% rename from src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LithoThemeFingerprint.kt index a5af1f6cb..1630dc9b4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/fingerprints/LithoThemeFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.litho.fingerprints +package app.revanced.patches.youtube.utils.litho.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt new file mode 100644 index 000000000..2acbdda21 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoFilterPatch.kt @@ -0,0 +1,46 @@ +package app.revanced.patches.youtube.utils.litho.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.shared.patch.litho.ComponentParserPatch +import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.generalHook +import app.revanced.patches.youtube.utils.fix.doublebacktoclose.patch.DoubleBackToClosePatch +import app.revanced.patches.youtube.utils.fix.swiperefresh.patch.SwipeRefreshPatch +import app.revanced.patches.youtube.utils.litho.fingerprints.ByteBufferFingerprint +import app.revanced.patches.youtube.utils.playertype.patch.PlayerTypeHookPatch +import app.revanced.util.integrations.Constants.ADS_PATH + +@DependsOn( + [ + ComponentParserPatch::class, + DoubleBackToClosePatch::class, + PlayerTypeHookPatch::class, + SwipeRefreshPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class LithoFilterPatch : BytecodePatch( + listOf(ByteBufferFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + + ByteBufferFingerprint.result?.mutableMethod?.addInstruction( + 0, + "sput-object p0, $ADS_PATH/ByteBufferFilterPatch;->bytebuffer:Ljava/nio/ByteBuffer;" + ) ?: return ByteBufferFingerprint.toErrorResult() + + + generalHook("$ADS_PATH/LithoFilterPatch;->filters") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoThemePatch.kt similarity index 94% rename from src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoThemePatch.kt index 8a6ec4554..767aca45a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/litho/patch/LithoThemePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.litho.patch +package app.revanced.patches.youtube.utils.litho.patch import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Name @@ -10,7 +10,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.misc.litho.fingerprints.LithoThemeFingerprint +import app.revanced.patches.youtube.utils.litho.fingerprints.LithoThemeFingerprint import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.formats.Instruction35c import org.jf.dexlib2.iface.reference.MethodReference diff --git a/src/main/resources/youtube/doubleback/host/values/arrays.xml b/src/main/resources/youtube/doubleback/host/values/arrays.xml new file mode 100644 index 000000000..cc7d2348b --- /dev/null +++ b/src/main/resources/youtube/doubleback/host/values/arrays.xml @@ -0,0 +1,15 @@ + + + + 0 + 1 + 2 + 3 + + + 0 + 1 + 2 + 3 + +