Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube): Support version 19.09.38, 19.10.39 and 19.11.43 #2971

Merged
merged 12 commits into from
Apr 20, 2024
Merged
4 changes: 3 additions & 1 deletion api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ public final class app/revanced/patches/shared/misc/mapping/ResourceMappingPatch
public static final field INSTANCE Lapp/revanced/patches/shared/misc/mapping/ResourceMappingPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
public final fun get (Ljava/lang/String;Ljava/lang/String;)J
}

public final class app/revanced/patches/shared/misc/mapping/ResourceMappingPatch$ResourceElement {
Expand Down Expand Up @@ -1846,11 +1847,12 @@ public final class app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPat

public final class app/revanced/util/BytecodeUtilsKt {
public static final fun containsWideLiteralInstructionValue (Lcom/android/tools/smali/dexlib2/iface/Method;J)Z
public static final fun findIndexForIdResource (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I
public static final fun findMutableMethodOf (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lcom/android/tools/smali/dexlib2/iface/Method;)Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;
public static final fun getException (Lapp/revanced/patcher/fingerprint/MethodFingerprint;)Lapp/revanced/patcher/patch/PatchException;
public static final fun indexOfFirstInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;Lkotlin/jvm/functions/Function1;)I
public static final fun indexOfFirstWideLiteralInstructionValue (Lcom/android/tools/smali/dexlib2/iface/Method;J)I
public static final fun indexOfIdResource (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I
public static final fun indexOfIdResourceOrThrow (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I
public static final fun injectHideViewCall (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;IILjava/lang/String;Ljava/lang/String;)V
public static final fun resultOrThrow (Lapp/revanced/patcher/fingerprint/MethodFingerprint;)Lapp/revanced/patcher/fingerprint/MethodFingerprintResult;
public static final fun returnEarly (Ljava/util/List;Z)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

object ResourceMappingPatch : ResourcePatch() {
internal lateinit var resourceMappings: List<ResourceElement>
private set
private val resourceMappings = Collections.synchronizedList(mutableListOf<ResourceElement>())

private val THREAD_COUNT = Runtime.getRuntime().availableProcessors()
private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT)

override fun execute(context: ResourceContext) {
// save the file in memory to concurrently read from
// sSve the file in memory to concurrently read from it.
val resourceXmlFile = context.get("res/values/public.xml").readBytes()

// create a synchronized list to store the resource mappings
val mappings = Collections.synchronizedList(mutableListOf<ResourceElement>())

for (threadIndex in 0 until THREAD_COUNT) {
threadPoolExecutor.execute thread@{
context.xmlEditor[resourceXmlFile.inputStream()].use { editor ->
Expand All @@ -33,7 +29,7 @@ object ResourceMappingPatch : ResourcePatch() {
val batchStart = jobSize * threadIndex
val batchEnd = jobSize * (threadIndex + 1)
element@ for (i in batchStart until batchEnd) {
// make sure to not go out of bounds when rounding errors occur at calculating the jobSize
// Prevent out of bounds.
if (i >= resourcesLength) return@thread

val node = resources.item(i)
Expand All @@ -46,18 +42,18 @@ object ResourceMappingPatch : ResourcePatch() {

val id = node.getAttribute("id").substring(2).toLong(16)

mappings.add(ResourceElement(typeAttribute, nameAttribute, id))
resourceMappings.add(ResourceElement(typeAttribute, nameAttribute, id))
}
}
}
}

threadPoolExecutor
.also { it.shutdown() }
.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS)

resourceMappings = mappings
threadPoolExecutor.also { it.shutdown() }.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS)
}

operator fun get(type: String, name: String) = resourceMappings.first {
it.type == type && it.name == name
}.id

data class ResourceElement(val type: String, val name: String, val id: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ object PremiumNavbarTabResourcePatch : ResourcePatch() {
internal var premiumTabId = -1L

override fun execute(context: ResourceContext) {
premiumTabId = ResourceMappingPatch.resourceMappings.single {
it.type == "id" && it.name == "premium_tab"
}.id
premiumTabId = ResourceMappingPatch["id", "premium_tab"]

showBottomNavigationItemsTextId = ResourceMappingPatch.resourceMappings.single {
it.type == "bool" && it.name == "show_bottom_navigation_items_text"
}.id
showBottomNavigationItemsTextId = ResourceMappingPatch[
"bool",
"show_bottom_navigation_items_text",
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
LithoFilterPatch::class,
SettingsPatch::class,
ResourceMappingPatch::class,
AddResourcesPatch::class
]
AddResourcesPatch::class,
],
)
object HideAdsResourcePatch : ResourcePatch() {
private const val FILTER_CLASS_DESCRIPTOR =
Expand All @@ -35,11 +35,11 @@ object HideAdsResourcePatch : ResourcePatch() {
SwitchPreference("revanced_hide_products_banner"),
SwitchPreference("revanced_hide_shopping_links"),
SwitchPreference("revanced_hide_web_search_results"),
SwitchPreference("revanced_hide_merchandise_banners")
SwitchPreference("revanced_hide_merchandise_banners"),
)

LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)

adAttributionId = ResourceMappingPatch.resourceMappings.single { it.name == "ad_attribution" }.id
adAttributionId = ResourceMappingPatch["id", "ad_attribution"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import app.revanced.patches.youtube.video.information.VideoInformationPatch
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import app.revanced.util.resultOrThrow
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
dependencies = [
IntegrationsPatch::class,
PlayerTypeHookPatch::class,
SwipeControlsResourcePatch::class
SwipeControlsResourcePatch::class,
],
compatiblePackages = [
CompatiblePackage(
Expand All @@ -42,17 +42,22 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
]
)
]
"19.09.38",
"19.10.39",
"19.11.43", // 19.12.x has an issue with opening YT using external links,
// and the app then crashes if double tap to skip forward/back is immediately used.
// The stack trace shows a call coming from integrations SwipeController,
// but it may be a bug in YT itself as other target versions do not have this issue.
],
),
],
)
@Suppress("unused")
object SwipeControlsBytecodePatch : BytecodePatch(
setOf(
MainActivityFingerprint,
SwipeControlsHostActivityFingerprint
)
SwipeControlsHostActivityFingerprint,
),
) {
override fun execute(context: BytecodeContext) {
val wrapperClass = SwipeControlsHostActivityFingerprint.result!!.mutableClass
Expand All @@ -74,9 +79,9 @@ object SwipeControlsBytecodePatch : BytecodePatch(
accessFlags and AccessFlags.FINAL.value.inv(),
annotations,
hiddenApiRestrictions,
implementation
implementation,
).toMutable()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import app.revanced.util.exception
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint
import app.revanced.util.exception
import app.revanced.util.findIndexForIdResource
import app.revanced.util.indexOfIdResourceOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
Expand All @@ -27,7 +27,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
IntegrationsPatch::class,
SettingsPatch::class,
ResourceMappingPatch::class,
AddResourcesPatch::class
AddResourcesPatch::class,
],
compatiblePackages = [
CompatiblePackage(
Expand All @@ -49,27 +49,29 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
]
)
]
"19.09.38",
"19.10.39",
"19.11.43",
],
),
],
)
@Suppress("unused")
object HideAutoplayButtonPatch : BytecodePatch(
setOf(LayoutConstructorFingerprint)
setOf(LayoutConstructorFingerprint),
) {
override fun execute(context: BytecodeContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
SwitchPreference("revanced_hide_autoplay_button")
SwitchPreference("revanced_hide_autoplay_button"),
)

LayoutConstructorFingerprint.result?.mutableMethod?.apply {
val layoutGenMethodInstructions = implementation!!.instructions

// resolve the offsets of where to insert the branch instructions and ...
val insertIndex = findIndexForIdResource("autonav_preview_stub")
val insertIndex = indexOfIdResourceOrThrow("autonav_preview_stub")

// where to branch away
val branchIndex =
Expand All @@ -90,8 +92,8 @@ object HideAutoplayButtonPatch : BytecodePatch(
move-result v$clobberRegister
if-eqz v$clobberRegister, :hidden
""",
ExternalLabel("hidden", jumpInstruction)
ExternalLabel("hidden", jumpInstruction),
)
} ?: throw LayoutConstructorFingerprint.exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import com.android.tools.smali.dexlib2.Opcode
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37",
"19.09.38",
"19.10.39",
"19.11.43"
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction3rc
"19.06.39",
"19.07.40",
"19.08.36",
"19.09.37"
"19.09.38",
"19.10.39",
"19.11.43"
]
)
]
Expand Down
Loading
Loading