refactor(nunl): HideAdsPatch

This commit is contained in:
Pun Butrach
2026-01-11 23:10:26 +07:00
parent 32dfe48ad7
commit 678645723a
2 changed files with 41 additions and 36 deletions

View File

@@ -1,44 +1,50 @@
package app.revanced.patches.nunl.ads
import app.revanced.patcher.fingerprint
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
import app.revanced.patcher.accessFlags
import app.revanced.patcher.definingClass
import app.revanced.patcher.firstMethodComposite
import app.revanced.patcher.instructions
import app.revanced.patcher.invoke
import app.revanced.patcher.name
import app.revanced.patcher.parameterTypes
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.returnType
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
internal val jwPlayerConfigFingerprint = fingerprint {
internal val BytecodePatchContext.jwPlayerConfigMethod by gettingFirstMutableMethodDeclaratively {
accessFlags(AccessFlags.PUBLIC)
custom { methodDef, classDef ->
classDef.type == "Lcom/jwplayer/pub/api/configuration/PlayerConfig${'$'}Builder;" && methodDef.name == "advertisingConfig"
}
definingClass($$"Lcom/jwplayer/pub/api/configuration/PlayerConfig$Builder;")
name("advertisingConfig")
}
internal val screenMapperFingerprint = fingerprint {
internal val screenMapperMethodMatch = firstMethodComposite {
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
returns("Lnl/nu/android/bff/domain/models/screen/ScreenEntity;")
parameters("Lnl/nu/performance/api/client/objects/Screen;")
returnType("Lnl/nu/android/bff/domain/models/screen/ScreenEntity;")
parameterTypes("Lnl/nu/performance/api/client/objects/Screen;")
opcodes(
Opcode.MOVE_RESULT_OBJECT,
Opcode.IF_EQZ,
Opcode.CHECK_CAST
definingClass("Lnl/nu/android/bff/data/mappers/ScreenMapper;")
name("map")
instructions(
Opcode.MOVE_RESULT_OBJECT(),
Opcode.IF_EQZ(),
Opcode.CHECK_CAST(),
)
custom { methodDef, classDef ->
classDef.type == "Lnl/nu/android/bff/data/mappers/ScreenMapper;" && methodDef.name == "map"
}
}
internal val nextPageRepositoryImplFingerprint = fingerprint {
internal val nextPageRepositoryImplMethodMatch = firstMethodComposite {
accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL)
returns("Lnl/nu/android/bff/domain/models/Page;")
parameters("Lnl/nu/performance/api/client/PacResponse;", "Ljava/lang/String;")
returnType("Lnl/nu/android/bff/domain/models/Page;")
parameterTypes("Lnl/nu/performance/api/client/PacResponse;", "Ljava/lang/String;")
opcodes(
Opcode.MOVE_RESULT_OBJECT,
Opcode.IF_EQZ,
Opcode.CHECK_CAST
definingClass("Lnl/nu/android/bff/data/repositories/NextPageRepositoryImpl;")
name("mapToPage")
instructions(
Opcode.MOVE_RESULT_OBJECT(),
Opcode.IF_EQZ(),
Opcode.CHECK_CAST(),
)
custom { methodDef, classDef ->
classDef.type == "Lnl/nu/android/bff/data/repositories/NextPageRepositoryImpl;" && methodDef.name == "mapToPage"
}
}

View File

@@ -3,15 +3,14 @@ package app.revanced.patches.nunl.ads
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.removeInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.creatingBytecodePatch
import app.revanced.patches.shared.misc.extension.sharedExtensionPatch
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Suppress("unused")
val hideAdsPatch = bytecodePatch(
name = "Hide ads",
@Suppress("ObjectPropertyName")
val `Hide ads` by creatingBytecodePatch(
description = "Hide ads and sponsored articles in list pages and remove pre-roll ads on videos.",
) {
compatibleWith("nl.sanomamedia.android.nu")
@@ -21,14 +20,14 @@ val hideAdsPatch = bytecodePatch(
apply {
// Disable video pre-roll ads.
// Whenever the app tries to define the advertising config for JWPlayer, don't set the advertising config and directly return.
val iputInstructionIndex = jwPlayerConfigFingerprint.method.indexOfFirstInstructionOrThrow(Opcode.IPUT_OBJECT)
jwPlayerConfigFingerprint.method.removeInstructions(iputInstructionIndex, 1)
val iputInstructionIndex = jwPlayerConfigMethod.indexOfFirstInstructionOrThrow(Opcode.IPUT_OBJECT)
jwPlayerConfigMethod.removeInstructions(iputInstructionIndex, 1)
// Filter injected content from API calls out of lists.
arrayOf(screenMapperFingerprint, nextPageRepositoryImplFingerprint).forEach {
arrayOf(screenMapperMethodMatch, nextPageRepositoryImplMethodMatch).forEach { match ->
// Index of instruction moving result of BlockPage;->getBlocks(...).
val moveGetBlocksResultObjectIndex = it.patternMatch.startIndex
it.method.apply {
val moveGetBlocksResultObjectIndex = match.indices.first()
match.method.apply {
val moveInstruction = getInstruction<OneRegisterInstruction>(moveGetBlocksResultObjectIndex)
val listRegister = moveInstruction.registerA