fix(youtube/general-ads): hide reels shelf

This commit is contained in:
oSumAtrIX 2022-11-22 23:41:53 +01:00
parent 308e8dfbb1
commit a436663e77
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 65 additions and 10 deletions

View File

@ -0,0 +1,23 @@
package app.revanced.patches.youtube.ad.general.bytecode.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Name("reel-constructor-fingerprint")
@GeneralAdsCompatibility
@Version("0.0.1")
object ReelConstructorFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.INVOKE_VIRTUAL
),
customFingerprint = { method ->
method.implementation?.instructions?.any {
it.opcode == Opcode.CONST && (it as WideLiteralInstruction).wideLiteral == GeneralAdsResourcePatch.reelMultipleItemShelfId
} ?: false
}
)

View File

@ -5,17 +5,22 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.extensions.softCompareTo import app.revanced.patcher.extensions.softCompareTo
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.ad.general.bytecode.fingerprints.ReelConstructorFingerprint
import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch
import app.revanced.patches.youtube.misc.settings.framework.components.impl.* import app.revanced.patches.youtube.misc.settings.framework.components.impl.*
import org.jf.dexlib2.iface.Method import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction31i import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.instruction.formats.Instruction35c import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference import org.jf.dexlib2.immutable.reference.ImmutableMethodReference
@ -28,7 +33,9 @@ import java.util.*
@Description("Removes general ads.") @Description("Removes general ads.")
@GeneralAdsCompatibility @GeneralAdsCompatibility
@Version("0.0.1") @Version("0.0.1")
class GeneralAdsPatch : BytecodePatch() { class GeneralAdsPatch : BytecodePatch(
listOf(ReelConstructorFingerprint)
) {
internal companion object { internal companion object {
private fun MutableClass.findMutableMethodOf( private fun MutableClass.findMutableMethodOf(
method: Method method: Method
@ -42,6 +49,14 @@ class GeneralAdsPatch : BytecodePatch() {
} }
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
fun String.buildHideCall(viewRegister: Int) = "invoke-static { v$viewRegister }, " +
"Lapp/revanced/integrations/patches/GeneralAdsPatch;" +
"->" +
"$this(Landroid/view/View;)V"
fun MutableMethod.injectHideCall(insertIndex: Int, viewRegister: Int, method: String) =
this.addInstruction(insertIndex, method.buildHideCall(viewRegister))
context.classes.forEach { classDef -> context.classes.forEach { classDef ->
classDef.methods.forEach { method -> classDef.methods.forEach { method ->
with(method.implementation) { with(method.implementation) {
@ -61,19 +76,31 @@ class GeneralAdsPatch : BytecodePatch() {
// Hide the view // Hide the view
val viewRegister = (this as Instruction35c).registerC val viewRegister = (this as Instruction35c).registerC
context.proxy(classDef).mutableClass.findMutableMethodOf(method).addInstruction( context.proxy(classDef)
insertIndex, .mutableClass
"invoke-static { v$viewRegister }, " + .findMutableMethodOf(method)
"Lapp/revanced/integrations/patches/GeneralAdsPatch;" + .injectHideCall(insertIndex, viewRegister, "hideAdAttributionView")
"->" +
"hideAdAttributionView(Landroid/view/View;)V"
)
} }
} }
} }
} }
} }
with(
ReelConstructorFingerprint.result
?: return PatchResultError("Could not resolve fingerprint")
) {
// iput-object v$viewRegister, ...
val insertIndex = this.scanResult.patternScanResult!!.startIndex + 2
with(this.mutableMethod) {
val viewRegister = (instruction(insertIndex) as TwoRegisterInstruction).registerA
injectHideCall(insertIndex, viewRegister, "hideReelView")
}
}
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -6,10 +6,10 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.mapping.patch.ResourceMappingPatch
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import app.revanced.patches.shared.mapping.patch.ResourceMappingPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch.PreferenceScreen import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.framework.components.impl.* import app.revanced.patches.youtube.misc.settings.framework.components.impl.*
@ -25,6 +25,7 @@ import app.revanced.patches.youtube.misc.settings.framework.components.impl.*
class GeneralAdsResourcePatch : ResourcePatch { class GeneralAdsResourcePatch : ResourcePatch {
internal companion object { internal companion object {
var adAttributionId: Long = -1 var adAttributionId: Long = -1
var reelMultipleItemShelfId: Long = -1
} }
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
@ -218,7 +219,11 @@ class GeneralAdsResourcePatch : ResourcePatch {
) )
) )
adAttributionId = ResourceMappingPatch.resourceMappings.single { it.name == "ad_attribution" }.id fun String.getId() = ResourceMappingPatch.resourceMappings.single { it.name == this }.id
adAttributionId = "ad_attribution".getId()
reelMultipleItemShelfId = "reel_multiple_items_shelf".getId()
return PatchResultSuccess() return PatchResultSuccess()
} }
} }