Skip to content

Commit

Permalink
fix(youtube/general-ads): restore swipe back to exit gesture (#1405)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
0xrxL and oSumAtrIX committed Dec 31, 2022
1 parent bf982e8 commit 2440587
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.ad.general.bytecode.fingerprints.ReelConstructorFingerprint
import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.patch.FixBackToExitGesturePatch
import app.revanced.patches.youtube.misc.fix.verticalscroll.patch.VerticalScrollPatch
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.instruction.formats.Instruction35c


@Patch
@DependsOn([GeneralAdsResourcePatch::class, VerticalScrollPatch::class])
@DependsOn([GeneralAdsResourcePatch::class, VerticalScrollPatch::class, FixBackToExitGesturePatch::class])
@Name("general-ads")
@Description("Removes general ads.")
@GeneralAdsCompatibility
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.annotation

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.49.37")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class FixBackToExitGestureCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object OnBackPressedFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.RETURN_VOID
),
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("WatchWhileActivity;")
&& methodDef.name == "onBackPressed"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object RecyclerViewScrollingFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.CHECK_CAST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_LEZ,
Opcode.IGET_OBJECT,
Opcode.CONST_4,
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.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 RecyclerViewTopScrollingFingerprint : MethodFingerprint(
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), listOf(
Opcode.IGET_OBJECT,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.CONST_4,
Opcode.INVOKE_VIRTUAL,
Opcode.GOTO,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object RecyclerViewTopScrollingParentFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.CONST_16,
Opcode.INVOKE_VIRTUAL,
Opcode.NEW_INSTANCE
),
customFingerprint = { methodDef ->
methodDef.name == "<init>"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.patch

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.addInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.annotation.FixBackToExitGestureCompatibility
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.OnBackPressedFingerprint
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewScrollingFingerprint
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewTopScrollingFingerprint
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewTopScrollingParentFingerprint

@Description("Fixes the swipe back to exit gesture.")
@FixBackToExitGestureCompatibility
@Version("0.0.1")
class FixBackToExitGesturePatch : BytecodePatch(
listOf(
RecyclerViewTopScrollingParentFingerprint,
RecyclerViewScrollingFingerprint,
OnBackPressedFingerprint,
)
) {
override fun execute(context: BytecodeContext): PatchResult {
RecyclerViewTopScrollingFingerprint.apply {
resolve(
context,
RecyclerViewTopScrollingParentFingerprint.result?.classDef
?: return RecyclerViewTopScrollingParentFingerprint.toErrorResult()
)
}

mapOf(
RecyclerViewTopScrollingFingerprint to IntegrationsMethod(
methodName = "onTopView"
),
RecyclerViewScrollingFingerprint to IntegrationsMethod(
methodName = "onScrollingViews"
),
OnBackPressedFingerprint to IntegrationsMethod(
"p0", "onBackPressed", "Lcom/google/android/apps/youtube/app/watchwhile/WatchWhileActivity;"
)
).forEach { (fingerprint, target) ->
try {
fingerprint.injectCall(target)
} catch (error: PatchResultError) {
return error
}
}

return PatchResultSuccess()
}

private companion object {
/**
* A reference to a method from the integrations for [FixBackToExitGesturePatch].
*
* @param register The method registers.
* @param methodName The method name.
* @param parameterTypes The parameters of the method.
*/
data class IntegrationsMethod(
val register: String = "", val methodName: String, val parameterTypes: String = ""
) {
override fun toString() =
"invoke-static {$register}, Lapp/revanced/integrations/patches/FixBackToExitGesturePatch;->$methodName($parameterTypes)V"
}

/**
* Inject a call to a method from the integrations.
*
* @param targetMethod The target method to call.
*/
fun MethodFingerprint.injectCall(targetMethod: IntegrationsMethod) = result?.apply {
mutableMethod.addInstruction(
scanResult.patternScanResult!!.endIndex, targetMethod.toString()
)
} ?: throw this.toErrorResult()
}
}

0 comments on commit 2440587

Please sign in to comment.