Skip to content

Commit af81ee7

Browse files
inotia00Francesco146
authored andcommitted
feat(YouTube): Add Change share sheet patch
1 parent 5774c2d commit af81ee7

5 files changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package app.revanced.patches.youtube.misc.share
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
7+
import app.revanced.patches.shared.litho.LithoFilterPatch
8+
import app.revanced.patches.youtube.misc.share.fingerprints.BottomSheetRecyclerViewFingerprint
9+
import app.revanced.patches.youtube.misc.share.fingerprints.UpdateShareSheetCommandFingerprint
10+
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
11+
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
12+
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
13+
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
14+
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView
15+
import app.revanced.patches.youtube.utils.settings.SettingsPatch
16+
import app.revanced.util.getTargetIndexOrThrow
17+
import app.revanced.util.getWideLiteralInstructionIndex
18+
import app.revanced.util.patch.BaseBytecodePatch
19+
import app.revanced.util.resultOrThrow
20+
import com.android.tools.smali.dexlib2.Opcode
21+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
22+
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
23+
24+
@Suppress("unused")
25+
object ShareSheetPatch : BaseBytecodePatch(
26+
name = "Change share sheet",
27+
description = "Add option to change from in-app share sheet to system share sheet.",
28+
dependencies = setOf(
29+
LithoFilterPatch::class,
30+
SettingsPatch::class,
31+
SharedResourceIdPatch::class
32+
),
33+
compatiblePackages = COMPATIBLE_PACKAGE,
34+
fingerprints = setOf(
35+
BottomSheetRecyclerViewFingerprint,
36+
UpdateShareSheetCommandFingerprint,
37+
)
38+
) {
39+
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
40+
"$MISC_PATH/ShareSheetPatch;"
41+
42+
private const val FILTER_CLASS_DESCRIPTOR =
43+
"$COMPONENTS_PATH/ShareSheetMenuFilter;"
44+
45+
override fun execute(context: BytecodeContext) {
46+
47+
// Detects that the Share sheet panel has been invoked.
48+
BottomSheetRecyclerViewFingerprint.resultOrThrow().mutableMethod.apply {
49+
val constIndex = getWideLiteralInstructionIndex(BottomSheetRecyclerView)
50+
val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST)
51+
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
52+
53+
addInstruction(
54+
targetIndex + 1,
55+
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onShareSheetMenuCreate(Landroid/support/v7/widget/RecyclerView;)V"
56+
)
57+
}
58+
59+
// Remove the app list from the Share sheet panel on YouTube.
60+
UpdateShareSheetCommandFingerprint.resultOrThrow().let {
61+
it.mutableMethod.apply {
62+
val targetIndex = it.scanResult.patternScanResult!!.endIndex
63+
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA
64+
65+
addInstructions(
66+
targetIndex + 1, """
67+
invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->overridePackageName(Ljava/lang/String;)Ljava/lang/String;
68+
move-result-object v$targetRegister
69+
"""
70+
)
71+
}
72+
}
73+
74+
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
75+
76+
/**
77+
* Add settings
78+
*/
79+
SettingsPatch.addPreference(
80+
arrayOf(
81+
"PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS",
82+
"SETTINGS: CHANGE_SHARE_SHEET"
83+
)
84+
)
85+
}
86+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app.revanced.patches.youtube.misc.share.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView
5+
import app.revanced.util.fingerprint.LiteralValueFingerprint
6+
import com.android.tools.smali.dexlib2.AccessFlags
7+
8+
internal object BottomSheetRecyclerViewFingerprint : LiteralValueFingerprint(
9+
returnType = "Lj${'$'}/util/Optional;",
10+
accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL,
11+
parameters = emptyList(),
12+
literalSupplier = { BottomSheetRecyclerView }
13+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package app.revanced.patches.youtube.misc.share.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import app.revanced.util.getReference
6+
import app.revanced.util.indexOfFirstInstruction
7+
import com.android.tools.smali.dexlib2.AccessFlags
8+
import com.android.tools.smali.dexlib2.Opcode
9+
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
10+
11+
internal object UpdateShareSheetCommandFingerprint : MethodFingerprint(
12+
returnType = "V",
13+
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
14+
parameters = listOf("L", "Ljava/util/Map;"),
15+
opcodes = listOf(
16+
Opcode.IF_EQZ,
17+
Opcode.INVOKE_INTERFACE,
18+
Opcode.MOVE_RESULT_OBJECT,
19+
Opcode.CHECK_CAST,
20+
Opcode.IGET_OBJECT
21+
),
22+
customFingerprint = custom@{ methodDef, _ ->
23+
methodDef.indexOfFirstInstruction {
24+
opcode == Opcode.SGET_OBJECT &&
25+
getReference<FieldReference>()?.name == "updateShareSheetCommand"
26+
} >= 0
27+
}
28+
)

src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object SharedResourceIdPatch : ResourcePatch() {
3232
var Bar = -1L
3333
var BarContainerHeight = -1L
3434
var BottomSheetFooterText = -1L
35+
var BottomSheetRecyclerView = -1L
3536
var BottomUiContainerStub = -1L
3637
var CaptionToggleContainer = -1L
3738
var CastMediaRouteButton = -1L
@@ -136,6 +137,7 @@ object SharedResourceIdPatch : ResourcePatch() {
136137
Bar = getId(LAYOUT, "bar")
137138
BarContainerHeight = getId(DIMEN, "bar_container_height")
138139
BottomSheetFooterText = getId(ID, "bottom_sheet_footer_text")
140+
BottomSheetRecyclerView = getId(LAYOUT, "bottom_sheet_recycler_view")
139141
BottomUiContainerStub = getId(ID, "bottom_ui_container_stub")
140142
CaptionToggleContainer = getId(ID, "caption_toggle_container")
141143
CastMediaRouteButton = getId(LAYOUT, "castmediaroutebutton")

src/main/resources/youtube/settings/xml/revanced_prefs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@
666666
<!-- PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS
667667
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>PREFERENCE_CATEGORY: MISC_EXPERIMENTAL_FLAGS -->
668668

669+
<!-- SETTINGS: CHANGE_SHARE_SHEET
670+
<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 -->
671+
669672
<!-- SETTINGS: ENABLE_OPUS_CODEC
670673
<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 -->
671674

@@ -740,6 +743,7 @@
740743
</PreferenceCategory>
741744

742745
<PreferenceCategory android:title="@string/revanced_preference_screen_misc_title" android:layout="@layout/revanced_settings_preferences_category">
746+
<Preference android:title="Change share sheet" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
743747
<Preference android:title="Disable QUIC protocol" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
744748
<Preference android:title="Enable debug logging" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
745749
<Preference android:title="Enable external browser" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
@@ -748,6 +752,7 @@
748752
<Preference android:title="Remove background playback restrictions" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
749753
<Preference android:title="Sanitize sharing links" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
750754
<Preference android:title="Spoof client" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
755+
<Preference android:title="Watch history" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
751756
</PreferenceCategory>
752757

753758
<PreferenceCategory android:title="@string/revanced_preference_category_others" android:layout="@layout/revanced_settings_preferences_category">

0 commit comments

Comments
 (0)