diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/ClientInfoFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/ClientInfoFingerprint.kt index d287b958a..68c180f79 100644 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/ClientInfoFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/ClientInfoFingerprint.kt @@ -9,7 +9,5 @@ object ClientInfoFingerprint : MethodFingerprint( returnType = "L", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf(), - opcodes = listOf( - Opcode.OR_INT_LIT16 - ) + opcodes = listOf(Opcode.OR_INT_LIT16) ) 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 index 576bcbc01..9df39c9c2 100644 --- 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 @@ -4,11 +4,6 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.Opcode object OnBackPressedFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.RETURN_VOID - ), - customFingerprint = { methodDef -> - methodDef.definingClass.endsWith("WatchWhileActivity;") - && methodDef.name == "onBackPressed" - } + opcodes = listOf(Opcode.RETURN_VOID), + customFingerprint = { it.definingClass.endsWith("WatchWhileActivity;") && it.name == "onBackPressed" } ) 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 index 223d6c7ef..d38baa10b 100644 --- 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 @@ -30,25 +30,25 @@ class DoubleBackToClosePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { - /* - Hook onBackPressed method inside WatchWhileActivity + /** + * Hook onBackPressed method inside WatchWhileActivity */ OnBackPressedFingerprint.result?.let { - val insertIndex = it.scanResult.patternScanResult!!.endIndex + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex - with(it.mutableMethod) { addInstruction( insertIndex, "invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR" + - "->" + - "closeActivityOnBackPressed(Landroid/app/Activity;)V" + "->" + + "closeActivityOnBackPressed(Landroid/app/Activity;)V" ) } } ?: return OnBackPressedFingerprint.toErrorResult() - /* - Inject the methods which start of ScrollView + /** + * Inject the methods which start of ScrollView */ ScrollPositionFingerprint.result?.let { val insertMethod = context.toMethodWalker(it.method) @@ -57,19 +57,18 @@ class DoubleBackToClosePatch : BytecodePatch( val insertIndex = insertMethod.implementation!!.instructions.size - 1 - 1 - injectScrollView(insertMethod, insertIndex, "onStartScrollView") + insertMethod.injectScrollView(insertIndex, "onStartScrollView") } ?: return ScrollPositionFingerprint.toErrorResult() - /* - Inject the methods which stop of ScrollView + /**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 - injectScrollView(insertMethod, insertIndex, "onStopScrollView") + insertMethod.injectScrollView(insertIndex, "onStopScrollView") } ?: return ScrollTopFingerprint.toErrorResult() } ?: return ScrollTopParentFingerprint.toErrorResult() @@ -80,12 +79,11 @@ class DoubleBackToClosePatch : BytecodePatch( const val INTEGRATIONS_CLASS_DESCRIPTOR = "$UTILS_PATH/DoubleBackToClosePatch;" - fun injectScrollView( - method: MutableMethod, + fun MutableMethod.injectScrollView( index: Int, descriptor: String ) { - method.addInstruction( + 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 3a9ae3238..86fe1fb67 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 @@ -5,48 +5,44 @@ import app.revanced.extensions.injectHideCall import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.instruction 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.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.adAttributionId import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus -import org.jf.dexlib2.iface.instruction.formats.Instruction31i +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.iface.instruction.formats.Instruction35c @Name("hide-general-ads-bytecode-patch") @DependsOn([SharedResourceIdPatch::class]) @Version("0.0.1") +@Suppress("LABEL_NAME_CLASH") class GeneralAdsBytecodePatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { context.classes.forEach { classDef -> classDef.methods.forEach { method -> - with(method.implementation) { - this?.instructions?.forEachIndexed { index, instruction -> - if (instruction.opcode != org.jf.dexlib2.Opcode.CONST) - return@forEachIndexed - // Instruction to store the id adAttribution into a register - if ((instruction as Instruction31i).wideLiteral != SharedResourceIdPatch.adAttributionLabelId) - return@forEachIndexed + if (!method.isWideLiteralExists(adAttributionId)) + return@forEach - val insertIndex = index + 1 + context.proxy(classDef) + .mutableClass + .findMutableMethodOf(method) + .apply { + val insertIndex = method.getWideLiteralIndex(adAttributionId) + 1 + if (instruction(insertIndex).opcode != org.jf.dexlib2.Opcode.INVOKE_VIRTUAL) + return@forEach - // Call to get the view with the id adAttribution - with(instructions.elementAt(insertIndex)) { - if (opcode != org.jf.dexlib2.Opcode.INVOKE_VIRTUAL) - return@forEachIndexed + val viewRegister = instruction(insertIndex).registerC - // Hide the view - val viewRegister = (this as Instruction35c).registerC - context.proxy(classDef) - .mutableClass - .findMutableMethodOf(method) - .implementation!!.injectHideCall(insertIndex, viewRegister, "ads/GeneralAdsPatch", "hideAdAttributionView") - } + this.implementation!!.injectHideCall(insertIndex, viewRegister, "ads/GeneralAdsPatch", "hideAdAttributionView") } - } } } + context.updatePatchStatus("GeneralAds") return PatchResultSuccess() 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 43d5f4452..121483b42 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,6 +14,7 @@ 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.misc.litho.patch.LithoFilterPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import org.w3c.dom.Element @@ -23,9 +24,9 @@ import org.w3c.dom.Element @Description("Removes general ads.") @DependsOn( [ - HideGetPremiumPatch::class, + ByteBufferFilterPatch::class, GeneralAdsBytecodePatch::class, - LithoFilterPatch::class, + HideGetPremiumPatch::class, SettingsPatch::class ] ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/patch/HideGetPremiumPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/patch/HideGetPremiumPatch.kt index bd984ded2..d0ff8d2dc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/patch/HideGetPremiumPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/patch/HideGetPremiumPatch.kt @@ -17,17 +17,15 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @Name("hide-get-premium") @Version("0.0.1") class HideGetPremiumPatch : BytecodePatch( - listOf( - CompactYpcOfferModuleViewFingerprint - ) + listOf(CompactYpcOfferModuleViewFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { CompactYpcOfferModuleViewFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex - val measuredWidthRegister = (instruction(startIndex) as TwoRegisterInstruction).registerA - val measuredHeightInstruction = instruction(startIndex + 1) as TwoRegisterInstruction + val measuredWidthRegister = instruction(startIndex).registerA + val measuredHeightInstruction = instruction(startIndex + 1) val measuredHeightRegister = measuredHeightInstruction.registerA val tempRegister = measuredHeightInstruction.registerB 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 index 3a280d005..609ab7a1c 100644 --- 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 @@ -15,5 +15,5 @@ object SwipeRefreshLayoutFingerprint : MethodFingerprint( Opcode.MOVE_RESULT, Opcode.RETURN ), - customFingerprint = { it.definingClass == "Landroidx/swiperefreshlayout/widget/SwipeRefreshLayout;" } + customFingerprint = { 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 index 0733ca8fb..0874d3e3e 100644 --- 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 @@ -19,16 +19,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class SwipeRefreshPatch : BytecodePatch( - listOf( - SwipeRefreshLayoutFingerprint - ) + listOf(SwipeRefreshLayoutFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { SwipeRefreshLayoutFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex) as OneRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstruction( insertIndex, diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/video/patch/VideoAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/video/patch/VideoAdsPatch.kt index eff53a959..d87a6db03 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/video/patch/VideoAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/video/patch/VideoAdsPatch.kt @@ -12,7 +12,6 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.patch.videoads.GeneralVideoAdsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch -import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus import app.revanced.util.integrations.Constants.ADS_PATH @Patch @@ -32,8 +31,6 @@ class VideoAdsPatch : BytecodePatch() { GeneralVideoAdsPatch.injectLegacyAds(INTEGRATIONS_CLASS_DESCRIPTOR) GeneralVideoAdsPatch.injectMainstreamAds(INTEGRATIONS_CLASS_DESCRIPTOR) - context.updatePatchStatus("VideoAds") - /* * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt index c835f81bc..fa45f8900 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/RepeatListenerFingerprint.kt @@ -15,7 +15,5 @@ object RepeatListenerFingerprint : MethodFingerprint( Opcode.CHECK_CAST, Opcode.CONST_WIDE_32 ), - strings = listOf( - "ppoobsa" - ) + strings = listOf("ppoobsa") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/VideoEndFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/VideoEndFingerprint.kt index 335dc63f6..238f92bc0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/VideoEndFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/fingerprints/VideoEndFingerprint.kt @@ -8,5 +8,5 @@ object VideoEndFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf(), - customFingerprint = { methodDef -> methodDef.implementation!!.instructions.count() == 3 && methodDef.annotations.isEmpty()} + customFingerprint = { it.implementation!!.instructions.count() == 3 && it.annotations.isEmpty()} ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt index 90252fa66..7a2b71fa5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/button/autorepeat/patch/AutoRepeatPatch.kt @@ -16,6 +16,7 @@ import app.revanced.util.integrations.Constants.UTILS_PATH import app.revanced.util.integrations.Constants.VIDEO_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.formats.Instruction31i @Name("always-autorepeat") @@ -45,40 +46,39 @@ class AutoRepeatPatch : BytecodePatch( } ?: return VideoEndParentFingerprint.toErrorResult() RepeatListenerFingerprint.result?.let { - val targetIndex = it.scanResult.patternScanResult!!.startIndex - 1 - val endIndex = it.scanResult.patternScanResult!!.endIndex - with (it.mutableMethod) { - val targetReference = (instruction(targetIndex) as BuilderInstruction35c).reference.toString() + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.startIndex - 1 + val endIndex = it.scanResult.patternScanResult!!.endIndex - val firstRegister = (instruction(targetIndex) as BuilderInstruction35c).registerC - val secondRegister = (instruction(targetIndex) as BuilderInstruction35c).registerD + val registerC = instruction(targetIndex).registerC + val registerD = instruction(targetIndex).registerD - val dummyRegister = (instruction(endIndex) as Instruction31i).registerA + val dummyRegister = (instruction(endIndex) as Instruction31i).registerA - addInstructions( - targetIndex + 1, """ + val targetReference = instruction(targetIndex).reference + + addInstructions( + targetIndex + 1, """ invoke-static {}, $UTILS_PATH/EnableAutoRepeatPatch;->shouldAutoRepeat()Z move-result v$dummyRegister if-nez v$dummyRegister, :bypass - invoke-virtual {v$firstRegister, v$secondRegister}, $targetReference + invoke-virtual {v$registerC, v$registerD}, $targetReference """, listOf(ExternalLabel("bypass", instruction(targetIndex + 1))) - ) - removeInstruction(targetIndex) - } + ) + removeInstruction(targetIndex) + } } ?: return RepeatListenerFingerprint.toErrorResult() AutoNavInformerFingerprint.result?.mutableMethod?.let { - with (it.implementation!!.instructions) { - val index = this.size - 1 - 1 - val register = (this[index] as OneRegisterInstruction).registerA - it.addInstructions( - index + 1, """ + val index = it.implementation!!.instructions.size - 1 - 1 + val register = it.instruction(index).registerA + + it.addInstructions( + index + 1, """ invoke-static {v$register}, $UTILS_PATH/EnableAutoRepeatPatch;->enableAutoRepeat(Z)Z move-result v0 """ - ) - - } + ) } ?: return AutoNavInformerFingerprint.toErrorResult() return PatchResultSuccess() diff --git a/src/main/kotlin/app/revanced/patches/youtube/button/overlaybuttons/bytecode/patch/OverlayButtonsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/button/overlaybuttons/bytecode/patch/OverlayButtonsBytecodePatch.kt index 0840bf747..3fbc6365d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/button/overlaybuttons/bytecode/patch/OverlayButtonsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/button/overlaybuttons/bytecode/patch/OverlayButtonsBytecodePatch.kt @@ -25,14 +25,14 @@ class OverlayButtonsBytecodePatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { arrayOf( - "$BUTTON_PATH/Download;", - "$BUTTON_PATH/AutoRepeat;", - "$BUTTON_PATH/CopyWithTimeStamp;", - "$BUTTON_PATH/Copy;", - "$BUTTON_PATH/Speed;" - ).forEach { descriptor -> - PlayerControlsPatch.initializeControl(descriptor) - PlayerControlsPatch.injectVisibility(descriptor) + "Download", + "AutoRepeat", + "CopyWithTimeStamp", + "Copy", + "Speed" + ).forEach { + PlayerControlsPatch.initializeControl("$BUTTON_PATH/$it;") + PlayerControlsPatch.injectVisibility("$BUTTON_PATH/$it;") } return PatchResultSuccess() diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt index ec34f48ea..5a9e61fa5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/buttoncontainer/patch/ButtonContainerPatch.kt @@ -4,17 +4,13 @@ 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.extensions.addInstructions -import app.revanced.patcher.extensions.instruction 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.patch.annotations.Patch -import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch -import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch +import app.revanced.patches.youtube.misc.litho.patch.ByteBufferFilterPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.BOTTOM_PLAYER @@ -23,8 +19,7 @@ import app.revanced.util.integrations.Constants.BOTTOM_PLAYER @Description("Adds the options to hide action buttons under a video.") @DependsOn( [ - LithoFilterPatch::class, - PlayerTypeHookPatch::class, + ByteBufferFilterPatch::class, SettingsPatch::class ] ) @@ -33,32 +28,9 @@ import app.revanced.util.integrations.Constants.BOTTOM_PLAYER class ButtonContainerPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - val instructionList = - """ - move-object/from16 v3, p2 - invoke-static {v3, v10}, $BOTTOM_PLAYER->hideActionButtons(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 - """ + ByteBufferFilterPatch.inject("$BOTTOM_PLAYER->hideActionButtons") - with(LithoFilterPatch.lithoMethod) { - addInstructions( - 0, """ - move-object/from16 v10, p3 - iget-object v10, v10, ${LithoFilterPatch.objectReference.definingClass}->${LithoFilterPatch.objectReference.name}:${LithoFilterPatch.objectReference.type} - if-eqz v10, :do_not_block - check-cast v10, ${LithoFilterPatch.bufferReference} - iget-object v10, v10, ${LithoFilterPatch.bufferReference}->b:Ljava/nio/ByteBuffer; - """ + instructionList,listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(0))) - ) - } - - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/comment/patch/CommentComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/comment/patch/CommentComponentPatch.kt index ade18317e..6c83c074a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/comment/patch/CommentComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttomplayer/comment/patch/CommentComponentPatch.kt @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch class CommentComponentPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/forcebackground/patch/PlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/forcebackground/patch/PlayerButtonBackgroundPatch.kt index d2c89b7ef..72971cdaf 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/forcebackground/patch/PlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/forcebackground/patch/PlayerButtonBackgroundPatch.kt @@ -21,18 +21,11 @@ import org.w3c.dom.Element @YouTubeCompatibility @Version("0.0.1") class PlayerButtonBackgroundPatch : ResourcePatch { - private companion object { - const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml" - val replacements = arrayOf( - "color" - ) - } - override fun execute(context: ResourceContext): PatchResult { - context.xmlEditor[RESOURCE_FILE_PATH].use { editor -> + context.xmlEditor["res/drawable/player_button_circle_background.xml"].use { editor -> editor.file.doRecursively { node -> - replacements.forEach replacement@{ replacement -> + arrayOf("color").forEach replacement@{ replacement -> if (node !is Element) return@replacement node.getAttributeNode("android:$replacement")?.let { attribute -> diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt index 2c155ade1..8e4dd4c17 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt @@ -14,9 +14,9 @@ import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme +import app.revanced.util.resources.ResourceUtils +import app.revanced.util.resources.ResourceUtils.copyResources import app.revanced.util.resources.ResourceUtils.copyXmlNode -import java.nio.file.Files -import java.nio.file.StandardCopyOption @Patch(false) @Name("materialyou") @@ -32,35 +32,28 @@ import java.nio.file.StandardCopyOption class MaterialYouPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - val drawables1 = "drawable-night-v31" to arrayOf( - "new_content_dot_background.xml" - ) - - val drawables2 = "drawable-v31" to arrayOf( - "new_content_count_background.xml", - "new_content_dot_background.xml" - ) - - val layout1 = "layout-v31" to arrayOf( - "new_content_count.xml" - ) - - arrayOf(drawables1, drawables2, layout1).forEach { (path, resourceNames) -> - Files.createDirectory(context["res"].resolve(path).toPath()) - resourceNames.forEach { name -> - val monetPath = "$path/$name" - - Files.copy( - this.javaClass.classLoader.getResourceAsStream("youtube/materialyou/$monetPath")!!, - context["res"].resolve(monetPath).toPath(), - StandardCopyOption.REPLACE_EXISTING - ) - } + arrayOf( + ResourceUtils.ResourceGroup( + "drawable-night-v31", + "new_content_dot_background.xml" + ), + ResourceUtils.ResourceGroup( + "drawable-v31", + "new_content_count_background.xml", + "new_content_dot_background.xml" + ), + ResourceUtils.ResourceGroup( + "layout-v31", + "new_content_count.xml" + ) + ).forEach { + context["res/${it.resourceDirectoryName}"].mkdirs() + context.copyResources("youtube/materialyou", it) } context.copyXmlNode("youtube/materialyou/host", "values-v31/colors.xml", "resources") - /* + /** * Add settings */ context.updatePatchStatusTheme("materialyou") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/optimize/patch/RedundantResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/optimize/patch/RedundantResourcePatch.kt index 0afc5834f..f87e065b3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/optimize/patch/RedundantResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/optimize/patch/RedundantResourcePatch.kt @@ -29,7 +29,7 @@ class RedundantResourcePatch : ResourcePatch { WHITELIST_XHDPI, WHITELIST_XXXHDPI ).forEach { (path, array) -> - val tmpDirectory = path + "-v21" + val tmpDirectory = "$path-v21" Files.createDirectory(context["res"].resolve(tmpDirectory).toPath()) (WHITELIST_GENERAL + array).forEach { name -> diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/fingerprints/TooltipContentViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/fingerprints/TooltipContentViewFingerprint.kt index 884415686..f39553e11 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/fingerprints/TooltipContentViewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/fingerprints/TooltipContentViewFingerprint.kt @@ -2,19 +2,13 @@ package app.revanced.patches.youtube.layout.etc.tooltip.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.toolTipId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode object TooltipContentViewFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.tooltipLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(toolTipId) } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/patch/TooltipContentViewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/patch/TooltipContentViewPatch.kt index e4fa77f8e..a3a21f3aa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/patch/TooltipContentViewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/tooltip/patch/TooltipContentViewPatch.kt @@ -39,7 +39,7 @@ class TooltipContentViewPatch : BytecodePatch( "return-void" ) ?: return TooltipContentViewFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.updatePatchStatus("hide-tooltip-content") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/flyoutpanel/patch/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/flyoutpanel/patch/FlyoutPanelPatch.kt index 29f7e520a..ae19f710e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/flyoutpanel/patch/FlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/flyoutpanel/patch/FlyoutPanelPatch.kt @@ -10,7 +10,7 @@ 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.LithoFilterPatch +import app.revanced.patches.youtube.ads.general.resource.patch.GeneralAdsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch @Patch @@ -18,7 +18,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch @Description("Adds options to hide player settings flyout panel.") @DependsOn( [ - LithoFilterPatch::class, + GeneralAdsPatch::class, SettingsPatch::class ] ) @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch class FlyoutPanelPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt index 12cdb3c32..e3c4c0df4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.layout.flyoutpanel.oldqualitylayout.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.videoQualityFragmentId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object QualityMenuViewInflateFingerprint : MethodFingerprint( @@ -22,10 +22,5 @@ object QualityMenuViewInflateFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.CHECK_CAST ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.videoQualityFragmentLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(videoQualityFragmentId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/patch/OldQualityLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/patch/OldQualityLayoutPatch.kt index 15f0b4e3d..0b05d03b1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/patch/OldQualityLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/flyoutpanel/oldqualitylayout/patch/OldQualityLayoutPatch.kt @@ -38,9 +38,10 @@ class OldQualityLayoutPatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { QualityMenuViewInflateFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(endIndex) as OneRegisterInstruction).registerA + val register = instruction(endIndex).registerA + addInstruction( endIndex + 1, "invoke-static { v$register }, $FLYOUT_PANEL->enableOldQualityMenu(Landroid/widget/ListView;)V" @@ -48,7 +49,7 @@ class OldQualityLayoutPatch : BytecodePatch( } } ?: return QualityMenuViewInflateFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt index 459c3bd4f..b3e387160 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -14,15 +15,15 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint -import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.autoNavPreviewId import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getStringIndex +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.FULLSCREEN -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.instruction.Instruction +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.reference.FieldReference @Patch @@ -30,53 +31,38 @@ import org.jf.dexlib2.iface.reference.FieldReference @Description("Hides the autoplay preview container in the fullscreen.") @DependsOn( [ - ResourceMappingPatch::class, - SettingsPatch::class + SettingsPatch::class, + SharedResourceIdPatch::class ] ) @YouTubeCompatibility @Version("0.0.1") class HideAutoplayPreviewPatch : BytecodePatch( - listOf( - LayoutConstructorFingerprint - ) + listOf(LayoutConstructorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - // resolve the offsets such as ... - val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single { - it.type == "id" && it.name == "autonav_preview_stub" - }.id + LayoutConstructorFingerprint.result?.mutableMethod?.let { + val insertInstruction = it.implementation!!.instructions - LayoutConstructorFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val registerIndex = indexOfFirst { - it.opcode == Opcode.CONST_STRING && - (it as BuilderInstruction21c).reference.toString() == "1.0x" - } - val dummyRegister = (this[registerIndex] as Instruction21c).registerA + val dummyRegister = it.instruction(it.getStringIndex("1.0x")).registerA + val insertIndex = it.getWideLiteralIndex(autoNavPreviewId) - // where to insert the branch instructions and ... - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId - } + val branchIndex = insertInstruction.subList(insertIndex + 1, insertInstruction.size - 1).indexOfFirst { instruction -> + ((instruction as? ReferenceInstruction)?.reference as? FieldReference)?.type == "Lcom/google/android/apps/youtube/app/player/autonav/AutonavToggleController;" + } + 1 - val branchIndex = this.subList(insertIndex + 1, this.size - 1).indexOfFirst { - ((it as? ReferenceInstruction)?.reference as? FieldReference)?.type == "Lcom/google/android/apps/youtube/app/player/autonav/AutonavToggleController;" - } + 1 + val jumpInstruction = it.instruction(insertIndex + branchIndex) - val jumpInstruction = this[insertIndex + branchIndex] as Instruction - - method.addInstructions( - insertIndex, """ - invoke-static {}, $FULLSCREEN->hideAutoPlayPreview()Z - move-result v$dummyRegister - if-nez v$dummyRegister, :hidden + it.addInstructions( + insertIndex, """ + invoke-static {}, $FULLSCREEN->hideAutoPlayPreview()Z + move-result v$dummyRegister + if-nez v$dummyRegister, :hidden """, listOf(ExternalLabel("hidden", jumpInstruction)) - ) - } + ) } ?: return LayoutConstructorFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelAlternativeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelAlternativeFingerprint.kt new file mode 100644 index 000000000..a66f7938d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelAlternativeFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.fullscreen.flimstripoverlay.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.accessibilityVideoTimeId +import app.revanced.util.bytecode.isWideLiteralExists +import org.jf.dexlib2.Opcode + +object ScrubbingLabelAlternativeFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.IF_NEZ, + Opcode.INVOKE_VIRTUAL, + Opcode.IPUT_BOOLEAN, + Opcode.RETURN_VOID + ), + customFingerprint = { it.isWideLiteralExists(accessibilityVideoTimeId) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelFingerprint.kt index 5f7d4512a..d5c1e23cd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/fingerprints/ScrubbingLabelFingerprint.kt @@ -1,16 +1,14 @@ package app.revanced.patches.youtube.layout.fullscreen.flimstripoverlay.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.scrubbingId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object ScrubbingLabelFingerprint : MethodFingerprint( - opcodes = listOf(Opcode.IPUT_BOOLEAN), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.scrubbingLabelId - } == true - } + opcodes = listOf( + Opcode.IPUT_BOOLEAN, + Opcode.CONST_WIDE_32 + ), + customFingerprint = { it.isWideLiteralExists(scrubbingId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/patch/HideFilmstripOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/patch/HideFilmstripOverlayPatch.kt index 1bee37c7d..6cf2b887e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/patch/HideFilmstripOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/flimstripoverlay/patch/HideFilmstripOverlayPatch.kt @@ -6,73 +6,80 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.removeInstruction +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError 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.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.fullscreen.flimstripoverlay.fingerprints.ScrubbingLabelAlternativeFingerprint import app.revanced.patches.youtube.layout.fullscreen.flimstripoverlay.fingerprints.ScrubbingLabelFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.FULLSCREEN -import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction -import org.jf.dexlib2.iface.reference.FieldReference @Patch @Name("hide-filmstrip-overlay") @Description("Hide flimstrip overlay on swipe controls.") -@DependsOn([SettingsPatch::class]) +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) @YouTubeCompatibility @Version("0.0.1") class HideFilmstripOverlayPatch : BytecodePatch( listOf( - ScrubbingLabelFingerprint + ScrubbingLabelFingerprint, + ScrubbingLabelAlternativeFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { - ScrubbingLabelFingerprint.result?.mutableMethod?.let { - with (it.implementation!!.instructions) { - for ((index, instruction) in this.withIndex()) { - if (instruction.opcode != Opcode.IPUT_BOOLEAN) continue - val primaryRegister = (instruction as TwoRegisterInstruction).registerA - val secondaryRegister = (instruction as TwoRegisterInstruction).registerB - val dummyRegister = primaryRegister + 2 - val fieldReference = (instruction as ReferenceInstruction).reference as FieldReference - it.addInstructions( - index + 1, """ - invoke-static {}, $FULLSCREEN->hideFilmstripOverlay()Z - move-result v$dummyRegister - if-eqz v$dummyRegister, :show - const/4 v$primaryRegister, 0x0 - :show - iput-boolean v$primaryRegister, v$secondaryRegister, ${fieldReference.definingClass}->${fieldReference.name}:${fieldReference.type} - """ - ) + val result = try { + ScrubbingLabelFingerprint.result!! + } catch (_: Exception) { + ScrubbingLabelAlternativeFingerprint.result + ?: return ScrubbingLabelAlternativeFingerprint.toErrorResult() + } - it.removeInstruction(index) + result.mutableMethod.hook(result.scanResult.patternScanResult!!.endIndex - 1) - /* - * Add settings - */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE: FULLSCREEN_SETTINGS", - "SETTINGS: HIDE_FILMSTRIP_OVERLAY" - ) - ) + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: FULLSCREEN_SETTINGS", + "SETTINGS: HIDE_FILMSTRIP_OVERLAY" + ) + ) - SettingsPatch.updatePatchStatus("hide-filmstrip-overlay") + SettingsPatch.updatePatchStatus("hide-filmstrip-overlay") - return PatchResultSuccess() - } - } - } ?: return ScrubbingLabelFingerprint.toErrorResult() + return PatchResultSuccess() + } + private companion object { + fun MutableMethod.hook(index: Int) { + val targetInstruction = instruction(index) + val fieldReference = instruction(index).reference + replaceInstruction( + index, + "invoke-static {v${targetInstruction.registerA}}, $FULLSCREEN->hideFilmstripOverlay(Z)Z" + ) - return PatchResultError("Could not find the method to hook.") + addInstructions( + index + 1, """ + move-result v${targetInstruction.registerA} + iput-boolean v${targetInstruction.registerA}, v${targetInstruction.registerB}, $fieldReference + """ + ) + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/patch/HideFullscreenPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/patch/HideFullscreenPanelsPatch.kt index c069f6b16..74e73ea0a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/patch/HideFullscreenPanelsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/fullscreenpanels/patch/HideFullscreenPanelsPatch.kt @@ -19,11 +19,11 @@ import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.youtube.layout.fullscreen.fullscreenpanels.fingerprints.FullscreenViewAdderFingerprint import app.revanced.patches.youtube.layout.fullscreen.quickactions.patch.QuickActionsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getStringIndex import app.revanced.util.integrations.Constants.FULLSCREEN import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c -import org.jf.dexlib2.builder.instruction.BuilderInstruction35c -import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.formats.Instruction35c @Patch @@ -45,9 +45,9 @@ class HideFullscreenPanelsPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { FullscreenViewAdderFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex - val register = (implementation!!.instructions[endIndex] as Instruction35c).registerD + val register = instruction(endIndex).registerD for (i in 1..3) removeInstruction(endIndex - i) @@ -60,30 +60,26 @@ class HideFullscreenPanelsPatch : BytecodePatch( } } ?: return FullscreenViewAdderFingerprint.toErrorResult() - LayoutConstructorFingerprint.result?.mutableMethod?.let { method -> - val instructions = method.implementation!!.instructions - val registerIndex = instructions.indexOfFirst { - it.opcode == Opcode.CONST_STRING && - (it as BuilderInstruction21c).reference.toString() == "1.0x" - } - val dummyRegister = (instructions[registerIndex] as Instruction21c).registerA + LayoutConstructorFingerprint.result?.mutableMethod?.let { + val instructions = it.implementation!!.instructions + val dummyRegister = it.instruction(it.getStringIndex("1.0x")).registerA - val invokeIndex = method.implementation!!.instructions.indexOfFirst { - it.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal && - ((it as? BuilderInstruction35c)?.reference.toString() == + val invokeIndex = instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.INVOKE_VIRTUAL && + ((instruction as ReferenceInstruction).reference.toString() == "Landroid/widget/FrameLayout;->addView(Landroid/view/View;)V") } - method.addInstructions( + it.addInstructions( invokeIndex, """ invoke-static {}, $FULLSCREEN->showFullscreenTitle()Z move-result v$dummyRegister if-eqz v$dummyRegister, :hidden - """, listOf(ExternalLabel("hidden", method.instruction(invokeIndex + 1))) + """, listOf(ExternalLabel("hidden", it.instruction(invokeIndex + 1))) ) } ?: return LayoutConstructorFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/hapticfeedback/patch/HapticFeedBackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/hapticfeedback/patch/HapticFeedBackPatch.kt index bc3ab2dd4..b0387b724 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/hapticfeedback/patch/HapticFeedBackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/hapticfeedback/patch/HapticFeedBackPatch.kt @@ -51,7 +51,7 @@ class HapticFeedBackPatch : BytecodePatch( } ?: return fingerprint.toErrorResult() } - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -68,34 +68,34 @@ class HapticFeedBackPatch : BytecodePatch( private companion object { fun MethodFingerprintResult.disableHaptics(targetMethodName: String) { - val startIndex = scanResult.patternScanResult!!.startIndex - val endIndex = scanResult.patternScanResult!!.endIndex - val insertIndex = endIndex + 4 - val targetRegister = (method.implementation!!.instructions.elementAt(insertIndex) as OneRegisterInstruction).registerA - val dummyRegister = targetRegister + 1 + mutableMethod.apply { + val startIndex = scanResult.patternScanResult!!.startIndex + val endIndex = scanResult.patternScanResult!!.endIndex + val insertIndex = endIndex + 4 + val targetRegister = instruction(insertIndex).registerA + val dummyRegister = targetRegister + 1 - with (mutableMethod) { removeInstruction(insertIndex) addInstructions( insertIndex, """ - invoke-static {}, $FULLSCREEN->$targetMethodName()Z - move-result v$dummyRegister - if-eqz v$dummyRegister, :vibrate - const-wide/16 v$targetRegister, 0x0 - goto :exit - :vibrate - const-wide/16 v$targetRegister, 0x19 - """, listOf(ExternalLabel("exit", mutableMethod.instruction(insertIndex))) + invoke-static {}, $FULLSCREEN->$targetMethodName()Z + move-result v$dummyRegister + if-eqz v$dummyRegister, :vibrate + const-wide/16 v$targetRegister, 0x0 + goto :exit + :vibrate + const-wide/16 v$targetRegister, 0x19 + """, listOf(ExternalLabel("exit", instruction(insertIndex))) ) addInstructions( startIndex, """ - invoke-static {}, $FULLSCREEN->$targetMethodName()Z - move-result v$dummyRegister - if-eqz v$dummyRegister, :vibrate - return-void - """, listOf(ExternalLabel("vibrate", mutableMethod.instruction(startIndex))) + invoke-static {}, $FULLSCREEN->$targetMethodName()Z + move-result v$dummyRegister + if-eqz v$dummyRegister, :vibrate + return-void + """, listOf(ExternalLabel("vibrate", instruction(startIndex))) ) } } @@ -107,7 +107,7 @@ class HapticFeedBackPatch : BytecodePatch( move-result v0 if-eqz v0, :vibrate return-void - """, listOf(ExternalLabel("vibrate", mutableMethod.instruction(0))) + """, listOf(ExternalLabel("vibrate", mutableMethod.instruction(0))) ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt index b7def1644..720f10999 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt @@ -27,21 +27,19 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class LandScapeModePatch : BytecodePatch( - listOf( - OrientationParentFingerprint - ) + listOf(OrientationParentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { OrientationParentFingerprint.result?.classDef?.let { classDef -> arrayOf( OrientationPrimaryFingerprint, OrientationSecondaryFingerprint - ).forEach { fingerprint -> - fingerprint.also { it.resolve(context, classDef) }.result?.injectOverride() ?: return fingerprint.toErrorResult() + ).forEach { + it.also { it.resolve(context, classDef) }.result?.injectOverride() ?: return it.toErrorResult() } } ?: return OrientationParentFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -61,15 +59,15 @@ class LandScapeModePatch : BytecodePatch( "$FULLSCREEN->disableLandScapeMode(Z)Z" fun MethodFingerprintResult.injectOverride() { - with (mutableMethod) { + mutableMethod.apply { val index = scanResult.patternScanResult!!.endIndex - val register = (instruction(index) as OneRegisterInstruction).registerA + val register = instruction(index).registerA addInstructions( index +1, """ invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR move-result v$register - """ + """ ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/quickactions/patch/QuickActionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/quickactions/patch/QuickActionsPatch.kt index 9195c54c8..422866fe7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/quickactions/patch/QuickActionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/quickactions/patch/QuickActionsPatch.kt @@ -4,27 +4,21 @@ 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.extensions.addInstructions -import app.revanced.patcher.extensions.instruction 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.patch.annotations.Patch -import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch -import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch +import app.revanced.patches.youtube.ads.general.resource.patch.GeneralAdsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch -import app.revanced.util.integrations.Constants.FULLSCREEN @Patch @Name("hide-quick-actions") @Description("Adds the options to hide quick actions components in the fullscreen.") @DependsOn( [ - LithoFilterPatch::class, - PlayerTypeHookPatch::class, + GeneralAdsPatch::class, SettingsPatch::class ] ) @@ -33,32 +27,7 @@ import app.revanced.util.integrations.Constants.FULLSCREEN class QuickActionsPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - val instructionList = - """ - move-object/from16 v3, p2 - invoke-static {v3, v10}, $FULLSCREEN->hideQuickActionButtons(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 - """ - - with(LithoFilterPatch.lithoMethod) { - addInstructions( - 0, """ - move-object/from16 v10, p3 - iget-object v10, v10, ${LithoFilterPatch.objectReference.definingClass}->${LithoFilterPatch.objectReference.name}:${LithoFilterPatch.objectReference.type} - if-eqz v10, :do_not_block - check-cast v10, ${LithoFilterPatch.bufferReference} - iget-object v10, v10, ${LithoFilterPatch.bufferReference}->b:Ljava/nio/ByteBuffer; - """ + instructionList,listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(0))) - ) - } - - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt index be7f621da..8e112a073 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/fingerprints/SeekEduContainerFingerprint.kt @@ -1,16 +1,10 @@ package app.revanced.patches.youtube.layout.fullscreen.seekmessage.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.Opcode +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.easySeekEduContainerId +import app.revanced.util.bytecode.isWideLiteralExists object SeekEduContainerFingerprint : MethodFingerprint( returnType = "V", - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.easySeekEduContainerId - } == true - } + customFingerprint = { it.isWideLiteralExists(easySeekEduContainerId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt index bfbc4ecf1..deb404a6b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/seekmessage/patch/SeekMessagePatch.kt @@ -30,9 +30,7 @@ import app.revanced.util.integrations.Constants.FULLSCREEN @YouTubeCompatibility @Version("0.0.1") class SeekMessagePatch : BytecodePatch( - listOf( - SeekEduContainerFingerprint - ) + listOf(SeekEduContainerFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/fingerprints/AccountMenuParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/fingerprints/AccountMenuParentFingerprint.kt index 8c88487c7..a8678ac74 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/fingerprints/AccountMenuParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/fingerprints/AccountMenuParentFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.accountmenu.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.compactLinkId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object AccountMenuParentFingerprint : MethodFingerprint( opcodes = listOf( @@ -12,10 +12,5 @@ object AccountMenuParentFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.compactLinkLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(compactLinkId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/patch/AccountMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/patch/AccountMenuPatch.kt index 0978a7c39..94e0d29a0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/patch/AccountMenuPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/accountmenu/patch/AccountMenuPatch.kt @@ -33,17 +33,15 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class AccountMenuPatch : BytecodePatch( - listOf( - AccountMenuParentFingerprint - ) + listOf(AccountMenuParentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { AccountMenuParentFingerprint.result?.let { parentResult -> AccountMenuFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1 - val register = (instruction(targetIndex) as OneRegisterInstruction).registerA + val register = instruction(targetIndex).registerA addInstruction( targetIndex + 1, @@ -52,9 +50,9 @@ class AccountMenuPatch : BytecodePatch( } } ?: return AccountMenuFingerprint.toErrorResult() - with (parentResult.mutableMethod) { + parentResult.mutableMethod.apply { val endIndex = parentResult.scanResult.patternScanResult!!.endIndex - val register = (instruction(endIndex) as OneRegisterInstruction).registerA + val register = instruction(endIndex).registerA addInstruction( endIndex + 1, @@ -63,7 +61,7 @@ class AccountMenuPatch : BytecodePatch( } } ?: return AccountMenuParentFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/patch/AutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/patch/AutoCaptionsPatch.kt index ff38cb61f..4eef14fd6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/patch/AutoCaptionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autocaptions/patch/AutoCaptionsPatch.kt @@ -49,9 +49,9 @@ class AutoCaptionsPatch : BytecodePatch( addInstructions( 0, """ - const/4 v0, ${status.value} - sput-boolean v0, $GENERAL->captionsButtonStatus:Z - """ + const/4 v0, ${status.value} + sput-boolean v0, $GENERAL->captionsButtonStatus:Z + """ ) } } @@ -66,11 +66,11 @@ class AutoCaptionsPatch : BytecodePatch( if-nez v0, :auto_captions_shown const/4 v0, 0x1 return v0 - """, listOf(ExternalLabel("auto_captions_shown", it.instruction(0))) + """, listOf(ExternalLabel("auto_captions_shown", it.instruction(0))) ) } ?: return SubtitleTrackFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autopopuppanels/patch/PlayerPopupPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autopopuppanels/patch/PlayerPopupPanelsPatch.kt index 0060731fe..2bf4987cb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/autopopuppanels/patch/PlayerPopupPanelsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/autopopuppanels/patch/PlayerPopupPanelsPatch.kt @@ -25,9 +25,7 @@ import app.revanced.util.integrations.Constants.GENERAL @YouTubeCompatibility @Version("0.0.1") class PlayerPopupPanelsPatch : BytecodePatch( - listOf( - EngagementPanelControllerFingerprint - ) + listOf(EngagementPanelControllerFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -44,7 +42,7 @@ class PlayerPopupPanelsPatch : BytecodePatch( ) } ?: return EngagementPanelControllerFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/fingerprints/BreakingNewsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/fingerprints/BreakingNewsFingerprint.kt index 2ae095107..ce81d13c4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/fingerprints/BreakingNewsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/fingerprints/BreakingNewsFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.breakingnews.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.horizontalCardListId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object BreakingNewsFingerprint : MethodFingerprint( opcodes = listOf( @@ -12,10 +12,5 @@ object BreakingNewsFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { instruction -> - instruction.opcode.ordinal == Opcode.CONST.ordinal && - (instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.horizontalCardListId - } == true - } + customFingerprint = { it.isWideLiteralExists(horizontalCardListId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/patch/BreakingNewsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/patch/BreakingNewsPatch.kt index b2b046d53..4e63e6131 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/patch/BreakingNewsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/breakingnews/patch/BreakingNewsPatch.kt @@ -39,7 +39,7 @@ class BreakingNewsPatch : BytecodePatch( BreakingNewsFingerprint.result?.let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex - val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + val targetRegister = instruction(targetIndex).registerA addInstruction( targetIndex + 1, "invoke-static {v$targetRegister}, $GENERAL->hideBreakingNewsShelf(Landroid/view/View;)V" diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt index 90d67bc51..4603fce19 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/FilterBarHeightFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.categorybar.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.filterBarHeightId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object FilterBarHeightFingerprint : MethodFingerprint( opcodes = listOf( @@ -12,10 +12,5 @@ object FilterBarHeightFingerprint : MethodFingerprint( Opcode.MOVE_RESULT, Opcode.IPUT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.filterBarHeightLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(filterBarHeightId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt index 7003a1ee0..c01879e17 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/RelatedChipCloudFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.categorybar.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.relatedChipCloudMarginId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object RelatedChipCloudFingerprint : MethodFingerprint( opcodes = listOf( @@ -11,10 +11,5 @@ object RelatedChipCloudFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.relatedChipCloudMarginLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(relatedChipCloudMarginId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/SearchResultsChipBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/SearchResultsChipBarFingerprint.kt index b8ec6d437..1e30b2de7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/SearchResultsChipBarFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/fingerprints/SearchResultsChipBarFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.categorybar.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.barContainerHeightId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object SearchResultsChipBarFingerprint : MethodFingerprint( opcodes = listOf( @@ -13,10 +13,5 @@ object SearchResultsChipBarFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.barContainerHeightLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(barContainerHeightId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt index 84af575a5..2de277fb7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/categorybar/patch/CategoryBarPatch.kt @@ -48,9 +48,9 @@ class CategoryBarPatch : BytecodePatch( * Home feed and subscriptions feed */ FilterBarHeightFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstructions( insertIndex, """ @@ -65,9 +65,9 @@ class CategoryBarPatch : BytecodePatch( * Category Bar in related video */ RelatedChipCloudFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex) as OneRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstruction( insertIndex + 1, @@ -80,9 +80,9 @@ class CategoryBarPatch : BytecodePatch( * Category Bar in search results */ SearchResultsChipBarFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex - 2 - val register = (instruction(targetIndex) as OneRegisterInstruction).registerA + val register = instruction(targetIndex).registerA addInstructions( targetIndex + 1, """ @@ -93,7 +93,7 @@ class CategoryBarPatch : BytecodePatch( } } ?: return SearchResultsChipBarFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt index cddb86e2d..34fed951f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.channellistsubmenu.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.channelListSubMenuId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object ChannelListSubMenuFingerprint : MethodFingerprint( opcodes = listOf( @@ -12,10 +12,5 @@ object ChannelListSubMenuFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.channelListSubMenuLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(channelListSubMenuId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt index da13fea9d..6a6f4147c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt @@ -31,16 +31,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class ChannelListSubMenuPatch : BytecodePatch( - listOf( - ChannelListSubMenuFingerprint - ) + listOf(ChannelListSubMenuFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { ChannelListSubMenuFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(endIndex) as OneRegisterInstruction).registerA + val register = instruction(endIndex).registerA addInstruction( endIndex + 1, @@ -49,7 +47,7 @@ class ChannelListSubMenuPatch : BytecodePatch( } } ?: return ChannelListSubMenuFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt index 73dec56b2..e0ce6d870 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.crowdfundingbox.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.donationCompanionResourceId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object CrowdfundingBoxFingerprint : MethodFingerprint( opcodes = listOf( @@ -11,10 +11,5 @@ object CrowdfundingBoxFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.IPUT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.donationCompanionResourceId - } == true - } + customFingerprint = { it.isWideLiteralExists(donationCompanionResourceId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/patch/CrowdfundingBoxPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/patch/CrowdfundingBoxPatch.kt index b26f88be8..32a3ab275 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/patch/CrowdfundingBoxPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/crowdfundingbox/patch/CrowdfundingBoxPatch.kt @@ -31,16 +31,14 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class CrowdfundingBoxPatch : BytecodePatch( - listOf( - CrowdfundingBoxFingerprint - ) + listOf(CrowdfundingBoxFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { CrowdfundingBoxFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstruction( insertIndex, @@ -49,7 +47,7 @@ class CrowdfundingBoxPatch : BytecodePatch( } } ?: return CrowdfundingBoxFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/fingerprints/FloatingMicrophoneFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/fingerprints/FloatingMicrophoneFingerprint.kt index 51f80fef1..40a91c4b9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/fingerprints/FloatingMicrophoneFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/fingerprints/FloatingMicrophoneFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.floatingmicrophone.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.fabId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object FloatingMicrophoneFingerprint : MethodFingerprint( opcodes = listOf( @@ -11,10 +11,5 @@ object FloatingMicrophoneFingerprint : MethodFingerprint( Opcode.IF_EQZ, Opcode.RETURN_VOID ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.fabLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(fabId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/patch/FloatingMicrophonePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/patch/FloatingMicrophonePatch.kt index d376ed951..c5860cfc5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/patch/FloatingMicrophonePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/floatingmicrophone/patch/FloatingMicrophonePatch.kt @@ -31,16 +31,14 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class FloatingMicrophonePatch : BytecodePatch( - listOf( - FloatingMicrophoneFingerprint - ) + listOf(FloatingMicrophoneFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { FloatingMicrophoneFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex - val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstructions( insertIndex + 1, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/headerswitch/patch/HeaderSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/headerswitch/patch/HeaderSwitchPatch.kt index dda198f34..09802aa0c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/headerswitch/patch/HeaderSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/headerswitch/patch/HeaderSwitchPatch.kt @@ -76,7 +76,7 @@ class HeaderSwitchPatch : BytecodePatch() { val errorIndex: Int = patchSuccessArray.indexOf(false) if (errorIndex == -1) { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/fingerprints/LoadMoreButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/fingerprints/LoadMoreButtonFingerprint.kt index e392c6bf1..eb53d2822 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/fingerprints/LoadMoreButtonFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/fingerprints/LoadMoreButtonFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.loadmorebutton.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.expandButtonId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object LoadMoreButtonFingerprint : MethodFingerprint( opcodes = listOf( @@ -12,10 +12,5 @@ object LoadMoreButtonFingerprint : MethodFingerprint( Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { instruction -> - instruction.opcode.ordinal == Opcode.CONST.ordinal && - (instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.expandButtonId - } == true - } + customFingerprint = { it.isWideLiteralExists(expandButtonId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/patch/LoadMoreButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/patch/LoadMoreButtonPatch.kt index 7ff0dac67..f674fb44a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/patch/LoadMoreButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/loadmorebutton/patch/LoadMoreButtonPatch.kt @@ -31,15 +31,13 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class LoadMoreButtonPatch : BytecodePatch( - listOf( - LoadMoreButtonFingerprint, - ) + listOf(LoadMoreButtonFingerprint,) ) { override fun execute(context: BytecodeContext): PatchResult { LoadMoreButtonFingerprint.result?.let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex - val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + val targetRegister = instruction(targetIndex).registerA addInstruction( targetIndex + 1, "invoke-static {v$targetRegister}, $GENERAL->hideLoadMoreButton(Landroid/view/View;)V" diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt index db8a86e3e..785fde312 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/mixplaylists/patch/MixPlaylistsPatch.kt @@ -10,7 +10,7 @@ import app.revanced.patcher.patch.PatchResultSuccess 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.LithoFilterPatch +import app.revanced.patches.youtube.misc.litho.patch.ByteBufferFilterPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch @Patch @@ -18,7 +18,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch @Description("Removes mix playlists from home feed and video player.") @DependsOn( [ - LithoFilterPatch::class, + ByteBufferFilterPatch::class, SettingsPatch::class ] ) @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch class MixPlaylistsPatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt index aa0f338c6..a1792c0d1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/fingerprints/AccountSwitcherAccessibilityLabelFingerprint.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.layout.general.personalinformation.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.accountSwitcherAccessibilityId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object AccountSwitcherAccessibilityLabelFingerprint : MethodFingerprint( opcodes = listOf( @@ -15,10 +15,5 @@ object AccountSwitcherAccessibilityLabelFingerprint : MethodFingerprint( Opcode.APUT_OBJECT, Opcode.CONST ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { it -> - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.accountSwitcherAccessibilityLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(accountSwitcherAccessibilityId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/patch/HideEmailAddressPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/patch/HideEmailAddressPatch.kt index 09f04f6fb..450b24225 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/patch/HideEmailAddressPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/personalinformation/patch/HideEmailAddressPatch.kt @@ -25,16 +25,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class HideEmailAddressPatch : BytecodePatch( - listOf( - AccountSwitcherAccessibilityLabelFingerprint - ) + listOf(AccountSwitcherAccessibilityLabelFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { AccountSwitcherAccessibilityLabelFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex - 2) as OneRegisterInstruction).registerA + val register = instruction(insertIndex - 2).registerA addInstructions( insertIndex, """ @@ -45,7 +43,7 @@ class HideEmailAddressPatch : BytecodePatch( } } ?: return AccountSwitcherAccessibilityLabelFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt index 03804ed99..c753b316c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.general.searchterms.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.searchSuggestionEntryId +import app.revanced.util.bytecode.isWideLiteralExists object SearchSuggestionEntryFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.searchSuggestionEntryLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(searchSuggestionEntryId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt index 2d39b7cfe..71e2e3b49 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt @@ -16,10 +16,11 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.layout.general.searchterms.fingerprints.* import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.searchSuggestionEntryId import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.GENERAL import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Patch @Name("hide-search-terms") @@ -42,9 +43,9 @@ class SearchTermsPatch : BytecodePatch( SearchEndpointParentFingerprint.result?.let { parentResult -> SearchEndpointFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1 - val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + val targetRegister = instruction(targetIndex).registerA addInstruction( targetIndex + 1, @@ -54,27 +55,22 @@ class SearchTermsPatch : BytecodePatch( } ?: return SearchEndpointFingerprint.toErrorResult() } ?: return SearchEndpointParentFingerprint.toErrorResult() - SearchSuggestionEntryFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val targetIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.searchSuggestionEntryLabelId - } + 2 + SearchSuggestionEntryFingerprint.result?.mutableMethod?.let { + val targetIndex = it.getWideLiteralIndex(searchSuggestionEntryId) + 2 + val targetRegister = it.instruction(targetIndex).registerA - val targetRegister = (elementAt(targetIndex) as OneRegisterInstruction).registerA + it.addInstruction( + targetIndex + 4, + "invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V" + ) - method.addInstruction( - targetIndex + 4, - "invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V" - ) - - method.addInstruction( - targetIndex + 2, - "invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V" - ) - } + it.addInstruction( + targetIndex + 2, + "invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V" + ) } ?: return SearchSuggestionEntryFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/snackbar/patch/HideSnackBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/snackbar/patch/HideSnackBarPatch.kt index fa0966b34..f49887846 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/snackbar/patch/HideSnackBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/snackbar/patch/HideSnackBarPatch.kt @@ -25,9 +25,7 @@ import app.revanced.util.integrations.Constants.GENERAL @YouTubeCompatibility @Version("0.0.1") class HideSnackBarPatch : BytecodePatch( - listOf( - HideSnackBarFingerprint - ) + listOf(HideSnackBarFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -42,7 +40,7 @@ class HideSnackBarPatch : BytecodePatch( ) } ?: return HideSnackBarFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt index 1a550eb5d..8d9f00a8d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt @@ -2,18 +2,12 @@ package app.revanced.patches.youtube.layout.general.tabletminiplayer.fingerprint import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.floatyBarTopMarginId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object MiniPlayerDimensionsCalculatorFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.floatyBarTopMarginLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(floatyBarTopMarginId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/patch/TabletMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/patch/TabletMiniPlayerPatch.kt index 92052e17e..d67e99cdb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/patch/TabletMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/patch/TabletMiniPlayerPatch.kt @@ -7,6 +7,7 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch @@ -19,9 +20,9 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.layout.general.tabletminiplayer.fingerprints.* import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getStringIndex import app.revanced.util.integrations.Constants.GENERAL import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @@ -52,21 +53,17 @@ class TabletMiniPlayerPatch : BytecodePatch( } ?: return MiniPlayerDimensionsCalculatorFingerprint.toErrorResult() MiniPlayerOverrideFingerprint.result?.let { - val targetIndex = it.mutableMethod.implementation!!.instructions.indexOfFirst { instruction -> - instruction.opcode == Opcode.CONST_STRING && - (instruction as BuilderInstruction21c).reference.toString() == "appName" - } + 2 - (context.toMethodWalker(it.method) - .nextMethod(targetIndex, true) + it.mutableMethod.apply { + (context.toMethodWalker(this) + .nextMethod(getStringIndex("appName") + 2, true) .getMethod() as MutableMethod) - .instructionProxyCall() + .instructionProxyCall() + } } ?: return MiniPlayerOverrideFingerprint.toErrorResult() - MiniPlayerResponseModelSizeCheckFingerprint.result?.let { - val (_, _, _) = it.addProxyCall() - } ?: return MiniPlayerResponseModelSizeCheckFingerprint.toErrorResult() + MiniPlayerResponseModelSizeCheckFingerprint.result?.addProxyCall() ?: return MiniPlayerResponseModelSizeCheckFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -104,7 +101,7 @@ class TabletMiniPlayerPatch : BytecodePatch( val insertInstructions = this.implementation!!.instructions for ((index, instruction) in insertInstructions.withIndex()) { if (instruction.opcode != Opcode.RETURN) continue - val parameterRegister = (instruction as OneRegisterInstruction).registerA + val parameterRegister = this.instruction(index).registerA this.insertOverride(index, parameterRegister) this.insertOverride(insertInstructions.size - 1, parameterRegister) break @@ -114,8 +111,7 @@ class TabletMiniPlayerPatch : BytecodePatch( fun MethodFingerprintResult.unwrap(): Triple { val scanIndex = this.scanResult.patternScanResult!!.endIndex val method = this.mutableMethod - val instructions = method.implementation!!.instructions - val parameterRegister = (instructions[scanIndex] as OneRegisterInstruction).registerA + val parameterRegister = method.instruction(scanIndex).registerA return Triple(method, scanIndex, parameterRegister) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt index cf4303692..535c65000 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/widesearchbar/bytecode/patch/WideSearchbarPatch.kt @@ -54,12 +54,12 @@ class WideSearchbarPatch : BytecodePatch( .nextMethod(index, true) .getMethod() as MutableMethod - injectSearchBarHook(targetMethod) + targetMethod.injectSearchBarHook() } ?: return fingerprint.toErrorResult() } ?: return parentFingerprint.toErrorResult() } - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -74,13 +74,12 @@ class WideSearchbarPatch : BytecodePatch( return PatchResultSuccess() } - private fun injectSearchBarHook(method: MutableMethod) { - val index = method.implementation!!.instructions.size - 1 - method.addInstructions( - index, """ - invoke-static {}, $GENERAL->enableWideSearchbar()Z - move-result p0 - """ + private fun MutableMethod.injectSearchBarHook() { + addInstructions( + implementation!!.instructions.size - 1, """ + invoke-static {}, $GENERAL->enableWideSearchbar()Z + move-result p0 + """ ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/homepage/patch/ChangeHomePagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/homepage/patch/ChangeHomePagePatch.kt index 8609386f0..12147fe00 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/homepage/patch/ChangeHomePagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/homepage/patch/ChangeHomePagePatch.kt @@ -43,8 +43,9 @@ class ChangeHomePagePatch : BytecodePatch( } ?: return LauncherActivityFingerprint.toErrorResult() IntentExceptionFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.endIndex + 1 + addInstructions( index, """ invoke-static {}, $NAVIGATION->changeHomePage()Z @@ -56,7 +57,7 @@ class ChangeHomePagePatch : BytecodePatch( } } ?: return IntentExceptionFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt index 75b9d8b11..2a8829dc0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/label/patch/NavigationLabelPatch.kt @@ -26,19 +26,17 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction @YouTubeCompatibility @Version("0.0.1") class NavigationLabelPatch : BytecodePatch( - listOf( - PivotBarSetTextFingerprint - ) + listOf(PivotBarSetTextFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { PivotBarSetTextFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex - 2 - val targetReference = (instruction(targetIndex) as ReferenceInstruction).reference.toString() + val targetReference = instruction(targetIndex).reference.toString() if (targetReference != "Landroid/widget/TextView;") return PivotBarSetTextFingerprint.toErrorResult() - val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA + val targetRegister = instruction(targetIndex).registerA addInstruction( targetIndex + 1, "invoke-static {v$targetRegister}, $NAVIGATION->hideNavigationLabel(Landroid/widget/TextView;)V" diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/navigationbuttons/patch/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/navigationbuttons/patch/NavigationButtonsPatch.kt index 8e0a6486e..0760a4fbe 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/navigationbuttons/patch/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/navigationbuttons/patch/NavigationButtonsPatch.kt @@ -92,13 +92,13 @@ class NavigationButtonsPatch : BytecodePatch( } ?: return PivotBarCreateButtonViewFingerprint.toErrorResult() - /* + /** * Switch create button with notifications button */ AutoMotiveFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - val register = (instruction(insertIndex) as OneRegisterInstruction).registerA + val register = instruction(insertIndex).registerA addInstructions( insertIndex, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/shortsnavbar/patch/ShortsNavBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/shortsnavbar/patch/ShortsNavBarPatch.kt index 5c2f32316..42e0fb8b4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/shortsnavbar/patch/ShortsNavBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/shortsnavbar/patch/ShortsNavBarPatch.kt @@ -44,10 +44,9 @@ class ShortsNavBarPatch : BytecodePatch( PivotBarCreateButtonViewFingerprint.result?.let { parentResult -> SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex - val instructions = implementation!!.instructions - val register = (instructions[startIndex] as OneRegisterInstruction).registerA + val register = instruction(startIndex).registerA addInstruction( startIndex + 1, @@ -58,11 +57,11 @@ class ShortsNavBarPatch : BytecodePatch( } ?: return PivotBarCreateButtonViewFingerprint.toErrorResult() ReelWatchBundleFingerprint.result?.let { - with (context + (context .toMethodWalker(it.method) .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) .getMethod() as MutableMethod - ) { + ).apply { addInstruction( 0, "invoke-static {}, $NAVIGATION->hideShortsPlayerNavBar()V" @@ -88,7 +87,7 @@ class ShortsNavBarPatch : BytecodePatch( }.forEach { instruction -> val insertIndex = indexOf(instruction) + 4 val targetRegister = - (navigationEndpointMethod.instruction(insertIndex) as OneRegisterInstruction).registerA + navigationEndpointMethod.instruction(insertIndex).registerA navigationEndpointMethod.addInstructions( insertIndex, @@ -102,7 +101,7 @@ class ShortsNavBarPatch : BytecodePatch( } ?: return NavigationEndpointFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt index a5d3089c9..906b2033e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt @@ -9,6 +9,5 @@ object PivotBarChangedFingerprint : MethodFingerprint( Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT ), - customFingerprint = { it.definingClass.endsWith("PivotBar;") - && it.name == "onConfigurationChanged" } + customFingerprint = { it.definingClass.endsWith("PivotBar;") && it.name == "onConfigurationChanged" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/patch/TabletNavigationBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/patch/TabletNavigationBarPatch.kt index 911273d45..6f7ff9a41 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/patch/TabletNavigationBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/patch/TabletNavigationBarPatch.kt @@ -40,7 +40,7 @@ class TabletNavigationBarPatch : BytecodePatch( it.result?.insertHook() ?: return it.toErrorResult() } - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -57,7 +57,7 @@ class TabletNavigationBarPatch : BytecodePatch( companion object { private fun MethodFingerprintResult.insertHook() { val targetIndex = this.scanResult.patternScanResult!!.startIndex + 1 - val register = (mutableMethod.instruction(targetIndex) as OneRegisterInstruction).registerA + val register = mutableMethod.instruction(targetIndex).registerA mutableMethod.addInstructions( targetIndex + 1, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/patch/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/patch/HideAutoplayButtonPatch.kt index e7def06f9..3417d67cf 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/patch/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/autoplaybutton/patch/HideAutoplayButtonPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -14,15 +15,15 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint -import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.autoNavPreviewId import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getStringIndex +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.PLAYER -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.instruction.Instruction +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.reference.MethodReference @Patch @@ -30,53 +31,39 @@ import org.jf.dexlib2.iface.reference.MethodReference @Description("Hides the autoplay button in the video player.") @DependsOn( [ - ResourceMappingPatch::class, - SettingsPatch::class + SettingsPatch::class, + SharedResourceIdPatch::class ] ) @YouTubeCompatibility @Version("0.0.1") class HideAutoplayButtonPatch : BytecodePatch( - listOf( - LayoutConstructorFingerprint - ) + listOf(LayoutConstructorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - // resolve the offsets such as ... - val autoNavToggleId = ResourceMappingPatch.resourceMappings.single { - it.type == "id" && it.name == "autonav_toggle" - }.id - LayoutConstructorFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val registerIndex = indexOfFirst { - it.opcode == Opcode.CONST_STRING && - (it as BuilderInstruction21c).reference.toString() == "1.0x" - } - val dummyRegister = (this[registerIndex] as Instruction21c).registerA + LayoutConstructorFingerprint.result?.mutableMethod?.let { + val insertInstruction = it.implementation!!.instructions - // where to insert the branch instructions and ... - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == autoNavToggleId - } - // where to branch away - val branchIndex = this.subList(insertIndex + 1, this.size - 1).indexOfFirst { - ((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener" - } + 2 + val dummyRegister = it.instruction(it.getStringIndex("1.0x")).registerA + val insertIndex = it.getWideLiteralIndex(autoNavPreviewId) - val jumpInstruction = this[insertIndex + branchIndex] as Instruction + val branchIndex = insertInstruction.subList(insertIndex + 1, insertInstruction.size - 1).indexOfFirst { instruction -> + ((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener" + } + 2 - method.addInstructions( - insertIndex, """ - invoke-static {}, $PLAYER->hideAutoPlayButton()Z - move-result v$dummyRegister - if-nez v$dummyRegister, :hidden + val jumpInstruction = it.instruction(insertIndex + branchIndex) + + it.addInstructions( + insertIndex, """ + invoke-static {}, $PLAYER->hideAutoPlayButton()Z + move-result v$dummyRegister + if-nez v$dummyRegister, :hidden """, listOf(ExternalLabel("hidden", jumpInstruction)) - ) - } + ) } ?: return LayoutConstructorFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/captionsbutton/patch/HideCaptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/captionsbutton/patch/HideCaptionsButtonPatch.kt index fb6bd63f1..c593420ee 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/captionsbutton/patch/HideCaptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/captionsbutton/patch/HideCaptionsButtonPatch.kt @@ -24,14 +24,12 @@ import org.jf.dexlib2.Opcode @YouTubeCompatibility @Version("0.0.1") class HideCaptionsButtonBytecodePatch : BytecodePatch( - listOf( - SubtitleButtonControllerFingerprint - ) + listOf(SubtitleButtonControllerFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { SubtitleButtonControllerFingerprint.result?.mutableMethod?.let { - with (it.implementation!!.instructions) { + it.implementation!!.instructions.apply { for ((index, instruction) in this.withIndex()) { if (instruction.opcode != Opcode.IGET_BOOLEAN) continue @@ -45,7 +43,7 @@ class HideCaptionsButtonBytecodePatch : BytecodePatch( } } ?: return SubtitleButtonControllerFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/castbutton/patch/HideCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/castbutton/patch/HideCastButtonPatch.kt index c7e844529..1eea0a6b4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/castbutton/patch/HideCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/castbutton/patch/HideCastButtonPatch.kt @@ -38,7 +38,7 @@ class HideCastButtonPatch : BytecodePatch() { } } - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/collapsebutton/patch/HideCollapseButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/collapsebutton/patch/HideCollapseButtonPatch.kt index 442f99124..5344f423b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/collapsebutton/patch/HideCollapseButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/collapsebutton/patch/HideCollapseButtonPatch.kt @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch class HideCollapseButtonPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutCircleFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutCircleFingerprint.kt index 91b4584f0..4b2e6cc22 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutCircleFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutCircleFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.layout.player.endscreencards.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.layoutCircleId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object LayoutCircleFingerprint : MethodFingerprint( @@ -13,10 +13,5 @@ object LayoutCircleFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.CHECK_CAST, ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.layoutCircle - } == true - } + customFingerprint = { it.isWideLiteralExists(layoutCircleId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutIconFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutIconFingerprint.kt index 1cb79f9e7..aca1805f0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutIconFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutIconFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.layout.player.endscreencards.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.layoutIconId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object LayoutIconFingerprint : MethodFingerprint( @@ -13,10 +13,5 @@ object LayoutIconFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.CHECK_CAST, ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.layoutIcon - } == true - } + customFingerprint = { it.isWideLiteralExists(layoutIconId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutVideoFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutVideoFingerprint.kt index 284af2891..8b565d9fc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutVideoFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/fingerprints/LayoutVideoFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.layout.player.endscreencards.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.layoutVideoId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object LayoutVideoFingerprint : MethodFingerprint( @@ -13,10 +13,5 @@ object LayoutVideoFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.CHECK_CAST, ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.layoutVideo - } == true - } + customFingerprint = { it.isWideLiteralExists(layoutVideoId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/patch/HideEndscreenCardsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/patch/HideEndscreenCardsPatch.kt index 81e6ce220..113dec865 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/patch/HideEndscreenCardsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/endscreencards/patch/HideEndscreenCardsPatch.kt @@ -17,7 +17,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.layout.player.endscreencards.fingerprints.* import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch -import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @Name("hide-endscreen-cards") @@ -41,8 +41,8 @@ class HideEndscreenCardsPatch : BytecodePatch( fun MethodFingerprintResult.injectHideCalls() { val index = this.scanResult.patternScanResult!!.endIndex - with (this.mutableMethod) { - val register = (this.instruction(index) as Instruction21c).registerA + this.mutableMethod.apply { + val register = this.instruction(index).registerA this.implementation!!.injectHideCall(index + 1, register, "layout/PlayerPatch", "hideEndscreen") } } @@ -55,7 +55,7 @@ class HideEndscreenCardsPatch : BytecodePatch( it.result?.injectHideCalls() ?: return it.toErrorResult() } - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/infocards/patch/HideInfocardsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/infocards/patch/HideInfocardsPatch.kt index 28a92d855..e67065384 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/infocards/patch/HideInfocardsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/infocards/patch/HideInfocardsPatch.kt @@ -40,7 +40,7 @@ class HideInfocardsPatch : BytecodePatch( ) ?: return InfocardsIncognitoFingerprint.toErrorResult() } ?: return InfocardsIncognitoParentFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/livechatbutton/patch/HideLiveChatButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/livechatbutton/patch/HideLiveChatButtonPatch.kt index e81b4040b..a4fd86f76 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/livechatbutton/patch/HideLiveChatButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/livechatbutton/patch/HideLiveChatButtonPatch.kt @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch class HideLiveChatButtonPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/musicbutton/patch/HideMusicButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/musicbutton/patch/HideMusicButtonPatch.kt index 3e77552cd..d490082c5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/musicbutton/patch/HideMusicButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/musicbutton/patch/HideMusicButtonPatch.kt @@ -30,7 +30,7 @@ class HideMusicButtonPatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { MusicAppDeeplinkButtonFingerprint.result?.mutableMethod?.let { - with (it.implementation!!.instructions) { + it.implementation!!.instructions.apply { val jumpInstruction = this[size - 1] as Instruction it.addInstructions( 0, """ @@ -42,7 +42,7 @@ class HideMusicButtonPatch : BytecodePatch( } } ?: return MusicAppDeeplinkButtonFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt index 404fd9ed6..c37273de7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/playerbuttonbg/patch/HidePlayerButtonBackgroundPatch.kt @@ -15,6 +15,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.layout.player.playerbuttonbg.fingerprints.HidePlayerButtonFingerprint import app.revanced.patches.youtube.misc.playerbutton.patch.PlayerButtonPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH @Patch @Name("hide-player-button-background") @@ -28,18 +29,16 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch @YouTubeCompatibility @Version("0.0.1") class HidePlayerButtonBackgroundPatch : BytecodePatch( - listOf( - HidePlayerButtonFingerprint - ) + listOf(HidePlayerButtonFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { HidePlayerButtonFingerprint.result?.mutableMethod?.addInstruction( 0, - "invoke-static { p0 }, Lapp/revanced/integrations/utils/ResourceHelper;->hidePlayerButtonBackground(Landroid/view/View;)V" + "invoke-static { p0 }, $INTEGRATIONS_PATH/utils/ResourceHelper;->hidePlayerButtonBackground(Landroid/view/View;)V" ) ?: return HidePlayerButtonFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/previousnextbutton/patch/HidePreviousNextButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/previousnextbutton/patch/HidePreviousNextButtonPatch.kt index 994adb08a..017b99067 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/previousnextbutton/patch/HidePreviousNextButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/previousnextbutton/patch/HidePreviousNextButtonPatch.kt @@ -38,7 +38,7 @@ class HidePreviousNextButtonPatch : BytecodePatch( ) ?: return SupportsNextPreviousFingerprint.toErrorResult() } ?: return ControlsOverlayStyleFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/suggestactions/patch/SuggestedActionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/suggestactions/patch/SuggestedActionsPatch.kt index bb5d59b1e..7e70c6d88 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/suggestactions/patch/SuggestedActionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/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.shared.patch.mapping.ResourceMappingPatch -import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch +import app.revanced.patches.youtube.misc.litho.patch.ByteBufferFilterPatch import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus @@ -27,7 +27,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction31i @Description("Hide the suggested actions bar inside the player.") @DependsOn( [ - LithoFilterPatch::class, + ByteBufferFilterPatch::class, PlayerTypeHookPatch::class, ResourceMappingPatch::class, SettingsPatch::class diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/player/watermark/patch/HideChannelWatermarkPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/watermark/patch/HideChannelWatermarkPatch.kt index 253673407..ba92dd4a9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/player/watermark/patch/HideChannelWatermarkPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/watermark/patch/HideChannelWatermarkPatch.kt @@ -28,30 +28,28 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class HideChannelWatermarkBytecodePatch : BytecodePatch( - listOf( - HideWatermarkParentFingerprint - ) + listOf(HideWatermarkParentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { HideWatermarkParentFingerprint.result?.let { parentResult -> HideWatermarkFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - val insertIndex = it.scanResult.patternScanResult!!.endIndex + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + val register = instruction(insertIndex).registerA - with (it.mutableMethod) { - val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA removeInstruction(insertIndex) addInstructions( insertIndex, """ invoke-static {}, $PLAYER->hideChannelWatermark()Z move-result v$register - """ + """ ) } } ?: return HideWatermarkFingerprint.toErrorResult() } ?: return HideWatermarkParentFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbar/patch/HideSeekbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbar/patch/HideSeekbarPatch.kt index 7c6bd07af..81cde11f0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbar/patch/HideSeekbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbar/patch/HideSeekbarPatch.kt @@ -42,7 +42,7 @@ class HideSeekbarPatch : BytecodePatch() { """, listOf(ExternalLabel("show_seekbar", insertMethod.instruction(0))) ) - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt index ca7272fed..8b5316b0b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.inlineTimeBarColorizedBarPlayedColorDarkId +import app.revanced.util.bytecode.isWideLiteralExists object SeekbarColorFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.inlineTimeBarColorizedBarPlayedColorDarkId - } == true - } + customFingerprint = { it.isWideLiteralExists(inlineTimeBarColorizedBarPlayedColorDarkId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt index 680eac7fa..6caab086d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -18,10 +18,12 @@ import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints.* import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.inlineTimeBarColorizedBarPlayedColorDarkId +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.inlineTimeBarPlayedNotHighlightedColorId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import app.revanced.util.integrations.Constants.SEEKBAR import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("custom-seekbar-color-bytecode-patch") @DependsOn( @@ -40,20 +42,9 @@ class SeekbarColorBytecodePatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext): PatchResult { - SeekbarColorFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val insertIndex = arrayOf( - SharedResourceIdPatch.inlineTimeBarColorizedBarPlayedColorDarkId, - SharedResourceIdPatch.inlineTimeBarPlayedNotHighlightedColorId - ).map { id -> - this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == id - } + 2 - } - - method.hook(insertIndex[0]) - method.hook(insertIndex[1]) - } + SeekbarColorFingerprint.result?.mutableMethod?.let { + it.hook(it.getWideLiteralIndex(inlineTimeBarColorizedBarPlayedColorDarkId) + 2) + it.hook(it.getWideLiteralIndex(inlineTimeBarPlayedNotHighlightedColorId) + 2) } ?: return SeekbarColorFingerprint.toErrorResult() ControlsOverlayStyleFingerprint.result?.let { parentResult -> @@ -86,7 +77,7 @@ class SeekbarColorBytecodePatch : BytecodePatch( private companion object { fun MutableMethod.hook(insertIndex: Int) { - val insertRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA + val insertRegister = instruction(insertIndex).registerA addInstructions( insertIndex + 1, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingFingerprint.kt index e2b5e92c3..0256fb2db 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingFingerprint.kt @@ -2,9 +2,9 @@ package app.revanced.patches.youtube.layout.seekbar.seekbartapping.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isNarrowLiteralExists import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction object SeekbarTappingFingerprint : MethodFingerprint( returnType = "Z", @@ -17,10 +17,5 @@ object SeekbarTappingFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.RETURN ), - customFingerprint = { methodDef -> - methodDef.name == "onTouchEvent" - && methodDef.implementation!!.instructions.any { - ((it as? NarrowLiteralInstruction)?.narrowLiteral == 2147483647) - } - } + customFingerprint = { it.name == "onTouchEvent" && it.isNarrowLiteralExists(2147483647) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingParentFingerprint.kt index 97f73d5cd..8aad92683 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/fingerprints/SeekbarTappingParentFingerprint.kt @@ -2,18 +2,12 @@ package app.revanced.patches.youtube.layout.seekbar.seekbartapping.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.accessibilityProgressTimeId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction object SeekbarTappingParentFingerprint : MethodFingerprint( returnType = "L", access = AccessFlags.PUBLIC or AccessFlags.FINAL, - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.accessibilityProgressTimeLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(accessibilityProgressTimeId)} ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/patch/SeekbarTappingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/patch/SeekbarTappingPatch.kt index fc17b069d..050d77a01 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/patch/SeekbarTappingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbartapping/patch/SeekbarTappingPatch.kt @@ -68,9 +68,8 @@ class SeekbarTappingPatch : BytecodePatch( SeekbarTappingFingerprint.result?.let { val insertIndex = it.scanResult.patternScanResult!!.endIndex - with (it.mutableMethod) { - val instructions = implementation!!.instructions - val register = (instructions[insertIndex - 1] as Instruction35c).registerC + it.mutableMethod.apply { + val register = instruction(insertIndex - 1).registerC val pMethod = tapSeekMethods["P"]!! val oMethod = tapSeekMethods["O"]!! @@ -87,7 +86,7 @@ class SeekbarTappingPatch : BytecodePatch( } } ?: return SeekbarTappingFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/timestamps/patch/HideTimeStampPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/timestamps/patch/HideTimeStampPatch.kt index d9ebee56a..4556d5d24 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/timestamps/patch/HideTimeStampPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/timestamps/patch/HideTimeStampPatch.kt @@ -25,9 +25,7 @@ import app.revanced.util.integrations.Constants.SEEKBAR @YouTubeCompatibility @Version("0.0.1") class HideTimeStampPatch : BytecodePatch( - listOf( - TimeCounterFingerprint - ) + listOf(TimeCounterFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -42,7 +40,7 @@ class HideTimeStampPatch : BytecodePatch( ) } ?: return TimeCounterFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsCommentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsCommentFingerprint.kt index d741c3820..fb3831fd4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsCommentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsCommentFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.rightCommentId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsCommentFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.rightCommentLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(rightCommentId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsInfoPanelFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsInfoPanelFingerprint.kt index 44cbc92e4..464ca40c6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsInfoPanelFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsInfoPanelFingerprint.kt @@ -1,16 +1,10 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerInfoPanelId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsInfoPanelFingerprint : MethodFingerprint( returnType = "V", - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerInfoPanelLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(reelPlayerInfoPanelId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt index 232169b83..dfd0f9567 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerBadgeId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsPaidContentFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadgeLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(reelPlayerBadgeId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsRemixFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsRemixFingerprint.kt index 94f39dbc1..699b56fe3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsRemixFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsRemixFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelRemixId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsRemixFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelRemixLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(reelRemixId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsFingerprint.kt index c1be64225..ba3271e45 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerPausedId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsSubscriptionsFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerPausedLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(reelPlayerPausedId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsTabletParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsTabletParentFingerprint.kt index bfda9510c..dd765ffff 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsTabletParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/fingerprints/ShortsSubscriptionsTabletParentFingerprint.kt @@ -1,15 +1,9 @@ package app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerFooterId +import app.revanced.util.bytecode.isWideLiteralExists object ShortsSubscriptionsTabletParentFingerprint : MethodFingerprint( - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerFooterLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(reelPlayerFooterId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsCommentButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsCommentButtonPatch.kt index 58feece36..b2e573312 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsCommentButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsCommentButtonPatch.kt @@ -5,38 +5,32 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction 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.youtube.layout.shorts.shortscomponent.fingerprints.ShortsCommentFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.rightCommentId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.SHORTS import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("hide-shorts-comment") -@DependsOn([SharedResourceIdPatch::class]) @YouTubeCompatibility @Version("0.0.1") class ShortsCommentButtonPatch : BytecodePatch( listOf(ShortsCommentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - ShortsCommentFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.rightCommentLabelId - } + 3 + ShortsCommentFingerprint.result?.mutableMethod?.let { + val insertIndex = it.getWideLiteralIndex(rightCommentId) + 3 + val insertRegister = it.instruction(insertIndex).registerA - val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA - - method.addInstruction( - insertIndex + 1, - "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerCommentsButton(Landroid/view/View;)V" - ) - } + it.addInstruction( + insertIndex + 1, + "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerCommentsButton(Landroid/view/View;)V" + ) } ?: return ShortsCommentFingerprint.toErrorResult() return PatchResultSuccess() diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsComponentPatch.kt index 7cdbb55cc..8a332bef9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsComponentPatch.kt @@ -11,8 +11,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.shared.patch.mapping.ResourceMappingPatch -import app.revanced.patches.youtube.ads.general.bytecode.patch.GeneralAdsBytecodePatch -import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch +import app.revanced.patches.youtube.ads.general.resource.patch.GeneralAdsPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus @@ -22,8 +21,7 @@ import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus @Description("Hides other Shorts components.") @DependsOn( [ - GeneralAdsBytecodePatch::class, - LithoFilterPatch::class, + GeneralAdsPatch::class, ResourceMappingPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, @@ -41,7 +39,7 @@ class ShortsComponentPatch : BytecodePatch() { context.updatePatchStatus("ShortsComponent") - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsInfoPanelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsInfoPanelPatch.kt index e50ca9604..f572c36f9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsInfoPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsInfoPanelPatch.kt @@ -5,40 +5,34 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction 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.youtube.layout.shorts.shortscomponent.fingerprints.ShortsInfoPanelFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerInfoPanelId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.SHORTS import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("hide-shorts-info-panel") -@DependsOn([SharedResourceIdPatch::class]) @YouTubeCompatibility @Version("0.0.1") class ShortsInfoPanelPatch : BytecodePatch( listOf(ShortsInfoPanelFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - ShortsInfoPanelFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerInfoPanelLabelId - } + 3 + ShortsInfoPanelFingerprint.result?.mutableMethod?.let { + val insertIndex = it.getWideLiteralIndex(reelPlayerInfoPanelId) + 3 + val insertRegister = it.instruction(insertIndex).registerA - val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA - - method.addInstructions( - insertIndex + 1, """ - invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerInfoPanel(Landroid/view/ViewGroup;)Landroid/view/ViewGroup; - move-result-object v$insertRegister + it.addInstructions( + insertIndex + 1, """ + invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerInfoPanel(Landroid/view/ViewGroup;)Landroid/view/ViewGroup; + move-result-object v$insertRegister """ - ) - } + ) } ?: return ShortsInfoPanelFingerprint.toErrorResult() return PatchResultSuccess() diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsPaidContentBannerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsPaidContentBannerPatch.kt index 7e69f5b05..c1ac68aa3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsPaidContentBannerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsPaidContentBannerPatch.kt @@ -9,40 +9,32 @@ import app.revanced.patcher.extensions.instruction 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.layout.shorts.shortscomponent.fingerprints.ShortsPaidContentFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerBadge2Id +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerBadgeId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.SHORTS import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("hide-shorts-paid-content") -@DependsOn([SharedResourceIdPatch::class]) @YouTubeCompatibility @Version("0.0.1") class ShortsPaidContentBannerPatch : BytecodePatch( listOf(ShortsPaidContentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - ShortsPaidContentFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val primaryIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadgeLabelId - } + 3 + ShortsPaidContentFingerprint.result?.mutableMethod?.let { + val primaryIndex = it.getWideLiteralIndex(reelPlayerBadgeId) + 3 + val secondaryIndex = it.getWideLiteralIndex(reelPlayerBadge2Id) + 3 - val secondaryIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadge2LabelId - } + 3 - - if (primaryIndex > secondaryIndex) { - method.insertHook(primaryIndex) - method.insertHook(secondaryIndex) - } else { - method.insertHook(secondaryIndex) - method.insertHook(primaryIndex) - } + if (primaryIndex > secondaryIndex) { + it.insertHook(primaryIndex) + it.insertHook(secondaryIndex) + } else { + it.insertHook(secondaryIndex) + it.insertHook(primaryIndex) } } ?: return ShortsPaidContentFingerprint.toErrorResult() @@ -50,12 +42,13 @@ class ShortsPaidContentBannerPatch : BytecodePatch( } private companion object { fun MutableMethod.insertHook(insertIndex: Int) { - val insertRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA + val insertRegister = instruction(insertIndex).registerA + addInstructions( insertIndex + 1, """ invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerPaidContent(Landroid/view/ViewStub;)Landroid/view/ViewStub; move-result-object v$insertRegister - """ + """ ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsRemixButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsRemixButtonPatch.kt index 4fe07f2c4..e1e1bfb60 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsRemixButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsRemixButtonPatch.kt @@ -5,38 +5,32 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction 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.youtube.layout.shorts.shortscomponent.fingerprints.ShortsRemixFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelRemixId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.SHORTS import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Name("hide-shorts-remix") -@DependsOn([SharedResourceIdPatch::class]) @YouTubeCompatibility @Version("0.0.1") class ShortsRemixButtonPatch : BytecodePatch( listOf(ShortsRemixFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - ShortsRemixFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelRemixLabelId - } - 2 + ShortsRemixFingerprint.result?.mutableMethod?.let { + val insertIndex = it.getWideLiteralIndex(reelRemixId) - 2 + val insertRegister = it.instruction(insertIndex).registerA - val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA - - method.addInstruction( - insertIndex, - "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerRemixButton(Landroid/view/View;)V" - ) - } + it.addInstruction( + insertIndex, + "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerRemixButton(Landroid/view/View;)V" + ) } ?: return ShortsRemixFingerprint.toErrorResult() return PatchResultSuccess() diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsSubscriptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsSubscriptionsButtonPatch.kt index 88370cbbd..03c9d07e9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsSubscriptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/shortscomponent/patch/ShortsSubscriptionsButtonPatch.kt @@ -6,26 +6,24 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction 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.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints.ShortsSubscriptionsFingerprint -import app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints.ShortsSubscriptionsTabletFingerprint -import app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints.ShortsSubscriptionsTabletParentFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.layout.shorts.shortscomponent.fingerprints.* +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerFooterId +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.reelPlayerPausedId +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.SHORTS import org.jf.dexlib2.Opcode 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.instruction.WideLiteralInstruction import org.jf.dexlib2.iface.reference.FieldReference @Name("hide-shorts-subscriptions") -@DependsOn([SharedResourceIdPatch::class]) @YouTubeCompatibility @Version("0.0.1") class ShortsSubscriptionsButtonPatch : BytecodePatch( @@ -35,34 +33,28 @@ class ShortsSubscriptionsButtonPatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext): PatchResult { - ShortsSubscriptionsFingerprint.result?.mutableMethod?.let { method -> - with (method.implementation!!.instructions) { - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerPausedLabelId - } + 2 + ShortsSubscriptionsFingerprint.result?.mutableMethod?.let { + val insertIndex = it.getWideLiteralIndex(reelPlayerPausedId) + 2 + val insertRegister = it.instruction(insertIndex).registerA - val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA - - method.addInstruction( - insertIndex + 1, - "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerSubscriptionsButton(Landroid/view/View;)V" - ) - } + it.addInstruction( + insertIndex + 1, + "invoke-static {v$insertRegister}, $SHORTS->hideShortsPlayerSubscriptionsButton(Landroid/view/View;)V" + ) } ?: return ShortsSubscriptionsFingerprint.toErrorResult() ShortsSubscriptionsTabletParentFingerprint.result?.let { parentResult -> - with (parentResult.mutableMethod.implementation!!.instructions) { - val targetIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerFooterLabelId - } - 1 - if (elementAt(targetIndex).opcode.ordinal != Opcode.IPUT.ordinal) return ShortsSubscriptionsTabletFingerprint.toErrorResult() - subscriptionFieldReference = (elementAt(targetIndex) as ReferenceInstruction).reference as FieldReference + parentResult.mutableMethod.apply { + val targetIndex = getWideLiteralIndex(reelPlayerFooterId) - 1 + if (instruction(targetIndex).opcode != Opcode.IPUT) return ShortsSubscriptionsTabletFingerprint.toErrorResult() + subscriptionFieldReference = (instruction(targetIndex)).reference as FieldReference } + ShortsSubscriptionsTabletFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let { with (it.implementation!!.instructions) { filter { instruction -> val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference - instruction.opcode.ordinal == Opcode.IGET.ordinal && fieldReference == subscriptionFieldReference + instruction.opcode == Opcode.IGET && fieldReference == subscriptionFieldReference }.forEach { instruction -> val insertIndex = indexOf(instruction) + 1 val register = (instruction as TwoRegisterInstruction).registerA diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/startupshortsreset/patch/DisableShortsOnStartupPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/startupshortsreset/patch/DisableShortsOnStartupPatch.kt index d3c6119c8..45a5278ed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/startupshortsreset/patch/DisableShortsOnStartupPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/shorts/startupshortsreset/patch/DisableShortsOnStartupPatch.kt @@ -26,17 +26,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class DisableShortsOnStartupPatch : BytecodePatch( - listOf( - UserWasInShortsFingerprint - ) + listOf(UserWasInShortsFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { UserWasInShortsFingerprint.result?.let { - val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1 - - with (it.mutableMethod) { - val register = (instruction(insertIndex - 1) as OneRegisterInstruction).registerA + 2 + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1 + val register = instruction(insertIndex - 1).registerA + 2 addInstructions( insertIndex, """ invoke-static { }, $SHORTS->disableStartupShortsPlayer()Z @@ -48,7 +45,7 @@ class DisableShortsOnStartupPatch : BytecodePatch( } } ?: return UserWasInShortsFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt index d5f0c7dc1..751eb21ac 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt @@ -56,7 +56,7 @@ class PowerSaveModePatch : BytecodePatch( if (powerManagerIndex == -1) return PatchResultError("Couldn't find PowerManager reference") } ?: return PowerSaveModeFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt index c9bb26baa..b71859a0f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/clientspoof/patch/ClientSpoofPatch.kt @@ -26,10 +26,9 @@ class ClientSpoofPatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { UserAgentHeaderBuilderFingerprint.result?.let { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - - with (it.mutableMethod) { - val packageNameRegister = (instruction(insertIndex) as FiveRegisterInstruction).registerD + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + val packageNameRegister = instruction(insertIndex).registerD addInstruction(insertIndex, "const-string v$packageNameRegister, \"$PACKAGE_NAME\"") } } ?: return UserAgentHeaderBuilderFingerprint.toErrorResult() diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/externalbrowser/patch/ExternalBrowserPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/externalbrowser/patch/ExternalBrowserPatch.kt index aa891aad5..cfec70a2e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/externalbrowser/patch/ExternalBrowserPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/externalbrowser/patch/ExternalBrowserPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -15,7 +16,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.misc.externalbrowser.fingerprints.* import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.MISC_PATH -import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @Name("enable-external-browser") @@ -38,19 +39,19 @@ class ExternalBrowserPatch : BytecodePatch( ExternalBrowserTertiaryFingerprint ).forEach { val result = it.result?: return it.toErrorResult() - val endIndex = result.scanResult.patternScanResult!!.endIndex - with (result.mutableMethod) { - val register = (implementation!!.instructions[endIndex] as Instruction21c).registerA + it.result?.mutableMethod?.apply { + val endIndex = result.scanResult.patternScanResult!!.endIndex + val register = instruction(endIndex).registerA addInstructions( endIndex + 1, """ invoke-static {v$register}, $MISC_PATH/ExternalBrowserPatch;->enableExternalBrowser(Ljava/lang/String;)Ljava/lang/String; move-result-object v$register - """ + """ ) } } - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/fingerprints/Vp9PropsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/fingerprints/Vp9PropsFingerprint.kt index d7eca5278..505b8fb0b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/fingerprints/Vp9PropsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/fingerprints/Vp9PropsFingerprint.kt @@ -9,7 +9,5 @@ object Vp9PropsFingerprint : MethodFingerprint( returnType = "L", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf(), - opcodes = listOf( - Opcode.OR_INT_LIT16 - ) + opcodes = listOf(Opcode.OR_INT_LIT16) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/patch/ForceVP9CodecPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/patch/ForceVP9CodecPatch.kt index 8a1aa9979..297a12474 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/patch/ForceVP9CodecPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/forcevp9/patch/ForceVP9CodecPatch.kt @@ -64,8 +64,9 @@ class ForceVP9CodecPatch : BytecodePatch( VideoCapabilitiesParentFingerprint.result?.let { parentResult -> VideoCapabilitiesFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex + addInstructions( insertIndex, """ invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideMinHeight(I)I @@ -82,7 +83,7 @@ class ForceVP9CodecPatch : BytecodePatch( } ?: return VideoCapabilitiesFingerprint.toErrorResult() } ?: return VideoCapabilitiesParentFingerprint.toErrorResult() - /* + /** * Add settings */ SettingsPatch.addPreference( @@ -104,12 +105,12 @@ class ForceVP9CodecPatch : BytecodePatch( "$INTEGRATIONS_CLASS_DESCRIPTOR->shouldForceVP9(Z)Z" fun MethodFingerprintResult.injectOverride() { - with (mutableMethod) { + mutableMethod.apply { val startIndex = scanResult.patternScanResult!!.startIndex val endIndex = scanResult.patternScanResult!!.endIndex - val startRegister = (instruction(startIndex) as OneRegisterInstruction).registerA - val endRegister = (instruction(endIndex) as OneRegisterInstruction).registerA + val startRegister = instruction(startIndex).registerA + val endRegister = instruction(endIndex).registerA hookOverride(endIndex + 1, endRegister) removeInstruction(endIndex) @@ -147,7 +148,7 @@ class ForceVP9CodecPatch : BytecodePatch( if (indexString != targetString) continue - val register = (instruction as OneRegisterInstruction).registerA + val register = instruction(index).registerA addInstructions( index + 1, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt index f93befed7..ab5cc55ed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt @@ -36,7 +36,7 @@ class LayoutSwitchPatch : BytecodePatch( ClientFormFactorParentFingerprint.result?.let { parentResult -> ClientFormFactorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val jumpIndex = it.scanResult.patternScanResult!!.startIndex + 1 addInstructions( 1, """ @@ -56,7 +56,7 @@ class LayoutSwitchPatch : BytecodePatch( """ ) ?: return LayoutSwitchFingerprint.toErrorResult() - /* + /*( * Add settings */ SettingsPatch.addPreference( 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 new file mode 100644 index 000000000..746e96dde --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/ByteBufferFilterPatch.kt @@ -0,0 +1,51 @@ +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.addInstructions +import app.revanced.patcher.extensions.instruction +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.misc.playertype.patch.PlayerTypeHookPatch +import app.revanced.util.integrations.Constants.ADS_PATH + +@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.addInstructions( + 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 + """, listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(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 index cb6a72358..232013626 100644 --- 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 @@ -18,16 +18,15 @@ 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.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21c 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.instruction.formats.Instruction31i import org.jf.dexlib2.iface.reference.FieldReference -import org.jf.dexlib2.iface.reference.MethodReference +import org.jf.dexlib2.iface.reference.Reference import kotlin.properties.Delegates @DependsOn( @@ -47,70 +46,56 @@ class LithoFilterPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { - with (LithoBufferFingerprint.result!!) { - val startIndex = this.scanResult.patternScanResult!!.startIndex - bufferReference = (this.mutableMethod.instruction(startIndex) as BuilderInstruction21c).reference.toString() - } + LithoBufferFingerprint.result?.let { + val startIndex = it.scanResult.patternScanResult!!.startIndex + bufferReference = it.mutableMethod.instruction(startIndex).reference + } ?: return LithoBufferFingerprint.toErrorResult() LithoObjectFingerprint.result?.let { val endIndex = it.scanResult.patternScanResult!!.endIndex - objectRegister = (it.mutableMethod.instruction(endIndex) as BuilderInstruction35c).registerC + objectRegister = it.mutableMethod.instruction(endIndex).registerC } ?: return LithoObjectFingerprint.toErrorResult() LithoFingerprint.result?.let { result -> val endIndex = result.scanResult.patternScanResult!!.endIndex lithoMethod = result.mutableMethod - with (lithoMethod.implementation!!.instructions) { - val bufferIndex = indexOfFirst { - it.opcode == Opcode.CONST && - (it as Instruction31i).narrowLiteral == 168777401 - } - val bufferRegister = (lithoMethod.instruction(bufferIndex) as Instruction31i).registerA + lithoMethod.apply { + val bufferIndex = getNarrowLiteralIndex(168777401) + val bufferRegister = instruction(bufferIndex).registerA + val targetIndex = getStringIndex("Element missing type extension") + 2 + val identifierRegister = instruction(endIndex).registerA - val targetIndex = indexOfFirst { - it.opcode == Opcode.CONST_STRING && - (it as BuilderInstruction21c).reference.toString() == "Element missing type extension" - } + 2 - builderMethodDescriptor = (elementAt(targetIndex) as ReferenceInstruction).reference as MethodReference - emptyComponentFieldDescriptor = (elementAt(targetIndex + 2) as ReferenceInstruction).reference as FieldReference + builderMethodDescriptor = instruction(targetIndex).reference + emptyComponentFieldDescriptor = instruction(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.instruction(insertIndex).registerA - val identifierRegister = (lithoMethod.instruction(endIndex) as OneRegisterInstruction).registerA - - 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.instruction(insertIndex) as TwoRegisterInstruction).registerA - - val instructionList = - """ - invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister, v$bufferRegister}, $ADS_PATH/LithoFilterPatch;->filter(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 - """ - - val objectIndex = indexOfFirst { - it.opcode == Opcode.CONST_STRING && - (it as BuilderInstruction21c).reference.toString() == "" - } - 2 - objectReference = (elementAt(objectIndex) as ReferenceInstruction).reference as FieldReference - lithoMethod.addInstructions( - insertIndex + 1, - """ + val objectIndex = lithoMethod.getStringIndex("") - 2 + objectReference = lithoMethod.instruction(objectIndex).reference + lithoMethod.addInstructions( + insertIndex + 1, """ move-object/from16 v$bufferRegister, p3 - iget-object v$bufferRegister, v$bufferRegister, ${objectReference.definingClass}->${objectReference.name}:${objectReference.type} + 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; - """ + instructionList,listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1))) - ) + 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 + """, listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1))) + ) + } } } } ?: return LithoFingerprint.toErrorResult() @@ -123,9 +108,9 @@ class LithoFilterPatch : BytecodePatch( var objectRegister by Delegates.notNull() lateinit var lithoMethod: MutableMethod - lateinit var bufferReference: String - lateinit var builderMethodDescriptor: MethodReference - lateinit var emptyComponentFieldDescriptor: FieldReference - lateinit var objectReference: FieldReference + 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/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt index 339f4fffc..afcc19d0e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackManagerFingerprint.kt @@ -2,18 +2,14 @@ package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isNarrowLiteralExists import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction object MinimizedPlaybackManagerFingerprint : MethodFingerprint( returnType = "Z", access = AccessFlags.PUBLIC or AccessFlags.STATIC, parameters = listOf("L"), opcodes = listOf(Opcode.AND_INT_LIT16), - customFingerprint = { methodDef -> - methodDef.implementation!!.instructions.any { - ((it as? NarrowLiteralInstruction)?.narrowLiteral == 64657230) - } - } + customFingerprint = { it.isNarrowLiteralExists(64657230) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt index 9ff6d9bdb..0e1b979ad 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt @@ -2,8 +2,8 @@ package app.revanced.patches.youtube.misc.minimizedplayback.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.backgroundCategoryId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode @@ -19,10 +19,5 @@ object MinimizedPlaybackSettingsFingerprint : MethodFingerprint( Opcode.IF_NEZ, Opcode.GOTO ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { instruction -> - instruction.opcode.ordinal == Opcode.CONST.ordinal && - (instruction as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.backgroundCategoryLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(backgroundCategoryId) } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt deleted file mode 100644 index 42bb0f89c..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/PipControllerFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.youtube.misc.minimizedplayback.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 PipControllerFingerprint : MethodFingerprint( - returnType = "L", - access = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L"), - opcodes = listOf( - Opcode.IGET_BOOLEAN - ), - customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/common/ui/pip/DefaultPipController;" } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt index 6d5d521d3..b8d9db48c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt @@ -5,6 +5,7 @@ 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.instruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult @@ -12,8 +13,7 @@ import app.revanced.patcher.patch.PatchResultSuccess 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.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintPrimary -import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintSecondary +import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.* import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.MISC_PATH import org.jf.dexlib2.iface.instruction.formats.Instruction35c @@ -38,8 +38,8 @@ class OpenLinksDirectlyPatch : BytecodePatch( ).forEach { val result = it.result?: return it.toErrorResult() val insertIndex = result.scanResult.patternScanResult!!.startIndex - with (result.mutableMethod) { - val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerC + result.mutableMethod.apply { + val register = instruction(insertIndex).registerC replaceInstruction( insertIndex, "invoke-static {v$register}, $MISC_PATH/OpenLinksDirectlyPatch;->enableBypassRedirect(Ljava/lang/String;)Landroid/net/Uri;" @@ -47,7 +47,7 @@ class OpenLinksDirectlyPatch : BytecodePatch( } } - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/fingerprints/SpeedClassFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/fingerprints/SpeedClassFingerprint.kt index f6631ced0..18e902d28 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/fingerprints/SpeedClassFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/fingerprints/SpeedClassFingerprint.kt @@ -9,8 +9,6 @@ object SpeedClassFingerprint : MethodFingerprint( returnType = "L", access = AccessFlags.PUBLIC or AccessFlags.STATIC, parameters = listOf("L"), - opcodes = listOf( - Opcode.RETURN_OBJECT - ), + opcodes = listOf(Opcode.RETURN_OBJECT), strings = listOf("PLAYBACK_RATE_MENU_BOTTOM_SHEET_FRAGMENT") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/patch/OverrideSpeedHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/patch/OverrideSpeedHookPatch.kt index 14ffc166b..9d655af43 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/patch/OverrideSpeedHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/bytecode/patch/OverrideSpeedHookPatch.kt @@ -22,15 +22,10 @@ import app.revanced.patches.youtube.misc.overridespeed.resource.patch.OverrideSp import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import app.revanced.util.integrations.Constants.VIDEO_PATH import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.reference.FieldReference -import org.jf.dexlib2.immutable.ImmutableField -import org.jf.dexlib2.immutable.ImmutableMethod -import org.jf.dexlib2.immutable.ImmutableMethodImplementation -import org.jf.dexlib2.immutable.ImmutableMethodParameter - +import org.jf.dexlib2.immutable.* @Name("override-speed-hook") @DependsOn([OverrideSpeedHookResourcePatch::class]) @@ -49,21 +44,15 @@ class OverrideSpeedHookPatch : BytecodePatch( val parentClassDef = parentResult.classDef VideoSpeedChangedFingerprint.also { it.resolve(context, parentClassDef) }.result?.let { - videoSpeedChangedResult = it + it.mutableMethod.apply { + videoSpeedChangedResult = it + val startIndex = it.scanResult.patternScanResult!!.startIndex + val endIndex = it.scanResult.patternScanResult!!.endIndex - val startIndex = it.scanResult.patternScanResult!!.startIndex - val endIndex = it.scanResult.patternScanResult!!.endIndex - - with (it.method.implementation!!.instructions) { - - val firstReference = - (elementAt(startIndex) as ReferenceInstruction).reference as FieldReference - - val secondReference = - (elementAt(endIndex - 1) as ReferenceInstruction).reference as FieldReference - - val thirdReference = - (elementAt(endIndex) as ReferenceInstruction).reference as DexBackedMethodReference + val reference1 = instruction(startIndex).reference + val reference2 = instruction(endIndex - 1).reference + val reference3 = instruction(endIndex).reference + val fieldReference = reference2 as FieldReference val parentMutableClass = parentResult.mutableClass @@ -78,30 +67,30 @@ class OverrideSpeedHookPatch : BytecodePatch( null, ImmutableMethodImplementation( 4, """ - const/4 v0, 0x0 - cmpg-float v0, v3, v0 - if-lez v0, :cond_0 - iget-object v0, v2, ${parentClassDef.type}->${firstReference.name}:${firstReference.type} - check-cast v0, ${secondReference.definingClass} - iget-object v1, v0, ${secondReference.definingClass}->${secondReference.name}:${secondReference.type} - invoke-virtual {v1, v3}, $thirdReference - :cond_0 - return-void - """.toInstructions(), null, null + const/4 v0, 0x0 + cmpg-float v0, v3, v0 + if-lez v0, :cond_0 + iget-object v0, v2, $reference1 + check-cast v0, ${fieldReference.definingClass} + iget-object v1, v0, $reference2 + invoke-virtual {v1, v3}, $reference3 + :cond_0 + return-void + """.toInstructions(), null, null ) ).toMutable() ) - } - with(context - .toMethodWalker(it.method) - .nextMethod(endIndex, true) - .getMethod() as MutableMethod - ) { - addInstruction( - this.implementation!!.instructions.size - 1, - "sput p1, $INTEGRATIONS_VIDEO_HELPER_CLASS_DESCRIPTOR->currentSpeed:F" - ) + with(context + .toMethodWalker(this) + .nextMethod(endIndex, true) + .getMethod() as MutableMethod + ) { + addInstruction( + this.implementation!!.instructions.size - 1, + "sput p1, $INTEGRATIONS_VIDEO_HELPER_CLASS_DESCRIPTOR->currentSpeed:F" + ) + } } } ?: return VideoSpeedChangedFingerprint.toErrorResult() @@ -109,9 +98,9 @@ class OverrideSpeedHookPatch : BytecodePatch( SpeedClassFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.endIndex - val register = (implementation!!.instructions[index] as OneRegisterInstruction).registerA + val register = instruction(index).registerA SPEED_CLASS = this.returnType replaceInstruction( index, @@ -126,7 +115,7 @@ class OverrideSpeedHookPatch : BytecodePatch( } ?: return SpeedClassFingerprint.toErrorResult() VideoSpeedPatchFingerprint.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { it.mutableClass.staticFields.add( ImmutableField( definingClass, diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/resource/patch/OverrideSpeedHookResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/resource/patch/OverrideSpeedHookResourcePatch.kt index b1a2ab89f..c8c57da7a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/resource/patch/OverrideSpeedHookResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/overridespeed/resource/patch/OverrideSpeedHookResourcePatch.kt @@ -15,7 +15,7 @@ import app.revanced.util.resources.ResourceUtils.copyXmlNode class OverrideSpeedHookResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* + /** * Copy arrays */ context.copyXmlNode("youtube/speed/host", "values/arrays.xml", "resources") diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/fingerprints/LiveChatFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/fingerprints/LiveChatFingerprint.kt index b4956c45b..8834a469c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/fingerprints/LiveChatFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/fingerprints/LiveChatFingerprint.kt @@ -1,16 +1,11 @@ package app.revanced.patches.youtube.misc.playerbutton.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.liveChatButtonId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object LiveChatFingerprint : MethodFingerprint( opcodes = listOf(Opcode.NEW_INSTANCE), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.liveChatButtonId - } == true - } + customFingerprint = { it.isWideLiteralExists(liveChatButtonId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/patch/PlayerButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/patch/PlayerButtonPatch.kt index 343f4b013..16ea7bc76 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/patch/PlayerButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playerbutton/patch/PlayerButtonPatch.kt @@ -24,9 +24,7 @@ import org.jf.dexlib2.builder.instruction.BuilderInstruction35c @YouTubeCompatibility @Version("0.0.1") class PlayerButtonPatch : BytecodePatch( - listOf( - LiveChatFingerprint - ) + listOf(LiveChatFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/BottomControlsInflateFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/BottomControlsInflateFingerprint.kt index 490e96e4e..ca729611e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/BottomControlsInflateFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/BottomControlsInflateFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.misc.playercontrols.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.bottomUiContainerResourceId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object BottomControlsInflateFingerprint : MethodFingerprint( @@ -11,10 +11,5 @@ object BottomControlsInflateFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.bottomUiContainerResourceId - } == true - } + customFingerprint = { it.isWideLiteralExists(bottomUiContainerResourceId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/ControlsLayoutInflateFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/ControlsLayoutInflateFingerprint.kt index 7b15c6e68..55e975129 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/ControlsLayoutInflateFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/ControlsLayoutInflateFingerprint.kt @@ -1,8 +1,8 @@ package app.revanced.patches.youtube.misc.playercontrols.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.controlsLayoutStubResourceId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object ControlsLayoutInflateFingerprint : MethodFingerprint( @@ -13,10 +13,5 @@ object ControlsLayoutInflateFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT ), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.controlsLayoutStubResourceId - } == true - } + customFingerprint = { it.isWideLiteralExists(controlsLayoutStubResourceId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt index 7aa907ad4..59bbc8892 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt @@ -5,7 +5,5 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint object PlayerControlsVisibilityFingerprint : MethodFingerprint( returnType = "V", parameters = listOf("Z", "Z"), - customFingerprint = { - it.definingClass.endsWith("YouTubeControlsOverlay;") - } + customFingerprint = { it.definingClass.endsWith("YouTubeControlsOverlay;") } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playeroverlay/patch/PlayerOverlaysHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playeroverlay/patch/PlayerOverlaysHookPatch.kt index 99df76d3e..a1d88ec98 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playeroverlay/patch/PlayerOverlaysHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playeroverlay/patch/PlayerOverlaysHookPatch.kt @@ -18,9 +18,7 @@ import app.revanced.util.integrations.Constants.UTILS_PATH @YouTubeCompatibility @Version("0.0.1") class PlayerOverlaysHookPatch : BytecodePatch( - listOf( - PlayerOverlaysOnFinishInflateFingerprint - ) + listOf(PlayerOverlaysOnFinishInflateFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { // hook YouTubePlayerOverlaysLayout.onFinishInflate() diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/BadResponseFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/BadResponseFingerprint.kt index 2ed46500f..8f9d70000 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/BadResponseFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/BadResponseFingerprint.kt @@ -4,8 +4,6 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.Opcode object BadResponseFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.CONST_16 - ), + opcodes = listOf(Opcode.CONST_16), strings = listOf("Response code: ") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/SubtitleWindowFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/SubtitleWindowFingerprint.kt index 825078c3c..3d91fc5e8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/SubtitleWindowFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/fingerprints/SubtitleWindowFingerprint.kt @@ -4,7 +4,5 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint object SubtitleWindowFingerprint : MethodFingerprint( parameters = listOf("I", "I", "I", "Z", "Z"), - customFingerprint = { it.definingClass == "Lcom/google/android/libraries/youtube/player/subtitles/model/SubtitleWindowSettings;" - && it.name == "" - } + customFingerprint = { it.definingClass.endsWith("SubtitleWindowSettings;") && it.name == "" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/patch/ProtobufSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/patch/ProtobufSpoofPatch.kt index 6dc0b8e9d..4ae1e46d6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/patch/ProtobufSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/protobufpoof/patch/ProtobufSpoofPatch.kt @@ -44,11 +44,11 @@ class ProtobufSpoofPatch : BytecodePatch( // hook parameter ProtobufParameterBuilderFingerprint.result?.let { - with (context + (context .toMethodWalker(it.method) .nextMethod(it.scanResult.patternScanResult!!.startIndex, true) .getMethod() as MutableMethod - ) { + ).apply { val protobufParam = 3 addInstructions( @@ -85,7 +85,7 @@ class ProtobufSpoofPatch : BytecodePatch( // Hook video id, required for subtitle fix. MainstreamVideoIdPatch.injectCall("$MISC_PATH/ProtobufSpoofPatch;->setCurrentVideoId(Ljava/lang/String;)V") - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/quic/patch/QUICProtocolPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/quic/patch/QUICProtocolPatch.kt index d19424925..b5bced3b1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/quic/patch/QUICProtocolPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/quic/patch/QUICProtocolPatch.kt @@ -42,7 +42,7 @@ class QUICProtocolPatch : BytecodePatch( )?: return it.toErrorResult() } - /* + /** * Add settings */ SettingsPatch.addPreference( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index d0e0164b0..0f37c81ae 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -18,46 +18,48 @@ import app.revanced.util.enum.ResourceType.* @Version("0.0.1") class SharedResourceIdPatch : ResourcePatch { internal companion object { - var accessibilityProgressTimeLabelId: Long = -1 - var accountSwitcherAccessibilityLabelId: Long = -1 - var adAttributionLabelId: Long = -1 + var accessibilityProgressTimeId: Long = -1 + var accessibilityVideoTimeId: Long = -1 + var accountSwitcherAccessibilityId: Long = -1 + var adAttributionId: Long = -1 var appearanceStringId: Long = -1 - var backgroundCategoryLabelId: Long = -1 - var barContainerHeightLabelId: Long = -1 + var autoNavPreviewId: Long = -1 + var backgroundCategoryId: Long = -1 + var barContainerHeightId: Long = -1 var bottomUiContainerResourceId: Long = -1 - var channelListSubMenuLabelId: Long = -1 + var channelListSubMenuId: Long = -1 var chapterRepeatOnResourceId: Long = -1 - var compactLinkLabelId: Long = -1 + var compactLinkId: Long = -1 var controlsLayoutStubResourceId: Long = -1 - var dislikeButtonLabelId: Long = -1 + var dislikeButtonId: Long = -1 var donationCompanionResourceId: Long = -1 var easySeekEduContainerId: Long = -1 var expandButtonId: Long = -1 - var fabLabelId: Long = -1 - var filterBarHeightLabelId: Long = -1 - var floatyBarTopMarginLabelId: Long = -1 + var fabId: Long = -1 + var filterBarHeightId: Long = -1 + var floatyBarTopMarginId: Long = -1 var horizontalCardListId: Long = -1 var imageOnlyTabId: Long = -1 var inlineTimeBarColorizedBarPlayedColorDarkId: Long = -1 var inlineTimeBarPlayedNotHighlightedColorId: Long = -1 - var layoutCircle: Long = -1 - var layoutIcon: Long = -1 - var layoutVideo: Long = -1 - var likeButtonLabelId: Long = -1 + var layoutCircleId: Long = -1 + var layoutIconId: Long = -1 + var layoutVideoId: Long = -1 + var likeButtonId: Long = -1 var liveChatButtonId: Long = -1 - var reelPlayerBadgeLabelId: Long = -1 - var reelPlayerBadge2LabelId: Long = -1 - var reelPlayerFooterLabelId: Long = -1 - var reelPlayerInfoPanelLabelId: Long = -1 - var reelPlayerPausedLabelId: Long = -1 - var reelRemixLabelId: Long = -1 - var relatedChipCloudMarginLabelId: Long = -1 - var rightCommentLabelId: Long = -1 - var searchSuggestionEntryLabelId: Long = -1 - var scrubbingLabelId: Long = -1 - var slimMetadataToggleButtonLabelId: Long = -1 - var tooltipLabelId: Long = -1 - var videoQualityFragmentLabelId: Long = -1 + var reelPlayerBadgeId: Long = -1 + var reelPlayerBadge2Id: Long = -1 + var reelPlayerFooterId: Long = -1 + var reelPlayerInfoPanelId: Long = -1 + var reelPlayerPausedId: Long = -1 + var reelRemixId: Long = -1 + var relatedChipCloudMarginId: Long = -1 + var rightCommentId: Long = -1 + var searchSuggestionEntryId: Long = -1 + var scrubbingId: Long = -1 + var slimMetadataToggleButtonId: Long = -1 + var toolTipId: Long = -1 + var videoQualityFragmentId: Long = -1 } override fun execute(context: ResourceContext): PatchResult { @@ -66,46 +68,48 @@ class SharedResourceIdPatch : ResourcePatch { .resourceMappings .single { it.type == type.value && it.name == name }.id - accessibilityProgressTimeLabelId = find(STRING, "accessibility_player_progress_time") - accountSwitcherAccessibilityLabelId = find(STRING, "account_switcher_accessibility_label") - adAttributionLabelId = find(ID, "ad_attribution") + accessibilityProgressTimeId = find(STRING, "accessibility_player_progress_time") + accessibilityVideoTimeId = find(STRING, "accessibility_video_time") + accountSwitcherAccessibilityId = find(STRING, "account_switcher_accessibility_label") + adAttributionId = find(ID, "ad_attribution") appearanceStringId = find(STRING, "app_theme_appearance_dark") - backgroundCategoryLabelId = find(STRING, "pref_background_and_offline_category") - barContainerHeightLabelId = find(DIMEN, "bar_container_height") + autoNavPreviewId = find(ID, "autonav_preview_stub") + backgroundCategoryId = find(STRING, "pref_background_and_offline_category") + barContainerHeightId = find(DIMEN, "bar_container_height") bottomUiContainerResourceId = find(ID, "bottom_ui_container_stub") - channelListSubMenuLabelId = find(LAYOUT, "channel_list_sub_menu") + channelListSubMenuId = find(LAYOUT, "channel_list_sub_menu") chapterRepeatOnResourceId = find(STRING, "chapter_repeat_on") - compactLinkLabelId = find(LAYOUT, "compact_link") + compactLinkId = find(LAYOUT, "compact_link") controlsLayoutStubResourceId = find(ID, "controls_layout_stub") - dislikeButtonLabelId = find(ID, "dislike_button") + dislikeButtonId = find(ID, "dislike_button") donationCompanionResourceId = find(LAYOUT, "donation_companion") easySeekEduContainerId = find(ID, "easy_seek_edu_container") expandButtonId = find(LAYOUT, "expand_button_down") - fabLabelId = find(ID, "fab") - filterBarHeightLabelId = find(DIMEN, "filter_bar_height") - floatyBarTopMarginLabelId = find(DIMEN, "floaty_bar_button_top_margin") + fabId = find(ID, "fab") + filterBarHeightId = find(DIMEN, "filter_bar_height") + floatyBarTopMarginId = find(DIMEN, "floaty_bar_button_top_margin") horizontalCardListId = find(LAYOUT, "horizontal_card_list") imageOnlyTabId = find(LAYOUT, "image_only_tab") inlineTimeBarColorizedBarPlayedColorDarkId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark") inlineTimeBarPlayedNotHighlightedColorId = find(COLOR, "inline_time_bar_played_not_highlighted_color") - layoutCircle = find(LAYOUT, "endscreen_element_layout_circle") - layoutIcon = find(LAYOUT, "endscreen_element_layout_icon") - layoutVideo = find(LAYOUT, "endscreen_element_layout_video") - likeButtonLabelId = find(ID, "like_button") + layoutCircleId = find(LAYOUT, "endscreen_element_layout_circle") + layoutIconId = find(LAYOUT, "endscreen_element_layout_icon") + layoutVideoId = find(LAYOUT, "endscreen_element_layout_video") + likeButtonId = find(ID, "like_button") liveChatButtonId = find(ID, "live_chat_overlay_button") - reelPlayerBadgeLabelId = find(ID, "reel_player_badge") - reelPlayerBadge2LabelId = find(ID, "reel_player_badge2") - reelPlayerFooterLabelId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3") - reelPlayerInfoPanelLabelId = find(ID, "reel_player_info_panel") - reelPlayerPausedLabelId = find(ID, "reel_player_paused_state_buttons") - reelRemixLabelId = find(ID, "reel_dyn_remix") - relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins") - rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c") - searchSuggestionEntryLabelId = find(LAYOUT, "search_suggestion_entry") - scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing") - slimMetadataToggleButtonLabelId = find(COLOR, "slim_metadata_toggle_button") - tooltipLabelId = find(LAYOUT, "tooltip_content_view") - videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title") + reelPlayerBadgeId = find(ID, "reel_player_badge") + reelPlayerBadge2Id = find(ID, "reel_player_badge2") + reelPlayerFooterId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3") + reelPlayerInfoPanelId = find(ID, "reel_player_info_panel") + reelPlayerPausedId = find(ID, "reel_player_paused_state_buttons") + reelRemixId = find(ID, "reel_dyn_remix") + relatedChipCloudMarginId = find(LAYOUT, "related_chip_cloud_reduced_margins") + rightCommentId = find(DRAWABLE, "ic_right_comment_32c") + searchSuggestionEntryId = find(LAYOUT, "search_suggestion_entry") + scrubbingId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing") + slimMetadataToggleButtonId = find(COLOR, "slim_metadata_toggle_button") + toolTipId = find(LAYOUT, "tooltip_content_view") + videoQualityFragmentId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title") return PatchResultSuccess() } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/general/patch/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/general/patch/ReturnYouTubeDislikePatch.kt index b8eb94430..8c1d13542 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/general/patch/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/general/patch/ReturnYouTubeDislikePatch.kt @@ -72,16 +72,15 @@ class ReturnYouTubeDislikePatch : BytecodePatch( with (it.mutableMethod) { val conversionContextIndex = it.scanResult.patternScanResult!!.startIndex conversionContextFieldReference = - (instruction(conversionContextIndex) as ReferenceInstruction).reference + instruction(conversionContextIndex).reference } } ?: return TextComponentContextFingerprint.toErrorResult() TextComponentTmpFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex tmpRegister = - (instruction(startIndex) as FiveRegisterInstruction).registerE - + instruction(startIndex).registerE } } ?: return TextComponentTmpFingerprint.toErrorResult() @@ -90,10 +89,10 @@ class ReturnYouTubeDislikePatch : BytecodePatch( with (it.mutableMethod) { val atomicReferenceStartIndex = it.scanResult.patternScanResult!!.startIndex val insertIndex = it.scanResult.patternScanResult!!.endIndex - val moveCharSequenceInstruction = instruction(insertIndex) as TwoRegisterInstruction + val moveCharSequenceInstruction = instruction(insertIndex) val atomicReferenceRegister = - (instruction(atomicReferenceStartIndex) as FiveRegisterInstruction).registerC + instruction(atomicReferenceStartIndex).registerC val charSequenceRegister = moveCharSequenceInstruction.registerB @@ -114,7 +113,7 @@ class ReturnYouTubeDislikePatch : BytecodePatch( MainstreamVideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") - /* + /** * Add ReVanced Settings */ SettingsPatch.addReVancedPreference("ryd_settings") diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/ButtonTagFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/ButtonTagFingerprint.kt index 39d4d1ba4..cf3fcbd87 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/ButtonTagFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/ButtonTagFingerprint.kt @@ -2,19 +2,13 @@ package app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerp import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.dislikeButtonId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode object ButtonTagFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dislikeButtonLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(dislikeButtonId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/SlimMetadataButtonParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/SlimMetadataButtonParentFingerprint.kt index 54bceafd6..9427f2b53 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/SlimMetadataButtonParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/fingerprints/SlimMetadataButtonParentFingerprint.kt @@ -1,16 +1,10 @@ package app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.Opcode +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.slimMetadataToggleButtonId +import app.revanced.util.bytecode.isWideLiteralExists object SlimMetadataButtonParentFingerprint : MethodFingerprint( returnType = "I", - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.slimMetadataToggleButtonLabelId - } == true - } + customFingerprint = { it.isWideLiteralExists(slimMetadataToggleButtonId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/patch/ReturnYouTubeDislikeOldLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/patch/ReturnYouTubeDislikeOldLayoutPatch.kt index e8a73707f..f1aa02034 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/patch/ReturnYouTubeDislikeOldLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/oldlayout/patch/ReturnYouTubeDislikeOldLayoutPatch.kt @@ -13,13 +13,15 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.dislikeButtonId +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.likeButtonId import app.revanced.patches.youtube.misc.returnyoutubedislike.oldlayout.fingerprints.* +import app.revanced.util.bytecode.getWideLiteralIndex import app.revanced.util.integrations.Constants.UTILS_PATH import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction 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.instruction.WideLiteralInstruction import org.jf.dexlib2.iface.reference.Reference @Name("return-youtube-dislike-old-layout") @@ -37,17 +39,17 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch( SlimMetadataButtonParentFingerprint.result?.let { parentResult -> SlimMetadataButtonViewFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex slimMetadataButtonViewFieldReference = - (instruction(startIndex) as ReferenceInstruction).reference + instruction(startIndex).reference } } ?: return SlimMetadataButtonViewFingerprint.toErrorResult() SlimMetadataButtonTextFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex - val setTextInstruction = instruction(insertIndex) as FiveRegisterInstruction + val setTextInstruction = instruction(insertIndex) val tempRegister = setTextInstruction.registerC + 1 @@ -70,23 +72,19 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch( ButtonTagFingerprint.result?.let { parentResult -> ButtonTagOnClickFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { - with (it.mutableMethod) { + it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex getActiveBooleanFieldReference = - (instruction(startIndex) as ReferenceInstruction).reference + instruction(startIndex).reference } } ?: return ButtonTagOnClickFingerprint.toErrorResult() - with (parentResult.mutableMethod.implementation!!.instructions) { - val dislikeButtonIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dislikeButtonLabelId - } + parentResult.mutableMethod.apply { + val dislikeButtonIndex = getWideLiteralIndex(dislikeButtonId) + val dislikeButtonRegister = instruction(dislikeButtonIndex).registerA + val dislikeButtonInstruction = instruction(dislikeButtonIndex - 1) - val dislikeButtonRegister = (elementAt(dislikeButtonIndex) as OneRegisterInstruction).registerA - - val dislikeButtonInstruction = elementAt(dislikeButtonIndex - 1) as TwoRegisterInstruction - - parentResult.mutableMethod.addInstructions( + addInstructions( dislikeButtonIndex, """ invoke-virtual {v${dislikeButtonInstruction.registerB}}, $getActiveBooleanFieldReference move-result v$dislikeButtonRegister @@ -94,15 +92,11 @@ class ReturnYouTubeDislikeOldLayoutPatch : BytecodePatch( """ ) - val likeButtonIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.likeButtonLabelId - } + val likeButtonIndex = getWideLiteralIndex(likeButtonId) + val likeButtonRegister = instruction(likeButtonIndex).registerA + val likeButtonInstruction = instruction(likeButtonIndex - 1) - val likeButtonRegister = (elementAt(likeButtonIndex) as OneRegisterInstruction).registerA - - val likeButtonInstruction = elementAt(likeButtonIndex - 1) as TwoRegisterInstruction - - parentResult.mutableMethod.addInstructions( + addInstructions( likeButtonIndex, """ invoke-virtual {v${likeButtonInstruction.registerB}}, $getActiveBooleanFieldReference move-result v$likeButtonRegister diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/shorts/patch/ReturnYouTubeDislikeShortsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/shorts/patch/ReturnYouTubeDislikeShortsPatch.kt index 5acac3b70..15179d0c3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/shorts/patch/ReturnYouTubeDislikeShortsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/shorts/patch/ReturnYouTubeDislikeShortsPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -19,28 +20,24 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class ReturnYouTubeDislikeShortsPatch : BytecodePatch( - listOf( - ShortsTextComponentParentFingerprint - ) + listOf(ShortsTextComponentParentFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { ShortsTextComponentParentFingerprint.result?.let { - with (context + (context .toMethodWalker(it.method) .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) .getMethod() as MutableMethod - ) { - val insertInstructions = this.implementation!!.instructions - val insertIndex = insertInstructions.size - 1 - val insertRegister = (insertInstructions.elementAt(insertIndex) as OneRegisterInstruction).registerA + ).apply { + val insertIndex = implementation!!.instructions.size - 1 + val insertRegister = instruction(insertIndex).registerA this.insertShorts(insertIndex, insertRegister) } - with (it.mutableMethod) { - val insertInstructions = this.implementation!!.instructions + it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex + 2 - val insertRegister = (insertInstructions.elementAt(insertIndex - 1) as OneRegisterInstruction).registerA + val insertRegister = instruction(insertIndex - 1).registerA this.insertShorts(insertIndex, insertRegister) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterSystemFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterSystemFingerprint.kt index b92b80792..3ea5ae528 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterSystemFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/fingerprints/ThemeSetterSystemFingerprint.kt @@ -1,17 +1,12 @@ package app.revanced.patches.youtube.misc.settings.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch.Companion.appearanceStringId +import app.revanced.util.bytecode.isWideLiteralExists import org.jf.dexlib2.Opcode object ThemeSetterSystemFingerprint : MethodFingerprint( returnType = "L", opcodes = listOf(Opcode.RETURN_OBJECT), - customFingerprint = { methodDef -> - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.appearanceStringId - } == true - } + customFingerprint = { it.isWideLiteralExists(appearanceStringId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsBytecodePatch.kt index 661ef5b2a..bc9175ff9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/settings/bytecode/patch/SettingsBytecodePatch.kt @@ -34,7 +34,7 @@ class SettingsBytecodePatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { // apply the current theme of the settings page ThemeSetterSystemFingerprint.result?.let { - with(it.mutableMethod) { + it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex replaceInstruction( targetIndex, diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/fingerprints/PlayerControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/fingerprints/PlayerControllerFingerprint.kt index b7b311089..c68fcf754 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/fingerprints/PlayerControllerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/fingerprints/PlayerControllerFingerprint.kt @@ -3,8 +3,5 @@ package app.revanced.patches.youtube.misc.sponsorblock.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint object PlayerControllerFingerprint : MethodFingerprint( - customFingerprint = { - it.definingClass == "Lapp/revanced/integrations/sponsorblock/SegmentPlaybackController;" - && it.name == "setSponsorBarRect" - } + customFingerprint = { it.definingClass.endsWith("SegmentPlaybackController;") && it.name == "setSponsorBarRect" } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index ab21a1b31..08563144d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -5,6 +5,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult @@ -55,7 +56,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( /** * Hook the video time methods */ - with(MainstreamVideoIdPatch) { + MainstreamVideoIdPatch.apply { videoTimeHook( INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR, "setVideoTime" @@ -89,7 +90,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( for ((index, instruction) in insertInstructions.withIndex()) { if (instruction.opcode != Opcode.INVOKE_STATIC) continue - val invokeInstruction = instruction as Instruction35c + val invokeInstruction = insertMethod.instruction(index) if ((invokeInstruction.reference as MethodReference).name != "round") continue val insertIndex = index + 2 @@ -132,9 +133,9 @@ class SponsorBlockBytecodePatch : BytecodePatch( val drawSegmentInstructionInsertIndex = index - 1 - val (canvasInstance, centerY) = (insertInstructions[drawSegmentInstructionInsertIndex] as FiveRegisterInstruction).let { - it.registerC to it.registerE - } + val (canvasInstance, centerY) = + insertMethod.instruction(drawSegmentInstructionInsertIndex).let { it.registerC to it.registerE } + insertMethod.addInstruction( drawSegmentInstructionInsertIndex, "invoke-static {v$canvasInstance, v$centerY}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" @@ -166,7 +167,7 @@ class SponsorBlockBytecodePatch : BytecodePatch( for ((index, instruction) in instructions.withIndex()) { if (instruction.opcode != Opcode.CONST_STRING) continue - val register = (instruction as OneRegisterInstruction).registerA + val register = it.instruction(index).registerA it.replaceInstruction( index, "const-string v$register, \"${MainstreamVideoIdPatch.reactReference}\"" diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt index 551ab5782..570ab15df 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/sponsorblock/resource/patch/SponsorBlockResourcePatch.kt @@ -32,8 +32,8 @@ import app.revanced.util.resources.ResourceUtils.copyXmlNode class SponsorBlockResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - /* - merge SponsorBlock drawables to main drawables + /** + * merge SponsorBlock drawables to main drawables */ arrayOf( @@ -57,8 +57,8 @@ class SponsorBlockResourcePatch : ResourcePatch { context.copyResources("youtube/sponsorblock", resourceGroup) } - /* - merge xml nodes from the host to their real xml files + /** + * merge xml nodes from the host to their real xml files */ // collect all host resources @@ -94,13 +94,11 @@ class SponsorBlockResourcePatch : ResourcePatch { } } - /* + /** * Add ReVanced Settings */ SettingsPatch.addReVancedPreference("sponsorblock_settings") - SettingsPatch.updatePatchStatus("sponsorblock") - return PatchResultSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/timebar/patch/HookTimeBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/timebar/patch/HookTimeBarPatch.kt index d0962b947..891583254 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/timebar/patch/HookTimeBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/timebar/patch/HookTimeBarPatch.kt @@ -5,6 +5,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -16,13 +17,12 @@ import app.revanced.patches.youtube.misc.timebar.fingerprints.* @YouTubeCompatibility @Version("0.0.1") class HookTimeBarPatch : BytecodePatch( - listOf( - EmptyColorFingerprint - ) + listOf(EmptyColorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { EmptyColorFingerprint.result?.let { parentResult -> + emptyColorResult = parentResult emptyColorMethod = parentResult.mutableMethod OnDrawFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.let { setTimeBarMethod = it @@ -34,6 +34,7 @@ class HookTimeBarPatch : BytecodePatch( } internal companion object { + lateinit var emptyColorResult: MethodFingerprintResult lateinit var emptyColorMethod: MutableMethod lateinit var setTimeBarMethod: MutableMethod } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/legacy/patch/LegacyVideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/legacy/patch/LegacyVideoIdPatch.kt index e6f99a500..a51796071 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/legacy/patch/LegacyVideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/legacy/patch/LegacyVideoIdPatch.kt @@ -20,16 +20,14 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @YouTubeCompatibility @Version("0.0.1") class LegacyVideoIdPatch : BytecodePatch( - listOf( - LegacyVideoIdFingerprint - ) + listOf(LegacyVideoIdFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { LegacyVideoIdFingerprint.result?.let { insertIndex = it.scanResult.patternScanResult!!.endIndex - with (it.mutableMethod) { + it.mutableMethod.apply { insertMethod = this videoIdRegister = (implementation!!.instructions[insertIndex + 1] as OneRegisterInstruction).registerA } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/mainstream/patch/MainstreamVideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/mainstream/patch/MainstreamVideoIdPatch.kt index 47586c713..5a6d9e2f6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/mainstream/patch/MainstreamVideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/videoid/mainstream/patch/MainstreamVideoIdPatch.kt @@ -139,7 +139,6 @@ class MainstreamVideoIdPatch : BytecodePatch( } } - MainstreamVideoIdFingerprint.result?.let { insertIndex = it.scanResult.patternScanResult!!.endIndex diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/bytecode/patch/VideoSpeedBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/bytecode/patch/VideoSpeedBytecodePatch.kt index bf926a7e7..aada0e655 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/speed/bytecode/patch/VideoSpeedBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/bytecode/patch/VideoSpeedBytecodePatch.kt @@ -16,7 +16,6 @@ import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch import app.revanced.patches.youtube.video.livestream.patch.LiveStreamPatch import app.revanced.patches.youtube.video.speed.bytecode.fingerprints.* -import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus import app.revanced.util.integrations.Constants.VIDEO_PATH import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction @@ -58,8 +57,6 @@ class VideoSpeedBytecodePatch : BytecodePatch( LegacyVideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") - context.updatePatchStatus("VideoSpeed") - return PatchResultSuccess() } diff --git a/src/main/kotlin/app/revanced/util/bytecode/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/bytecode/BytecodeUtils.kt index ad83166e0..219f43821 100644 --- a/src/main/kotlin/app/revanced/util/bytecode/BytecodeUtils.kt +++ b/src/main/kotlin/app/revanced/util/bytecode/BytecodeUtils.kt @@ -1,30 +1,43 @@ package app.revanced.util.bytecode import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.Method import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -fun Method.getNarrowLiteralIndex(value: Int): Int { - return implementation?.let { - it.instructions.indexOfFirst { instruction -> - instruction.opcode == Opcode.CONST && (instruction as NarrowLiteralInstruction).narrowLiteral == value - } - } ?: -1 -} - fun Method.isNarrowLiteralExists(value: Int): Boolean { return getNarrowLiteralIndex(value) != -1 } -fun Method.getWideLiteralIndex(value: Long): Int { +fun Method.isWideLiteralExists(value: Long): Boolean { + return getWideLiteralIndex(value) != -1 +} + +fun Method.getNarrowLiteralIndex(value: Int): Int { return implementation?.let { it.instructions.indexOfFirst { instruction -> - instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == value + instruction.opcode == Opcode.CONST + && (instruction as NarrowLiteralInstruction).narrowLiteral == value } } ?: -1 } -fun Method.isWideLiteralExists(value: Long): Boolean { - return getWideLiteralIndex(value) != -1 +fun Method.getStringIndex(value: String): Int { + return implementation?.let { + it.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.CONST_STRING + && (instruction as BuilderInstruction21c).reference.toString() == value + } + } ?: -1 } + +fun Method.getWideLiteralIndex(value: Long): Int { + return implementation?.let { + it.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.CONST + && (instruction as WideLiteralInstruction).wideLiteral == value + } + } ?: -1 +} + diff --git a/src/main/kotlin/app/revanced/util/pivotbar/InjectionUtils.kt b/src/main/kotlin/app/revanced/util/pivotbar/InjectionUtils.kt index 8f3a5da38..d873ae7a6 100644 --- a/src/main/kotlin/app/revanced/util/pivotbar/InjectionUtils.kt +++ b/src/main/kotlin/app/revanced/util/pivotbar/InjectionUtils.kt @@ -20,7 +20,7 @@ internal object InjectionUtils { // Register to pass to the hook val registerIndex = insertIndex - 1 // MOVE_RESULT_OBJECT is always the previous instruction - val register = (injectTarget.instruction(registerIndex) as OneRegisterInstruction).registerA + val register = injectTarget.instruction(registerIndex).registerA injectTarget.addInstruction( insertIndex,