Skip to content

Commit

Permalink
feat(youtube): support version 18.08.37
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Apr 16, 2023
1 parent b0834fa commit 4f4ceab
Show file tree
Hide file tree
Showing 39 changed files with 361 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
Expand All @@ -20,6 +21,7 @@ import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutC
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.iface.reference.MethodReference
Expand Down Expand Up @@ -66,12 +68,15 @@ class HideAutoplayButtonPatch : BytecodePatch(

val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction

// can be clobbered because this register is overwritten after the injected code
val clobberRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA

addInstructions(
insertIndex,
"""
invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z
move-result v11
if-eqz v11, :hidden
move-result v$clobberRegister
if-eqz v$clobberRegister, :hidden
""", listOf(ExternalLabel("hidden", jumpInstruction))
)
} ?: return LayoutConstructorFingerprint.toErrorResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import app.revanced.patcher.annotation.Package
@Compatibility(
[Package(
"com.google.android.youtube", arrayOf(
"17.49.37",
"17.49.37",
"18.03.36",
"18.03.42",
"18.04.35",
"18.04.41",
"18.05.32",
"18.05.35",
"18.05.40"
"18.05.40",
"18.08.37"
)
)]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import org.jf.dexlib2.iface.instruction.WideLiteralInstruction

object CrowdfundingBoxFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST_4,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IPUT_OBJECT,
Opcode.CONST,
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any { instruction ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.patches.youtube.layout.hide.crowdfundingbox.bytecode.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
Expand All @@ -15,7 +16,7 @@ import app.revanced.patches.youtube.layout.hide.crowdfundingbox.annotations.Crow
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.bytecode.fingerprints.CrowdfundingBoxFingerprint
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.resource.patch.CrowdfundingBoxResourcePatch
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction

@Patch
@DependsOn([IntegrationsPatch::class, CrowdfundingBoxResourcePatch::class])
Expand All @@ -29,18 +30,20 @@ class CrowdfundingBoxPatch : BytecodePatch(
)
) {
override fun execute(context: BytecodeContext): PatchResult {
val crowdfundingBoxResult = CrowdfundingBoxFingerprint.result!!
val crowdfundingBoxMethod = crowdfundingBoxResult.mutableMethod
CrowdfundingBoxFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val objectRegister = (instruction(insertIndex) as TwoRegisterInstruction).registerA

val moveResultObjectIndex =
crowdfundingBoxResult.scanResult.patternScanResult!!.endIndex - 2

crowdfundingBoxMethod.addInstruction(
moveResultObjectIndex + 1, """
invoke-static {v${(crowdfundingBoxMethod.instruction(moveResultObjectIndex) as OneRegisterInstruction).registerA}}, Lapp/revanced/integrations/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V
"""
)
addInstruction(insertIndex, "invoke-static {v$objectRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR")
}
} ?: return CrowdfundingBoxFingerprint.toErrorResult()

return PatchResultSuccess()
}

private companion object {
const val INTEGRATIONS_METHOD_DESCRIPTOR =
"Lapp/revanced/integrations/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ package app.revanced.patches.youtube.layout.returnyoutubedislike.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf(
"17.49.37",
"18.03.36",
"18.03.42",
"18.04.35",
"18.04.41",
"18.05.32",
"18.05.35",
"18.05.40"
)
)]
)
@Compatibility([Package("com.google.android.youtube", arrayOf("18.08.37"))])
@Target(AnnotationTarget.CLASS)
internal annotation class ReturnYouTubeDislikeCompatibility
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints

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

object DislikeFingerprint : MethodFingerprint(
"V",
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
strings = listOf("like/dislike")
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints

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


@FuzzyPatternScanMethod(2)
object LikeFingerprint : MethodFingerprint(
"V",
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
strings = listOf("like/like")
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints

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

object RemoveLikeFingerprint : MethodFingerprint(
"V",
AccessFlags.PROTECTED or AccessFlags.CONSTRUCTOR,
strings = listOf("like/removelike")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints


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

object TextComponentConstructorFingerprint : MethodFingerprint(
access = AccessFlags.CONSTRUCTOR or AccessFlags.PRIVATE,
strings = listOf("TextComponent")
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints


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

object TextReferenceFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.INVOKE_STATIC_RANGE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_DIRECT,
Opcode.INVOKE_VIRTUAL
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints

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

object TextReferenceParamFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.MOVE_OBJECT,
Opcode.MOVE_OBJECT_FROM16 // the first occurrence of this instruction uses the register for the text object
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction

@Patch
@DependsOn(
Expand All @@ -42,7 +44,7 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Version("0.0.1")
class ReturnYouTubeDislikePatch : BytecodePatch(
listOf(
TextComponentSpecParentFingerprint,
TextComponentConstructorFingerprint,
ShortsTextComponentParentFingerprint,
LikeFingerprint,
DislikeFingerprint,
Expand Down Expand Up @@ -78,27 +80,37 @@ class ReturnYouTubeDislikePatch : BytecodePatch(

// region Hook components

TextComponentFingerprint.also { it.resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) }
.result?.let {
with(it.mutableMethod) {
val createComponentMethod = this

val conversionContextParam = 5
val textRefParam = createComponentMethod.parameters.size - 2
// Insert index must be 0, otherwise UI does not updated correctly in some situations
// such as switching from full screen or when using previous/next overlay buttons.
val insertIndex = 0

createComponentMethod.addInstructions(
insertIndex,
"""
move-object/from16 v7, p$conversionContextParam
move-object/from16 v8, p$textRefParam
invoke-static {v7, v8}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V
"""
)
}
} ?: return TextComponentFingerprint.toErrorResult()
TextReferenceFingerprint.also {
it.resolve(
context,
TextComponentConstructorFingerprint.result!!.classDef
)
}.result?.let { result ->
val moveTextRefParamInstructionIndex = TextReferenceParamFingerprint.also {
if (!TextReferenceParamFingerprint.resolve(context, result.method, result.classDef))
return TextReferenceParamFingerprint.toErrorResult()
}.result!!.scanResult.patternScanResult!!.endIndex

result.mutableMethod.apply {
val insertIndex = result.scanResult.patternScanResult!!.endIndex

val atomicReferenceInstruction = (instruction(insertIndex - 1) as FiveRegisterInstruction)
val conversionContextParam = atomicReferenceInstruction.registerC
val textRefParam = (instruction(moveTextRefParamInstructionIndex) as TwoRegisterInstruction).registerA

// Overwritten after injected code, which is why it can be used.
val clobberRegister = atomicReferenceInstruction.registerD

addInstructions(
insertIndex,
"""
# required instruction, otherwise register might be out of range
move-object/from16 v$clobberRegister, v$textRefParam
invoke-static {v$clobberRegister, v$conversionContextParam}, $ON_COMPONENT_CREATED_DESCRIPTOR
"""
)
}
} ?: return TextReferenceFingerprint.toErrorResult()

ShortsTextComponentParentFingerprint.result?.let {
context
Expand Down Expand Up @@ -138,6 +150,9 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
const val INTEGRATIONS_PATCH_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;"

const val ON_COMPONENT_CREATED_DESCRIPTOR =
"$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V"

private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class SpoofAppVersionPatch : BytecodePatch(
SpoofAppVersionFingerprint
)
) {
companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofAppVersionPatch"
}

override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
Expand Down Expand Up @@ -61,4 +57,8 @@ class SpoofAppVersionPatch : BytecodePatch(

return PatchResultSuccess()
}

private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/SpoofAppVersionPatch"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode


@FuzzyPatternScanMethod(2) // TODO: Find a good threshold value
@FuzzyPatternScanMethod(2)
object MiniPlayerDimensionsCalculatorFingerprint : MethodFingerprint(
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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("VIDEO_QUALITIES_QUICK_MENU_BOTTOM_SHEET_FRAGMENT")
)
Loading

0 comments on commit 4f4ceab

Please sign in to comment.