generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...nced/patches/youtube/layout/tabletminiplayer/annotations/TabletMiniPlayerCompatibility.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.26.35", "17.29.34") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class TabletMiniPlayerCompatibility |
41 changes: 41 additions & 0 deletions
41
...youtube/layout/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.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.tabletminiplayer.annotations.TabletMiniPlayerCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("mini-player-dimensions-calculator-fingerprint") | ||
@MatchingMethod( | ||
"Lkkr;", "pM" | ||
) | ||
@FuzzyPatternScanMethod(2) // TODO: Find a good threshold value | ||
@TabletMiniPlayerCompatibility | ||
@Version("0.0.1") | ||
object MiniPlayerDimensionsCalculatorFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
listOf("L"), | ||
listOf( | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.IGET_OBJECT, | ||
Opcode.IGET_OBJECT, | ||
Opcode.MUL_FLOAT, | ||
Opcode.INVOKE_INTERFACE, | ||
Opcode.IGET_BOOLEAN, | ||
Opcode.CONST_4, | ||
Opcode.IF_EQZ, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_NEZ, | ||
Opcode.FLOAT_TO_DOUBLE, | ||
Opcode.CONST_WIDE_HIGH16, | ||
Opcode.CMPL_DOUBLE, | ||
) | ||
) |
21 changes: 21 additions & 0 deletions
21
...ced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.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.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("mini-player-override-fingerprint") | ||
@MatchingMethod( | ||
"Lkkr;", "j" | ||
) | ||
@TabletMiniPlayerCompatibility | ||
@Version("0.0.1") | ||
object MiniPlayerOverrideFingerprint : MethodFingerprint( | ||
"Z", AccessFlags.STATIC or AccessFlags.PUBLIC ,null, | ||
listOf(Opcode.RETURN), // anchor to insert the instruction | ||
) |
21 changes: 21 additions & 0 deletions
21
...es/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideNoContextFingerprint.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.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.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("mini-player-override-no-context-fingerprint") | ||
@MatchingMethod( | ||
"Lkkr;", "k" | ||
) | ||
@TabletMiniPlayerCompatibility | ||
@Version("0.0.1") | ||
object MiniPlayerOverrideNoContextFingerprint : MethodFingerprint( | ||
"Z", AccessFlags.FINAL or AccessFlags.PRIVATE ,null, | ||
listOf(Opcode.RETURN), // anchor to insert the instruction | ||
) |
37 changes: 37 additions & 0 deletions
37
...utube/layout/tabletminiplayer/fingerprints/MiniPlayerResponseModelSizeCheckFingerprint.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.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.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("mini-player-response-model-size-check-fingerprint") | ||
@MatchingMethod( | ||
"Lenv;", "a" | ||
) | ||
@TabletMiniPlayerCompatibility | ||
@Version("0.0.1") | ||
object MiniPlayerResponseModelSizeCheckFingerprint : MethodFingerprint( | ||
"L", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
listOf("L", "L"), | ||
listOf( | ||
Opcode.OR_INT_LIT8, | ||
Opcode.IPUT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.RETURN_OBJECT, | ||
Opcode.RETURN_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.CHECK_CAST, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_NEZ, | ||
), | ||
null | ||
) |
92 changes: 92 additions & 0 deletions
92
...otlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package app.revanced.patches.youtube.layout.tabletminiplayer.patch | ||
|
||
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.impl.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerDimensionsCalculatorFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideNoContextFingerprint | ||
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerResponseModelSizeCheckFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class]) | ||
@Name("tablet-mini-player") | ||
@Description("Enables the tablet mini player layout.") | ||
@TabletMiniPlayerCompatibility | ||
@Version("0.0.1") | ||
class TabletMiniPlayerPatch : BytecodePatch( | ||
listOf( | ||
MiniPlayerDimensionsCalculatorFingerprint, | ||
MiniPlayerResponseModelSizeCheckFingerprint | ||
) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
// first resolve the fingerprints via the parent fingerprint | ||
val miniPlayerClass = MiniPlayerDimensionsCalculatorFingerprint.result!!.classDef | ||
|
||
/* | ||
* no context parameter method | ||
*/ | ||
MiniPlayerOverrideNoContextFingerprint.resolve(data, miniPlayerClass) | ||
val (method, _, parameterRegister) = MiniPlayerOverrideNoContextFingerprint.addProxyCall() | ||
// - 1 means to insert before the return instruction | ||
val secondInsertIndex = method.implementation!!.instructions.size - 1 | ||
method.insertOverride(secondInsertIndex, parameterRegister /** same register used to return **/) | ||
|
||
/* | ||
* method with context parameter | ||
*/ | ||
MiniPlayerOverrideFingerprint.resolve(data, miniPlayerClass) | ||
val (_, _, _) = MiniPlayerOverrideFingerprint.addProxyCall() | ||
|
||
/* | ||
* size check return value override | ||
*/ | ||
val (_, _, _) = MiniPlayerResponseModelSizeCheckFingerprint.addProxyCall() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
// helper methods | ||
private companion object { | ||
fun MethodFingerprint.addProxyCall(): Triple<MutableMethod, Int, Int> { | ||
val (method, scanIndex, parameterRegister) = this.unwrap() | ||
method.insertOverride(scanIndex, parameterRegister) | ||
|
||
return Triple(method, scanIndex, parameterRegister) | ||
} | ||
|
||
fun MutableMethod.insertOverride(index: Int, overrideRegister: Int) { | ||
this.addInstructions( | ||
index, | ||
""" | ||
invoke-static {v$overrideRegister}, Lapp/revanced/integrations/patches/TabletMiniPlayerOverridePatch;->getTabletMiniPlayerOverride(Z)Z | ||
move-result v$overrideRegister | ||
""" | ||
) | ||
} | ||
|
||
fun MethodFingerprint.unwrap(): Triple<MutableMethod, Int, Int> { | ||
val result = this.result!! | ||
val scanIndex = result.patternScanResult!!.endIndex | ||
val method = result.mutableMethod | ||
val instructions = method.implementation!!.instructions | ||
val parameterRegister = (instructions[scanIndex] as OneRegisterInstruction).registerA | ||
|
||
return Triple(method, scanIndex, parameterRegister) | ||
} | ||
} | ||
} |