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+ }
0 commit comments