fix: default-video-quality patch crashing (#227)

This commit is contained in:
Canny1913 2022-07-26 20:33:02 +03:00 committed by GitHub
parent 2b774ac3f5
commit 379327a6b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 22 deletions

View file

@ -5,7 +5,7 @@ import app.revanced.patcher.annotation.Package
@Compatibility( @Compatibility(
[Package( [Package(
"com.google.android.youtube", arrayOf("17.22.36", "17.24.35", "17.26.35", "17.27.39") "com.google.android.youtube", arrayOf("17.22.36", "17.24.35", "17.26.35", "17.27.39", "17.28.34", "17.29.34")
)] )]
) )
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)

View file

@ -4,18 +4,18 @@ package app.revanced.patches.youtube.misc.quality.fingerprints
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
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.annotation.DirectPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.quality.annotations.DefaultVideoQualityCompatibility import app.revanced.patches.youtube.misc.quality.annotations.DefaultVideoQualityCompatibility
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
@Name("video-quality-setter-fingerprint") @Name("video-quality-setter-fingerprint")
@MatchingMethod( @MatchingMethod(
"Lkec", "a" "Lkec;", "a"
) )
@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. @DirectPatternScanMethod
@DefaultVideoQualityCompatibility @DefaultVideoQualityCompatibility
@Version("0.0.1") @Version("0.0.1")
object VideoQualitySetterFingerprint : MethodFingerprint( object VideoQualitySetterFingerprint : MethodFingerprint(

View file

@ -17,26 +17,22 @@ import app.revanced.patches.youtube.misc.quality.annotations.DefaultVideoQuality
import app.revanced.patches.youtube.misc.quality.fingerprints.VideoQualityReferenceFingerprint import app.revanced.patches.youtube.misc.quality.fingerprints.VideoQualityReferenceFingerprint
import app.revanced.patches.youtube.misc.quality.fingerprints.VideoQualitySetterFingerprint import app.revanced.patches.youtube.misc.quality.fingerprints.VideoQualitySetterFingerprint
import app.revanced.patches.youtube.misc.quality.fingerprints.VideoUserQualityChangeFingerprint import app.revanced.patches.youtube.misc.quality.fingerprints.VideoUserQualityChangeFingerprint
import app.revanced.patches.youtube.misc.videoid.fingerprint.VideoIdFingerprint import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference import org.jf.dexlib2.iface.reference.FieldReference
@Dependencies( @Patch
dependencies = [IntegrationsPatch::class] @Dependencies([IntegrationsPatch::class, VideoIdPatch::class])
)
@Name("default-video-quality") @Name("default-video-quality")
@Description("Adds the ability to select preferred video quality.") @Description("Adds the ability to select preferred video quality.")
@DefaultVideoQualityCompatibility @DefaultVideoQualityCompatibility
@Version("0.0.1") @Version("0.0.1")
class DefaultVideoQualityPatch : BytecodePatch( class DefaultVideoQualityPatch : BytecodePatch(
listOf( listOf(
VideoQualitySetterFingerprint, VideoQualitySetterFingerprint
VideoIdFingerprint
) )
) { ) {
override fun execute(data: BytecodeData): PatchResult { override fun execute(data: BytecodeData): PatchResult {
val offset = 4
val setterMethod = VideoQualitySetterFingerprint.result!! val setterMethod = VideoQualitySetterFingerprint.result!!
VideoUserQualityChangeFingerprint.resolve(data, setterMethod.classDef) VideoUserQualityChangeFingerprint.resolve(data, setterMethod.classDef)
@ -48,6 +44,8 @@ class DefaultVideoQualityPatch : BytecodePatch(
(method.implementation!!.instructions.elementAt(0) as ReferenceInstruction).reference as FieldReference (method.implementation!!.instructions.elementAt(0) as ReferenceInstruction).reference as FieldReference
} }
VideoIdPatch.injectCall("Lapp/revanced/integrations/patches/VideoQualityPatch;->newVideoStarted(Ljava/lang/String;)V")
val qIndexMethodName = val qIndexMethodName =
data.classes.single { it.type == qualityFieldReference.type }.methods.single { it.parameterTypes.first() == "I" }.name data.classes.single { it.type == qualityFieldReference.type }.methods.single { it.parameterTypes.first() == "I" }.name
@ -61,15 +59,6 @@ class DefaultVideoQualityPatch : BytecodePatch(
""", """,
) )
val newVideoMethod = VideoIdFingerprint.result!!
val newVideoIndex = newVideoMethod.patternScanResult!!.endIndex + offset
newVideoMethod.mutableMethod.addInstructions(
newVideoIndex, """
const/4 v6, 0x1
invoke-static {v6}, Lapp/revanced/integrations/utils/ReVancedUtils;->setNewVideo(Z)V
"""
)
userQualityMethod.mutableMethod.addInstruction( userQualityMethod.mutableMethod.addInstruction(
0, 0,
"invoke-static {p3}, Lapp/revanced/integrations/patches/VideoQualityPatch;->userChangedQuality(I)V" "invoke-static {p3}, Lapp/revanced/integrations/patches/VideoQualityPatch;->userChangedQuality(I)V"