fix(youtube/general-ads): hide bytecode home ad view

This commit is contained in:
oSumAtrIX 2022-11-21 00:04:46 +01:00
parent 133265da90
commit 4976ad44b1
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 93 additions and 28 deletions

View File

@ -1,19 +0,0 @@
package app.revanced.patches.youtube.ad.general.bytecode.patch
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.misc.settings.framework.components.impl.*
@DependsOn()
@GeneralAdsCompatibility
@Version("0.0.1")
class GeneralAdsBytecodePatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
TODO("Not yet implemented")
}
}

View File

@ -0,0 +1,80 @@
package app.revanced.patches.youtube.ad.general.bytecode.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.softCompareTo
import app.revanced.patcher.patch.BytecodePatch
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.util.proxy.mutableTypes.MutableClass
import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibility
import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch
import app.revanced.patches.youtube.misc.settings.framework.components.impl.*
import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference
import java.util.*
@Patch
@DependsOn([GeneralAdsResourcePatch::class])
@Name("general-ads")
@Description("Removes general ads.")
@GeneralAdsCompatibility
@Version("0.0.1")
class GeneralAdsPatch : BytecodePatch() {
internal companion object {
private fun MutableClass.findMutableMethodOf(
method: Method
) = this.methods.first {
it.softCompareTo(
ImmutableMethodReference(
method.definingClass, method.name, method.parameters, method.returnType
)
)
}
}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
classDef.methods.forEach { method ->
with(method.implementation) {
this?.instructions?.forEachIndexed { index, instruction ->
if (instruction.opcode != org.jf.dexlib2.Opcode.CONST)
return@forEachIndexed
// Instruction to store the id adAttribution into a register
if ((instruction as Instruction31i).wideLiteral != app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch.adAttributionId)
return@forEachIndexed
val insertIndex = index + 1
// Call to get the view with the id adAttribution
with(instructions.elementAt(insertIndex)) {
if (opcode != org.jf.dexlib2.Opcode.INVOKE_VIRTUAL)
return@forEachIndexed
// Hide the view
val viewRegister = (this as Instruction35c).registerC
context.proxy(classDef).mutableClass.findMutableMethodOf(method).addInstruction(
insertIndex,
"invoke-static { v$viewRegister }, " +
"Lapp/revanced/integrations/patches/GeneralAdsPatch;" +
"->" +
"hideAdAttributionView(Landroid/view/View;)V"
)
}
}
}
}
}
return PatchResultSuccess()
}
}

View File

@ -1,14 +1,11 @@
package app.revanced.patches.youtube.ad.general.patch package app.revanced.patches.youtube.ad.general.resource.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult 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.patcher.patch.annotations.Patch
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
@ -17,13 +14,19 @@ 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.*
@Patch @DependsOn(dependencies = [
@DependsOn(dependencies = [FixLocaleConfigErrorPatch::class, LithoFilterPatch::class, SettingsPatch::class, ResourceMappingPatch::class]) FixLocaleConfigErrorPatch::class,
@Name("general-ads") LithoFilterPatch::class,
@Description("Removes general ads.") SettingsPatch::class,
ResourceMappingPatch::class
])
@GeneralAdsCompatibility @GeneralAdsCompatibility
@Version("0.0.1") @Version("0.0.1")
class GeneralAdsPatch : ResourcePatch { class GeneralAdsResourcePatch : ResourcePatch {
internal companion object {
var adAttributionId: Long = -1
}
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
PreferenceScreen.ADS.addPreferences( PreferenceScreen.ADS.addPreferences(
SwitchPreference( SwitchPreference(
@ -222,6 +225,7 @@ class GeneralAdsPatch : ResourcePatch {
) )
) )
adAttributionId = ResourceMappingPatch.resourceMappings.single { it.name == "ad_attribution" }.id
return PatchResultSuccess() return PatchResultSuccess()
} }
} }