From 003a400ce41ff543fb5484c576f5ec2df0a87273 Mon Sep 17 00:00:00 2001 From: 0xrxL <120989892+0xrxL@users.noreply.github.com> Date: Mon, 26 Dec 2022 18:33:18 +0100 Subject: [PATCH] fix(youtube/general-ads): don't early return when not necessary (#1353) --- .../CanScrollVerticallyFingerprint.kt | 7 ++++-- .../patch/VerticalScrollPatch.kt | 22 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt index 1f8792482..a0238430a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt @@ -7,6 +7,9 @@ import org.jf.dexlib2.Opcode object CanScrollVerticallyFingerprint : MethodFingerprint( "Z", parameters = emptyList(), - opcodes = listOf(Opcode.INSTANCE_OF), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + ), customFingerprint = { methodDef -> methodDef.definingClass.endsWith("SwipeRefreshLayout;") } -) \ No newline at end of file +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt index 3619ea653..f78eb494a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt @@ -4,12 +4,14 @@ import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patches.youtube.misc.fix.verticalscroll.annotations.VerticalScrollCompatibility import app.revanced.patches.youtube.misc.fix.verticalscroll.fingerprints.CanScrollVerticallyFingerprint +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Description("Fixes issues with scrolling on the home screen when the first component is of type EmptyComponent.") @VerticalScrollCompatibility @@ -20,13 +22,17 @@ class VerticalScrollPatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { val result = CanScrollVerticallyFingerprint.result ?: return CanScrollVerticallyFingerprint.toErrorResult() - result.mutableMethod.addInstructions( - 0, - """ - const/4 v0, 0x0 - return v0 - """ - ) + with(result) { + val method = mutableMethod + + val moveResultIndex = scanResult.patternScanResult!!.endIndex + val moveResultRegister = (method.instruction(moveResultIndex) as OneRegisterInstruction).registerA + + method.addInstruction( + moveResultIndex + 1, + "const/4 v$moveResultRegister, 0x0" + ) + } return PatchResultSuccess() }