refactor(enable-old-quality-layout): improve the patch method

This commit is contained in:
inotia00
2023-03-04 02:36:11 +09:00
parent 3177034060
commit 974d60336e
4 changed files with 40 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -14,17 +15,28 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.flyoutpanel.oldqualitylayout.fingerprints.QualityMenuViewInflateFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch
import app.revanced.patches.youtube.video.quality.bytecode.fingerprints.VideoQualitySettingsParentFingerprint
import app.revanced.util.integrations.Constants.FLYOUT_PANEL_LAYOUT
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("enable-old-quality-layout")
@Description("Enables the original quality flyout menu.")
@DependsOn([SettingsPatch::class])
@DependsOn(
[
LegacyVideoIdPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class OldQualityLayoutPatch : BytecodePatch(
listOf(QualityMenuViewInflateFingerprint)
listOf(
QualityMenuViewInflateFingerprint,
VideoQualitySettingsParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
@ -33,13 +45,26 @@ class OldQualityLayoutPatch : BytecodePatch(
val insertIndex = this.size - 1 - 1
val register = (this[insertIndex] as FiveRegisterInstruction).registerC
it.addInstructions(
insertIndex, // insert the integrations instructions right before the listener
it.addInstruction(
insertIndex + 1,
"invoke-static { v$register }, $FLYOUT_PANEL_LAYOUT->enableOldQualityMenu(Landroid/widget/ListView;)V"
)
}
} ?: return QualityMenuViewInflateFingerprint.toErrorResult()
VideoQualitySettingsParentFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.startIndex + LegacyVideoIdPatch.qualityOffSet
val register = (this.implementation!!.instructions[insertIndex] as OneRegisterInstruction).registerA
addInstructions(
insertIndex, """
invoke-static { v$register }, $FLYOUT_PANEL_LAYOUT->enableOldQualityLayout(I)I
move-result v$register
"""
)
}
} ?: return VideoQualitySettingsParentFingerprint.toErrorResult()
/*
* Add settings
*/

View File

@ -41,6 +41,8 @@ class LegacyVideoIdPatch : BytecodePatch(
companion object {
private var offset = 2
internal var qualityOffSet: Int = 0
private var insertIndex: Int = 0
private var videoIdRegister: Int = 0
private lateinit var insertMethod: MutableMethod

View File

@ -3,10 +3,16 @@ package app.revanced.patches.youtube.video.quality.bytecode.fingerprints
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 VideoQualitySettingsParentFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("[L", "I", "Z"),
opcodes = listOf(
Opcode.IF_EQZ,
Opcode.IF_EQ,
Opcode.IF_EQ
),
strings = listOf("menu_item_video_quality")
)

View File

@ -58,8 +58,10 @@ class VideoQualityBytecodePatch : BytecodePatch(
const-string v2, "$qIndexMethodName"
invoke-static {p1, p2, v1, v2}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->setVideoQuality([Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/String;)I
move-result p2
"""
"""
)
LegacyVideoIdPatch.qualityOffSet = 5
} ?: return VideoQualitySettingsParentFingerprint.toErrorResult()
LegacyVideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")