feat(music/video-information): integrate video-id patch

This commit is contained in:
inotia00 2023-09-18 00:44:34 +09:00
parent 5ed0708fb3
commit 37d416735a
12 changed files with 94 additions and 117 deletions

View File

@ -10,7 +10,7 @@ import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.buttoncontainerhook.patch.ButtonContainerHookPatch import app.revanced.patches.music.utils.buttoncontainerhook.patch.ButtonContainerHookPatch
import app.revanced.patches.music.utils.intenthook.patch.IntentHookPatch import app.revanced.patches.music.utils.intenthook.patch.IntentHookPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.music.utils.videoid.patch.VideoIdPatch import app.revanced.patches.music.video.information.patch.VideoInformationPatch
import app.revanced.util.enum.CategoryType import app.revanced.util.enum.CategoryType
@Patch @Patch
@ -21,7 +21,7 @@ import app.revanced.util.enum.CategoryType
ButtonContainerHookPatch::class, ButtonContainerHookPatch::class,
IntentHookPatch::class, IntentHookPatch::class,
SettingsPatch::class, SettingsPatch::class,
VideoIdPatch::class VideoInformationPatch::class
] ]
) )
@MusicCompatibility @MusicCompatibility

View File

@ -14,7 +14,7 @@ import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonItemResourcePatch import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonItemResourcePatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.music.utils.videoid.patch.VideoIdPatch import app.revanced.patches.music.video.information.patch.VideoInformationPatch
import app.revanced.util.enum.CategoryType import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_FLYOUT import app.revanced.util.integrations.Constants.MUSIC_FLYOUT
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -26,7 +26,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
[ [
FlyoutButtonItemResourcePatch::class, FlyoutButtonItemResourcePatch::class,
SettingsPatch::class, SettingsPatch::class,
VideoIdPatch::class VideoInformationPatch::class
] ]
) )
@MusicCompatibility @MusicCompatibility

View File

@ -18,7 +18,7 @@ import app.revanced.patches.music.misc.quality.fingerprints.UserQualityChangeFin
import app.revanced.patches.music.utils.annotations.MusicCompatibility import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.music.utils.videoid.patch.VideoIdPatch import app.revanced.patches.music.video.information.patch.VideoInformationPatch
import app.revanced.util.enum.CategoryType import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_MISC_PATH import app.revanced.util.integrations.Constants.MUSIC_MISC_PATH
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
@ -35,7 +35,7 @@ import com.android.tools.smali.dexlib2.iface.reference.Reference
[ [
SettingsPatch::class, SettingsPatch::class,
SharedResourceIdPatch::class, SharedResourceIdPatch::class,
VideoIdPatch::class VideoInformationPatch::class
] ]
) )
@MusicCompatibility @MusicCompatibility
@ -112,7 +112,7 @@ class VideoQualityPatch : BytecodePatch(
) ?: throw MusicVideoQualitySettingsFingerprint.exception ) ?: throw MusicVideoQualitySettingsFingerprint.exception
} ?: throw MusicVideoQualitySettingsParentFingerprint.exception } ?: throw MusicVideoQualitySettingsParentFingerprint.exception
VideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") VideoInformationPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
SettingsPatch.addMusicPreference( SettingsPatch.addMusicPreference(
CategoryType.MISC, CategoryType.MISC,
"revanced_enable_save_video_quality", "revanced_enable_save_video_quality",

View File

@ -13,7 +13,7 @@ import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprin
import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.LikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.LikeFingerprint
import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.RemoveLikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.RemoveLikeFingerprint
import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.TextComponentFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.bytecode.fingerprints.TextComponentFingerprint
import app.revanced.patches.music.utils.videoid.patch.VideoIdPatch import app.revanced.patches.music.video.information.patch.VideoInformationPatch
import app.revanced.util.integrations.Constants.MUSIC_UTILS_PATH import app.revanced.util.integrations.Constants.MUSIC_UTILS_PATH
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -22,7 +22,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
@DependsOn( @DependsOn(
[ [
SharedResourceIdPatch::class, SharedResourceIdPatch::class,
VideoIdPatch::class VideoInformationPatch::class
] ]
) )
class ReturnYouTubeDislikeBytecodePatch : BytecodePatch( class ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
@ -77,7 +77,7 @@ class ReturnYouTubeDislikeBytecodePatch : BytecodePatch(
} }
} ?: throw TextComponentFingerprint.exception } ?: throw TextComponentFingerprint.exception
VideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") VideoInformationPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
} }

View File

@ -13,7 +13,7 @@ import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.MusicPlaybackControlsTimeBarDrawFingerprint import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.MusicPlaybackControlsTimeBarDrawFingerprint
import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.MusicPlaybackControlsTimeBarOnMeasureFingerprint import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.MusicPlaybackControlsTimeBarOnMeasureFingerprint
import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.music.utils.sponsorblock.bytecode.fingerprints.SeekbarOnDrawFingerprint
import app.revanced.patches.music.utils.videoid.patch.VideoIdPatch import app.revanced.patches.music.video.information.patch.VideoInformationPatch
import app.revanced.patches.music.utils.videoinformation.patch.VideoInformationPatch import app.revanced.patches.music.utils.videoinformation.patch.VideoInformationPatch
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction3rc import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction3rc
@ -26,7 +26,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@DependsOn( @DependsOn(
[ [
SharedResourceIdPatch::class, SharedResourceIdPatch::class,
VideoIdPatch::class, VideoInformationPatch::class,
VideoInformationPatch::class VideoInformationPatch::class
] ]
) )
@ -166,7 +166,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
/** /**
* Set current video id * Set current video id
*/ */
VideoIdPatch.injectCall("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V") VideoInformationPatch.injectCall("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V")
} }
private companion object { private companion object {

View File

@ -1,79 +0,0 @@
package app.revanced.patches.music.utils.videoid.patch
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.music.utils.videoid.fingerprint.VideoIdParentFingerprint
import app.revanced.util.integrations.Constants.MUSIC_UTILS_PATH
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
class VideoIdPatch : BytecodePatch(
listOf(VideoIdParentFingerprint)
) {
override fun execute(context: BytecodeContext) {
VideoIdParentFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetClass = (targetReference as FieldReference).type
insertMethod = context
.findClass(targetClass)!!
.mutableClass.methods.first { method ->
method.name == "handleVideoStageEvent"
}
}
} ?: throw VideoIdParentFingerprint.exception
insertMethod.apply {
for (index in implementation!!.instructions.size - 1 downTo 0) {
if (getInstruction(index).opcode != Opcode.INVOKE_INTERFACE) continue
val targetReference = getInstruction<ReferenceInstruction>(index).reference
if (!targetReference.toString().endsWith("Ljava/lang/String;")) continue
insertIndex = index + 1
videoIdRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
break
}
offset++ // offset so setVideoId is called before any injected call
}
injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")
}
companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR = "$MUSIC_UTILS_PATH/VideoInformation;"
private var offset = 0
private var insertIndex: Int = 0
private var videoIdRegister: Int = 0
private lateinit var insertMethod: MutableMethod
/**
* Adds an invoke-static instruction, called with the new id when the video changes
* @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;`
*/
fun injectCall(
methodDescriptor: String
) {
insertMethod.addInstructions(
insertIndex + offset, // move-result-object offset
"invoke-static {v$videoIdRegister}, $methodDescriptor"
)
}
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.videoinformation.fingerprints package app.revanced.patches.music.video.information.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.videoinformation.fingerprints package app.revanced.patches.music.video.information.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.videoinformation.fingerprints package app.revanced.patches.music.video.information.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.videoid.fingerprint package app.revanced.patches.music.video.information.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.utils.videoinformation.fingerprints package app.revanced.patches.music.video.information.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode

View File

@ -1,8 +1,6 @@
package app.revanced.patches.music.utils.videoinformation.patch package app.revanced.patches.music.video.information.patch
import app.revanced.extensions.exception import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
@ -13,14 +11,16 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.fingerprints.SeekBarConstructorFingerprint import app.revanced.patches.music.utils.fingerprints.SeekBarConstructorFingerprint
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.videoinformation.fingerprints.PlayerControllerSetTimeReferenceFingerprint import app.revanced.patches.music.video.information.fingerprints.PlayerControllerSetTimeReferenceFingerprint
import app.revanced.patches.music.utils.videoinformation.fingerprints.PlayerInitFingerprint import app.revanced.patches.music.video.information.fingerprints.PlayerInitFingerprint
import app.revanced.patches.music.utils.videoinformation.fingerprints.SeekFingerprint import app.revanced.patches.music.video.information.fingerprints.SeekFingerprint
import app.revanced.patches.music.utils.videoinformation.fingerprints.VideoLengthFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoIdParentFingerprint
import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint
import app.revanced.util.integrations.Constants.MUSIC_VIDEO_PATH
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -29,19 +29,13 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
import com.android.tools.smali.dexlib2.util.MethodUtil import com.android.tools.smali.dexlib2.util.MethodUtil
@Name("Video information") @DependsOn([SharedResourceIdPatch::class])
@Description("Hooks YouTube to get information about the current playing video.")
@DependsOn(
[
SharedResourceIdPatch::class
]
)
@MusicCompatibility
class VideoInformationPatch : BytecodePatch( class VideoInformationPatch : BytecodePatch(
listOf( listOf(
PlayerControllerSetTimeReferenceFingerprint, PlayerControllerSetTimeReferenceFingerprint,
PlayerInitFingerprint, PlayerInitFingerprint,
SeekBarConstructorFingerprint, SeekBarConstructorFingerprint,
VideoIdParentFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
@ -80,6 +74,7 @@ class VideoInformationPatch : BytecodePatch(
} ?: throw SeekFingerprint.exception } ?: throw SeekFingerprint.exception
} ?: throw PlayerInitFingerprint.exception } ?: throw PlayerInitFingerprint.exception
/** /**
* Set current video length * Set current video length
*/ */
@ -109,6 +104,7 @@ class VideoInformationPatch : BytecodePatch(
} ?: throw VideoLengthFingerprint.exception } ?: throw VideoLengthFingerprint.exception
} ?: throw SeekBarConstructorFingerprint.exception } ?: throw SeekBarConstructorFingerprint.exception
/** /**
* Set the video time method * Set the video time method
*/ */
@ -118,24 +114,84 @@ class VideoInformationPatch : BytecodePatch(
.getMethod() as MutableMethod .getMethod() as MutableMethod
} ?: throw PlayerControllerSetTimeReferenceFingerprint.exception } ?: throw PlayerControllerSetTimeReferenceFingerprint.exception
/** /**
* Set current video time * Set current video time
*/ */
videoTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime") videoTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime")
/**
* Inject call for video id
*/
VideoIdParentFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference
val targetClass = (targetReference as FieldReference).type
videoIdMethod = context
.findClass(targetClass)!!
.mutableClass.methods.first { method ->
method.name == "handleVideoStageEvent"
}
}
} ?: throw VideoIdParentFingerprint.exception
videoIdMethod.apply {
for (index in implementation!!.instructions.size - 1 downTo 0) {
if (getInstruction(index).opcode != Opcode.INVOKE_INTERFACE) continue
val targetReference = getInstruction<ReferenceInstruction>(index).reference
if (!targetReference.toString().endsWith("Ljava/lang/String;")) continue
videoIdIndex = index + 1
videoIdRegister = getInstruction<OneRegisterInstruction>(videoIdIndex).registerA
break
}
offset++ // offset so setVideoId is called before any injected call
}
/**
* Set current video id
*/
injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")
} }
companion object { companion object {
private const val INTEGRATIONS_CLASS_DESCRIPTOR = private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/music/patches/utils/VideoInformation;" "$MUSIC_VIDEO_PATH/VideoInformation;"
private lateinit var playerInitMethod: MutableMethod private var offset = 0
private var playerInitInsertIndex = 4 private var playerInitInsertIndex = 4
private lateinit var timeMethod: MutableMethod
private var timeInitInsertIndex = 2 private var timeInitInsertIndex = 2
private var videoIdIndex = 0
private var videoIdRegister: Int = 0
private lateinit var videoIdMethod: MutableMethod
private lateinit var playerInitMethod: MutableMethod
private lateinit var timeMethod: MutableMethod
lateinit var rectangleFieldName: String lateinit var rectangleFieldName: String
/**
* Adds an invoke-static instruction, called with the new id when the video changes
* @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;`
*/
internal fun injectCall(
methodDescriptor: String
) {
videoIdMethod.addInstructions(
videoIdIndex + offset, // move-result-object offset
"invoke-static {v$videoIdRegister}, $methodDescriptor"
)
}
private fun MutableMethod.insert(insertIndex: Int, register: String, descriptor: String) = private fun MutableMethod.insert(insertIndex: Int, register: String, descriptor: String) =
addInstruction(insertIndex, "invoke-static { $register }, $descriptor") addInstruction(insertIndex, "invoke-static { $register }, $descriptor")