-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(youtube/general-ads): hide bytecode home ad view
- Loading branch information
Showing
3 changed files
with
93 additions
and
28 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
.../kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsBytecodePatch.kt
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters