From 2497425c9f11b8b14c861c2f0f34ff47bdbfac53 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 17 Jul 2022 16:00:58 +0200 Subject: [PATCH] fix: `old-quality-layout` patch --- .../app/revanced/extensions/Extensions.kt | 1 + .../OldQualityLayoutCompatibility.kt | 2 +- .../OldQualityParentFingerprint.kt | 50 ------------------- ...t => QualityMenuViewInflateFingerprint.kt} | 28 +++++++---- .../patch/OldQualityLayoutPatch.kt | 46 ++++++----------- 5 files changed, 36 insertions(+), 91 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityParentFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/{OldQualityFingerprint.kt => QualityMenuViewInflateFingerprint.kt} (52%) diff --git a/src/main/kotlin/app/revanced/extensions/Extensions.kt b/src/main/kotlin/app/revanced/extensions/Extensions.kt index 6a950ca4..b7bf29de 100644 --- a/src/main/kotlin/app/revanced/extensions/Extensions.kt +++ b/src/main/kotlin/app/revanced/extensions/Extensions.kt @@ -17,6 +17,7 @@ import org.w3c.dom.Node import java.io.OutputStream import java.nio.file.Files +// TODO: this method does not make sense here internal fun MutableMethodImplementation.injectHideCall( index: Int, register: Int diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/annotations/OldQualityLayoutCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/annotations/OldQualityLayoutCompatibility.kt index 5c99f754..d14dfe07 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/annotations/OldQualityLayoutCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/annotations/OldQualityLayoutCompatibility.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.annotation.Package @Compatibility( [Package( - "com.google.android.youtube", arrayOf("17.17.34", "17.19.36", "17.20.37", "17.22.36", "17.23.35", "17.23.36", "17.24.34", "17.24.35") + "com.google.android.youtube", arrayOf("17.17.34", "17.19.36", "17.20.37", "17.22.36", "17.23.35", "17.23.36", "17.24.34", "17.24.35", "17.25.34", "17.26.35") )] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityParentFingerprint.kt deleted file mode 100644 index 268904cb..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityParentFingerprint.kt +++ /dev/null @@ -1,50 +0,0 @@ -package app.revanced.patches.youtube.layout.oldqualitylayout.fingerprints - -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod -import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod -import app.revanced.patches.youtube.layout.oldqualitylayout.annotations.OldQualityLayoutCompatibility -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -@Name("old-quality-parent-method-fingerprint") -@MatchingMethod( - "Libh", "" -) -@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. -@OldQualityLayoutCompatibility -@Version("0.0.1") -object OldQualityParentFingerprint : MethodFingerprint( - "V", - AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - listOf("L", "L", "L", "L", "L", "L", "L"), - listOf( - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.SGET_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.SGET_OBJECT, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IGET_OBJECT, - Opcode.IF_NEZ, - Opcode.SGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.IF_NEZ, - Opcode.SGET_OBJECT, - Opcode.IGET_BOOLEAN, - Opcode.CONST_4, - Opcode.CONST_4, - Opcode.CONST_4, - ) -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt similarity index 52% rename from src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt index b6f07226..538307e5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/OldQualityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/fingerprints/QualityMenuViewInflateFingerprint.kt @@ -3,27 +3,37 @@ package app.revanced.patches.youtube.layout.oldqualitylayout.fingerprints import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.layout.oldqualitylayout.annotations.OldQualityLayoutCompatibility import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -@Name("old-quality-fingerprint") -@MatchingMethod(definingClass = "Libh") -@FuzzyPatternScanMethod(2) +@Name("quality-menu-view-inflate-fingerprint") +@MatchingMethod("Lkhp;", "K") @OldQualityLayoutCompatibility @Version("0.0.1") -object OldQualityFingerprint : MethodFingerprint( - "L", AccessFlags.FINAL or AccessFlags.PRIVATE, listOf("Z"), listOf( +object QualityMenuViewInflateFingerprint : MethodFingerprint( + "L", AccessFlags.FINAL or AccessFlags.PUBLIC, listOf("L", "L", "L"), listOf( + Opcode.INVOKE_SUPER, + Opcode.CONST, Opcode.CONST_4, Opcode.INVOKE_VIRTUAL, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST, Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_16, + Opcode.INVOKE_VIRTUAL, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, Opcode.IGET_OBJECT, - Opcode.GOTO, Opcode.IGET_OBJECT, + Opcode.CONST_STRING, ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt index 0c35d436..4ae41815 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/oldqualitylayout/patch/OldQualityLayoutPatch.kt @@ -4,20 +4,16 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.impl.BytecodeData -import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve +import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.Dependencies import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patches.youtube.layout.oldqualitylayout.annotations.OldQualityLayoutCompatibility -import app.revanced.patches.youtube.layout.oldqualitylayout.fingerprints.OldQualityFingerprint -import app.revanced.patches.youtube.layout.oldqualitylayout.fingerprints.OldQualityParentFingerprint +import app.revanced.patches.youtube.layout.oldqualitylayout.fingerprints.QualityMenuViewInflateFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.builder.instruction.BuilderInstruction21t +import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction @Patch @Dependencies([IntegrationsPatch::class]) @@ -26,35 +22,23 @@ import org.jf.dexlib2.builder.instruction.BuilderInstruction21t @OldQualityLayoutCompatibility @Version("0.0.1") class OldQualityLayoutPatch : BytecodePatch( - listOf( - OldQualityParentFingerprint - ) + listOf(QualityMenuViewInflateFingerprint) ) { override fun execute(data: BytecodeData): PatchResult { - OldQualityFingerprint.resolve(data, OldQualityParentFingerprint.result!!.classDef) - val result = OldQualityFingerprint.result - ?: return PatchResultError("Required parent method could not be found.") + val inflateFingerprintResult = QualityMenuViewInflateFingerprint.result!! + val method = inflateFingerprintResult.mutableMethod + val instructions = method.implementation!!.instructions - val implementation = result.mutableMethod.implementation!! + // at this index the listener is added to the list view + val listenerInvokeRegister = instructions.size - 1 - 1 - // use this register because it is free - val containerRegister = 5 + // get the register which stores the quality menu list view + val onItemClickViewRegister = (instructions[listenerInvokeRegister] as FiveRegisterInstruction).registerC - // if useOldStyleQualitySettings == true, jump over all instructions - implementation.addInstruction( - 4, BuilderInstruction21t( - Opcode.IF_NEZ, - containerRegister, - implementation.instructions[result.patternScanResult!!.endIndex].location.labels.first() - ) - ) - - // insert the new condition - result.mutableMethod.addInstructions( - 0, """ - invoke-static { }, Lapp/revanced/integrations/patches/OldStyleQualityPatch;->useOldStyleQualitySettings()Z - move-result v$containerRegister - """ + // insert the integrations method + method.addInstruction( + listenerInvokeRegister, // insert the integrations instructions right before the listener + "invoke-static { v$onItemClickViewRegister }, Lapp/revanced/integrations/patches/OldQualityLayoutPatch;->showOldQualityMenu(Landroid/widget/ListView;)V" ) return PatchResultSuccess()