Skip to content

Commit

Permalink
feat(youtube): support version 18.16.37
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed May 2, 2023
1 parent 795f7d3 commit 8beb5ea
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Expand Up @@ -7,5 +7,17 @@ import org.jf.dexlib2.Opcode

object MiniPlayerOverrideFingerprint : MethodFingerprint(
"Z", AccessFlags.STATIC or AccessFlags.PUBLIC,
opcodes = listOf(Opcode.RETURN), // anchor to insert the instruction
listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.CONST_4,
Opcode.IF_EQ,
Opcode.CONST_4,
Opcode.IF_EQ,
Opcode.CONST_4, // override this value
Opcode.RETURN,
Opcode.CONST_4, // override this value
Opcode.RETURN
),
)
@@ -1,13 +1,7 @@
package app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags


object MiniPlayerOverrideParentFingerprint : MethodFingerprint(
returnType = "L",
access = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L"),
strings = listOf("PLAYBACK_RATE_MENU_BOTTOM_SHEET_FRAGMENT")
strings = listOf("Possible Context wrapper loop - chain of wrappers larger than 10000")
)
Expand Up @@ -10,6 +10,7 @@ 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.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
Expand All @@ -20,6 +21,7 @@ import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMi
import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.*
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction

@Patch
Expand Down Expand Up @@ -68,10 +70,28 @@ class TabletMiniPlayerPatch : BytecodePatch(
MiniPlayerOverrideParentFingerprint.result?.let {
if (!MiniPlayerOverrideFingerprint.resolve(context, it.classDef))
throw MiniPlayerOverrideFingerprint.toErrorResult()

MiniPlayerOverrideFingerprint.addProxyCall()
} ?: return MiniPlayerOverrideParentFingerprint.toErrorResult()

/*
* Override every return instruction with the proxy call.
*/
MiniPlayerOverrideFingerprint.result!!.mutableMethod.apply {
implementation!!.let { implementation ->
val returnIndices = implementation.instructions
.withIndex()
.filter { (_, instruction) -> instruction.opcode == Opcode.RETURN }
.map { (index, _) -> index }

if (returnIndices.isEmpty()) throw PatchResultError("No return instructions found.")

// This method clobbers register p0 to return the value, calculate to override.
val returnedRegister = implementation.registerCount - parameters.size

// Hook the returned register on every return instruction.
returnIndices.forEach { index -> insertOverride(index, returnedRegister) }
}
}

/*
* Size check return value override.
*/
Expand Down

0 comments on commit 8beb5ea

Please sign in to comment.