forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube): Change fingerprints to support a wider range of target …
…versions
- Loading branch information
1 parent
979565e
commit 8a09174
Showing
2 changed files
with
44 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 37 additions & 42 deletions
79
...tlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,49 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture | ||
|
||
import app.revanced.patcher.Fingerprint | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/FixBackToExitGesturePatch;" | ||
|
||
internal val fixBackToExitGesturePatch = bytecodePatch( | ||
description = "Fixes the swipe back to exit gesture.", | ||
) { | ||
|
||
execute { | ||
/** | ||
* Inject a call to a method from the extension. | ||
* | ||
* @param targetMethod The target method to call. | ||
*/ | ||
fun Fingerprint.injectCall(targetMethod: ExtensionMethod) = method.addInstruction( | ||
patternMatch!!.endIndex, | ||
targetMethod.toString(), | ||
) | ||
|
||
mapOf( | ||
recyclerViewTopScrollingFingerprint.also { | ||
it.match(recyclerViewTopScrollingParentFingerprint.originalClassDef) | ||
} to ExtensionMethod( | ||
methodName = "onTopView", | ||
), | ||
recyclerViewScrollingFingerprint to ExtensionMethod( | ||
methodName = "onScrollingViews", | ||
), | ||
onBackPressedFingerprint to ExtensionMethod( | ||
"p0", | ||
"onBackPressed", | ||
"Landroid/app/Activity;", | ||
), | ||
).forEach { (fingerprint, target) -> fingerprint.injectCall(target) } | ||
} | ||
} | ||
recyclerViewTopScrollingFingerprint.match(recyclerViewTopScrollingParentFingerprint.originalClassDef) | ||
.let { | ||
it.method.addInstruction( | ||
it.patternMatch!!.endIndex, | ||
"invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->onTopView()V" | ||
) | ||
} | ||
|
||
/** | ||
* A reference to a method from the extension for [fixBackToExitGesturePatch]. | ||
* | ||
* @param register The method registers. | ||
* @param methodName The method name. | ||
* @param parameterTypes The parameters of the method. | ||
*/ | ||
private class ExtensionMethod( | ||
val register: String = "", | ||
val methodName: String, | ||
val parameterTypes: String = "", | ||
) { | ||
override fun toString() = | ||
"invoke-static {$register}, Lapp/revanced/extension/youtube/patches/FixBackToExitGesturePatch;->$methodName($parameterTypes)V" | ||
scrollPositionFingerprint.let { | ||
navigate(it.originalMethod) | ||
.to(it.patternMatch!!.startIndex + 1) | ||
.stop().apply { | ||
val index = indexOfFirstInstructionOrThrow { | ||
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.definingClass == | ||
"Landroid/support/v7/widget/RecyclerView;" | ||
} | ||
|
||
addInstruction( | ||
index, | ||
"invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->onScrollingViews()V" | ||
) | ||
} | ||
|
||
} | ||
|
||
onBackPressedFingerprint.let { | ||
it.method.addInstruction( | ||
it.patternMatch!!.endIndex, | ||
"invoke-static { p0 }, $EXTENSION_CLASS_DESCRIPTOR->onBackPressed(Landroid/app/Activity;)V" | ||
) | ||
} | ||
} | ||
} |