feat(YouTube): add Change share sheet patch

This commit is contained in:
inotia00 2024-08-11 17:42:02 +09:00
parent 4aec1a16b5
commit 7339479fd1
6 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,86 @@
package app.revanced.patches.youtube.misc.share
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.misc.share.fingerprints.BottomSheetRecyclerViewFingerprint
import app.revanced.patches.youtube.misc.share.fingerprints.UpdateShareSheetCommandFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Suppress("unused")
object ShareSheetPatch : BaseBytecodePatch(
name = "Change share sheet",
description = "Add option to change from in-app share sheet to system share sheet.",
dependencies = setOf(
LithoFilterPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class
),
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(
BottomSheetRecyclerViewFingerprint,
UpdateShareSheetCommandFingerprint,
)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$MISC_PATH/ShareSheetPatch;"
private const val FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/ShareSheetMenuFilter;"
override fun execute(context: BytecodeContext) {
// Detects that the Share sheet panel has been invoked.
BottomSheetRecyclerViewFingerprint.resultOrThrow().mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(BottomSheetRecyclerView)
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onShareSheetMenuCreate(Landroid/support/v7/widget/RecyclerView;)V"
)
}
// Remove the app list from the Share sheet panel on YouTube.
UpdateShareSheetCommandFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
addInstructions(
targetIndex + 1, """
invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->overridePackageName(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
"""
)
}
}
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS",
"SETTINGS: CHANGE_SHARE_SHEET"
)
)
}
}

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.share.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object BottomSheetRecyclerViewFingerprint : LiteralValueFingerprint(
returnType = "Lj${'$'}/util/Optional;",
accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = emptyList(),
literalSupplier = { BottomSheetRecyclerView }
)

View File

@ -0,0 +1,28 @@
package app.revanced.patches.youtube.misc.share.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
internal object UpdateShareSheetCommandFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Ljava/util/Map;"),
opcodes = listOf(
Opcode.IF_EQZ,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.IGET_OBJECT
),
customFingerprint = custom@{ methodDef, _ ->
methodDef.indexOfFirstInstruction {
opcode == Opcode.SGET_OBJECT &&
getReference<FieldReference>()?.name == "updateShareSheetCommand"
} >= 0
}
)

View File

@ -32,6 +32,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var Bar = -1L
var BarContainerHeight = -1L
var BottomSheetFooterText = -1L
var BottomSheetRecyclerView = -1L
var BottomUiContainerStub = -1L
var CaptionToggleContainer = -1L
var CastMediaRouteButton = -1L
@ -136,6 +137,7 @@ object SharedResourceIdPatch : ResourcePatch() {
Bar = getId(LAYOUT, "bar")
BarContainerHeight = getId(DIMEN, "bar_container_height")
BottomSheetFooterText = getId(ID, "bottom_sheet_footer_text")
BottomSheetRecyclerView = getId(LAYOUT, "bottom_sheet_recycler_view")
BottomUiContainerStub = getId(ID, "bottom_ui_container_stub")
CaptionToggleContainer = getId(ID, "caption_toggle_container")
CastMediaRouteButton = getId(LAYOUT, "castmediaroutebutton")

View File

@ -1538,6 +1538,9 @@ Tap on the continue button and disable battery optimizations."</string>
<string name="revanced_disable_quic_protocol_title">Disable QUIC protocol</string>
<string name="revanced_disable_quic_protocol_summary">"Disable CronetEngine's QUIC protocol."</string>
<string name="revanced_change_share_sheet_title">Change share sheet</string>
<string name="revanced_change_share_sheet_summary_on">System share sheet is used.</string>
<string name="revanced_change_share_sheet_summary_off">In-app share sheet is used.</string>
<string name="revanced_enable_opus_codec_title">Enable OPUS codec</string>
<string name="revanced_enable_opus_codec_summary">Enable the OPUS codec if the player response includes the OPUS codec.</string>

View File

@ -668,6 +668,9 @@
<!-- PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS -->
<!-- SETTINGS: CHANGE_SHARE_SHEET
<SwitchPreference android:title="@string/revanced_change_share_sheet_title" android:key="revanced_change_share_sheet" android:summaryOn="@string/revanced_change_share_sheet_summary_on" android:summaryOff="@string/revanced_change_share_sheet_summary_off" />SETTINGS: CHANGE_SHARE_SHEET -->
<!-- SETTINGS: ENABLE_OPUS_CODEC
<SwitchPreference android:title="@string/revanced_enable_opus_codec_title" android:key="revanced_enable_opus_codec" android:summary="@string/revanced_enable_opus_codec_summary" />SETTINGS: ENABLE_OPUS_CODEC -->
@ -742,6 +745,7 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/revanced_preference_screen_misc_title" android:layout="@layout/revanced_settings_preferences_category">
<Preference android:title="Change share sheet" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable QUIC protocol" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Enable debug logging" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Enable external browser" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>