mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-04 08:34:27 +02:00
feat(YouTube/Overlay buttons): hook download button for feed flyout menu
This commit is contained in:
parent
9ba4d6da15
commit
017ef705f8
@ -9,7 +9,7 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG
|
||||
import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
|
||||
import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch.mainActivityClassDef
|
||||
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch.mainActivityMutableClass
|
||||
import app.revanced.patches.music.utils.playerresponse.PlayerResponsePatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerCastMediaRouteButton
|
||||
@ -44,7 +44,7 @@ object ReplaceCastButtonPatch : BaseBytecodePatch(
|
||||
use = false
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
CastButtonContainerFingerprint.resolve(context, mainActivityClassDef)
|
||||
CastButtonContainerFingerprint.resolve(context, mainActivityMutableClass)
|
||||
|
||||
CastButtonContainerFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
|
@ -1,34 +1,6 @@
|
||||
package app.revanced.patches.music.utils.mainactivity
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.music.utils.mainactivity.fingerprints.MainActivityFingerprint
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||
import app.revanced.patches.shared.mainactivity.BaseMainActivityResolvePatch
|
||||
|
||||
object MainActivityResolvePatch : BytecodePatch(
|
||||
setOf(MainActivityFingerprint)
|
||||
) {
|
||||
lateinit var mainActivityClassDef: ClassDef
|
||||
private lateinit var onCreateMethod: MutableMethod
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
MainActivityFingerprint.resultOrThrow().let {
|
||||
mainActivityClassDef = it.classDef
|
||||
onCreateMethod = it.mutableMethod
|
||||
}
|
||||
}
|
||||
|
||||
fun injectInit(
|
||||
methods: String,
|
||||
descriptor: String
|
||||
) {
|
||||
onCreateMethod.addInstruction(
|
||||
2,
|
||||
"invoke-static/range {p0 .. p0}, $UTILS_PATH/$methods;->$descriptor(Landroid/app/Activity;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
object MainActivityResolvePatch : BaseMainActivityResolvePatch(MainActivityFingerprint)
|
@ -9,12 +9,13 @@ import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.music.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.music.utils.integrations.IntegrationsPatch
|
||||
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.music.utils.mainactivity.MainActivityResolvePatch.injectInit
|
||||
import app.revanced.patches.music.utils.settings.fingerprints.GoogleApiActivityFingerprint
|
||||
import app.revanced.patches.music.utils.settings.fingerprints.PreferenceFingerprint
|
||||
import app.revanced.patches.music.utils.settings.fingerprints.SettingsHeadersFragmentFingerprint
|
||||
import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR
|
||||
import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprint
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.resultOrThrow
|
||||
@ -41,6 +42,8 @@ object SettingsBytecodePatch : BytecodePatch(
|
||||
"$INTEGRATIONS_PATH/settings/ActivityHook;"
|
||||
private const val INTEGRATIONS_FRAGMENT_CLASS_DESCRIPTOR =
|
||||
"$INTEGRATIONS_PATH/settings/preference/ReVancedPreferenceFragment;"
|
||||
private const val INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/InitializationPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
@ -106,8 +109,9 @@ object SettingsBytecodePatch : BytecodePatch(
|
||||
}
|
||||
}
|
||||
|
||||
injectInit("InitializationPatch", "setDeviceInformation")
|
||||
injectInit("InitializationPatch", "onCreate")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setDeviceInformation")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "onCreate")
|
||||
MainActivityResolvePatch.injectConstructorMethodCall(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR, "setActivity")
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package app.revanced.patches.shared.mainactivity
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
abstract class BaseMainActivityResolvePatch(
|
||||
private val mainActivityOnCreateFingerprint: MethodFingerprint
|
||||
): BytecodePatch(
|
||||
setOf(mainActivityOnCreateFingerprint)
|
||||
) {
|
||||
lateinit var mainActivityMutableClass: MutableClass
|
||||
private lateinit var constructorMethod: MutableMethod
|
||||
private lateinit var onBackPressedMethod: MutableMethod
|
||||
private lateinit var onCreateMethod: MutableMethod
|
||||
private var constructorMethodIndex by Delegates.notNull<Int>()
|
||||
private var onBackPressedMethodIndex by Delegates.notNull<Int>()
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
val mainActivityResult = mainActivityOnCreateFingerprint.resultOrThrow()
|
||||
onCreateMethod = mainActivityResult.mutableMethod
|
||||
mainActivityMutableClass = mainActivityResult.mutableClass
|
||||
|
||||
/**
|
||||
* Set Constructor Method
|
||||
*/
|
||||
constructorMethod =
|
||||
mainActivityMutableClass.methods.find { method -> MethodUtil.isConstructor(method) }
|
||||
?: throw PatchException("Could not find constructorMethod")
|
||||
constructorMethodIndex = constructorMethod.implementation!!.instructions.size - 1
|
||||
|
||||
/**
|
||||
* Set OnBackPressed Method
|
||||
*/
|
||||
onBackPressedMethod =
|
||||
mainActivityMutableClass.methods.find { method -> method.name == "onBackPressed" }
|
||||
?: throw PatchException("Could not find onBackPressedMethod")
|
||||
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID)
|
||||
}
|
||||
|
||||
fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
constructorMethod.injectMethodCall(classDescriptor, methodDescriptor, constructorMethodIndex)
|
||||
|
||||
fun injectOnBackPressedMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
|
||||
|
||||
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor, 0)
|
||||
|
||||
private fun MutableMethod.injectMethodCall(
|
||||
classDescriptor: String,
|
||||
methodDescriptor: String,
|
||||
insertIndex: Int
|
||||
) {
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static/range {p0 .. p0}, $classDescriptor->$methodDescriptor(Landroid/app/Activity;)V"
|
||||
)
|
||||
}
|
||||
}
|
@ -4,32 +4,29 @@ import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.DownloadActionsFingerprint
|
||||
import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.OfflineVideoEndpointFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.util.resultOrThrow
|
||||
|
||||
@Patch(dependencies = [MainActivityResolvePatch::class])
|
||||
object DownloadButtonHookPatch : BytecodePatch(
|
||||
setOf(DownloadActionsFingerprint)
|
||||
setOf(OfflineVideoEndpointFingerprint)
|
||||
) {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/HookDownloadButtonPatch;"
|
||||
override fun execute(context: BytecodeContext) {
|
||||
DownloadActionsFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex
|
||||
|
||||
addInstructionsWithLabels(
|
||||
targetIndex, """
|
||||
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->shouldHookDownloadButton()Z
|
||||
move-result v0
|
||||
if-eqz v0, :default
|
||||
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->startDownloadActivity()V
|
||||
return-void
|
||||
""", ExternalLabel("default", getInstruction(targetIndex))
|
||||
)
|
||||
}
|
||||
OfflineVideoEndpointFingerprint.resultOrThrow().mutableMethod.apply {
|
||||
addInstructionsWithLabels(
|
||||
0, """
|
||||
invoke-static/range {p3 .. p3}, $INTEGRATIONS_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/lang/String;)Z
|
||||
move-result v0
|
||||
if-eqz v0, :show_native_downloader
|
||||
return-void
|
||||
""", ExternalLabel("show_native_downloader", getInstruction(0))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal object DownloadActionsFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
parameters = listOf("L", "L", "Z"),
|
||||
opcodes = listOf(Opcode.INVOKE_STATIC),
|
||||
strings = listOf("offline/get_download_action")
|
||||
)
|
@ -0,0 +1,16 @@
|
||||
package app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal object OfflineVideoEndpointFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
returnType = "V",
|
||||
parameters = listOf(
|
||||
"Ljava/util/Map;",
|
||||
"L",
|
||||
"Ljava/lang/String", // VideoId
|
||||
"L"),
|
||||
strings = listOf("Object is not an offlineable video: ")
|
||||
)
|
@ -1,67 +1,6 @@
|
||||
package app.revanced.patches.youtube.utils.mainactivity
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.shared.mainactivity.BaseMainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.fingerprints.MainActivityFingerprint
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object MainActivityResolvePatch : BytecodePatch(
|
||||
setOf(MainActivityFingerprint)
|
||||
) {
|
||||
lateinit var mainActivityMutableClass: MutableClass
|
||||
private lateinit var constructorMethod: MutableMethod
|
||||
private lateinit var onBackPressedMethod: MutableMethod
|
||||
private lateinit var onCreateMethod: MutableMethod
|
||||
private var constructorMethodIndex by Delegates.notNull<Int>()
|
||||
private var onBackPressedMethodIndex by Delegates.notNull<Int>()
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
val mainActivityResult = MainActivityFingerprint.resultOrThrow()
|
||||
onCreateMethod = mainActivityResult.mutableMethod
|
||||
mainActivityMutableClass = mainActivityResult.mutableClass
|
||||
|
||||
/**
|
||||
* Set Constructor Method
|
||||
*/
|
||||
constructorMethod =
|
||||
mainActivityMutableClass.methods.find { method -> MethodUtil.isConstructor(method) }
|
||||
?: throw PatchException("Could not find constructorMethod")
|
||||
constructorMethodIndex = constructorMethod.implementation!!.instructions.size - 1
|
||||
|
||||
/**
|
||||
* Set OnBackPressed Method
|
||||
*/
|
||||
onBackPressedMethod =
|
||||
mainActivityMutableClass.methods.find { method -> method.name == "onBackPressed" }
|
||||
?: throw PatchException("Could not find onBackPressedMethod")
|
||||
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID)
|
||||
}
|
||||
|
||||
fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
constructorMethod.injectMethodCall(classDescriptor, methodDescriptor, constructorMethodIndex)
|
||||
|
||||
fun injectOnBackPressedMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
|
||||
|
||||
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor, 0)
|
||||
|
||||
private fun MutableMethod.injectMethodCall(
|
||||
classDescriptor: String,
|
||||
methodDescriptor: String,
|
||||
insertIndex: Int
|
||||
) {
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static/range {p0 .. p0}, $classDescriptor->$methodDescriptor(Landroid/app/Activity;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
object MainActivityResolvePatch : BaseMainActivityResolvePatch(MainActivityFingerprint)
|
@ -7,6 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR
|
||||
import app.revanced.patches.shared.mapping.ResourceMappingPatch
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
@ -47,7 +48,7 @@ object SettingsBytecodePatch : BytecodePatch(
|
||||
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setDeviceInformation")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "onCreate")
|
||||
MainActivityResolvePatch.injectConstructorMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setMainActivity")
|
||||
MainActivityResolvePatch.injectConstructorMethodCall(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR, "setActivity")
|
||||
|
||||
}
|
||||
private fun MutableMethod.injectCall(index: Int) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user