forked from inotia00/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): add
Change share sheet
patch
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/kotlin/app/revanced/patches/youtube/misc/share/ShareSheetPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...pp/revanced/patches/youtube/misc/share/fingerprints/BottomSheetRecyclerViewFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
) |
28 changes: 28 additions & 0 deletions
28
...pp/revanced/patches/youtube/misc/share/fingerprints/UpdateShareSheetCommandFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters