fix(music/video-id-hook): patches are broken in the latest versions

This commit is contained in:
inotia00 2023-06-29 18:15:08 +09:00
parent 93dcba2582
commit 7a49a850ba
3 changed files with 51 additions and 22 deletions

View File

@ -1,16 +0,0 @@
package app.revanced.patches.music.utils.videoid.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object VideoIdFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("SubtitlesOverlayPresenter;") && methodDef.name == "handleVideoStageEvent" }
)

View File

@ -0,0 +1,20 @@
package app.revanced.patches.music.utils.videoid.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object VideoIdParentFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf(),
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.INVOKE_SUPER,
Opcode.IGET_OBJECT,
Opcode.CONST_4,
Opcode.IPUT_OBJECT,
Opcode.IGET_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("WatchFragment;") && methodDef.name == "onDestroyView" }
)

View File

@ -12,27 +12,52 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.videoid.fingerprint.VideoIdFingerprint
import app.revanced.patches.music.utils.videoid.fingerprint.VideoIdParentFingerprint
import app.revanced.util.integrations.Constants.MUSIC_UTILS_PATH
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference
@Name("video-id-hook")
@Description("Hook to detect when the video id changes.")
@MusicCompatibility
@Version("0.0.1")
class VideoIdPatch : BytecodePatch(
listOf(VideoIdFingerprint)
listOf(VideoIdParentFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
VideoIdFingerprint.result?.let {
VideoIdParentFingerprint.result?.let {
it.mutableMethod.apply {
insertIndex = it.scanResult.patternScanResult!!.endIndex
insertMethod = this
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"
}
}
} ?: return VideoIdParentFingerprint.toErrorResult()
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
} ?: return VideoIdFingerprint.toErrorResult()
}
injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")