refactor(nunl): HideAdsPatch
This commit is contained in:
parent
32dfe48ad7
commit
678645723a
2 changed files with 41 additions and 36 deletions
|
|
@ -1,44 +1,50 @@
|
||||||
package app.revanced.patches.nunl.ads
|
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.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
internal val jwPlayerConfigFingerprint = fingerprint {
|
internal val BytecodePatchContext.jwPlayerConfigMethod by gettingFirstMutableMethodDeclaratively {
|
||||||
accessFlags(AccessFlags.PUBLIC)
|
accessFlags(AccessFlags.PUBLIC)
|
||||||
custom { methodDef, classDef ->
|
definingClass($$"Lcom/jwplayer/pub/api/configuration/PlayerConfig$Builder;")
|
||||||
classDef.type == "Lcom/jwplayer/pub/api/configuration/PlayerConfig${'$'}Builder;" && methodDef.name == "advertisingConfig"
|
name("advertisingConfig")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val screenMapperFingerprint = fingerprint {
|
internal val screenMapperMethodMatch = firstMethodComposite {
|
||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||||
returns("Lnl/nu/android/bff/domain/models/screen/ScreenEntity;")
|
returnType("Lnl/nu/android/bff/domain/models/screen/ScreenEntity;")
|
||||||
parameters("Lnl/nu/performance/api/client/objects/Screen;")
|
parameterTypes("Lnl/nu/performance/api/client/objects/Screen;")
|
||||||
|
|
||||||
opcodes(
|
definingClass("Lnl/nu/android/bff/data/mappers/ScreenMapper;")
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
name("map")
|
||||||
Opcode.IF_EQZ,
|
|
||||||
Opcode.CHECK_CAST
|
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)
|
accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL)
|
||||||
returns("Lnl/nu/android/bff/domain/models/Page;")
|
returnType("Lnl/nu/android/bff/domain/models/Page;")
|
||||||
parameters("Lnl/nu/performance/api/client/PacResponse;", "Ljava/lang/String;")
|
parameterTypes("Lnl/nu/performance/api/client/PacResponse;", "Ljava/lang/String;")
|
||||||
|
|
||||||
opcodes(
|
definingClass("Lnl/nu/android/bff/data/repositories/NextPageRepositoryImpl;")
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
name("mapToPage")
|
||||||
Opcode.IF_EQZ,
|
|
||||||
Opcode.CHECK_CAST
|
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,14 @@ package app.revanced.patches.nunl.ads
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.getInstruction
|
import app.revanced.patcher.extensions.getInstruction
|
||||||
import app.revanced.patcher.extensions.removeInstructions
|
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.patches.shared.misc.extension.sharedExtensionPatch
|
||||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("ObjectPropertyName")
|
||||||
val hideAdsPatch = bytecodePatch(
|
val `Hide ads` by creatingBytecodePatch(
|
||||||
name = "Hide ads",
|
|
||||||
description = "Hide ads and sponsored articles in list pages and remove pre-roll ads on videos.",
|
description = "Hide ads and sponsored articles in list pages and remove pre-roll ads on videos.",
|
||||||
) {
|
) {
|
||||||
compatibleWith("nl.sanomamedia.android.nu")
|
compatibleWith("nl.sanomamedia.android.nu")
|
||||||
|
|
@ -21,14 +20,14 @@ val hideAdsPatch = bytecodePatch(
|
||||||
apply {
|
apply {
|
||||||
// Disable video pre-roll ads.
|
// 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.
|
// 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)
|
val iputInstructionIndex = jwPlayerConfigMethod.indexOfFirstInstructionOrThrow(Opcode.IPUT_OBJECT)
|
||||||
jwPlayerConfigFingerprint.method.removeInstructions(iputInstructionIndex, 1)
|
jwPlayerConfigMethod.removeInstructions(iputInstructionIndex, 1)
|
||||||
|
|
||||||
// Filter injected content from API calls out of lists.
|
// 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(...).
|
// Index of instruction moving result of BlockPage;->getBlocks(...).
|
||||||
val moveGetBlocksResultObjectIndex = it.patternMatch.startIndex
|
val moveGetBlocksResultObjectIndex = match.indices.first()
|
||||||
it.method.apply {
|
match.method.apply {
|
||||||
val moveInstruction = getInstruction<OneRegisterInstruction>(moveGetBlocksResultObjectIndex)
|
val moveInstruction = getInstruction<OneRegisterInstruction>(moveGetBlocksResultObjectIndex)
|
||||||
|
|
||||||
val listRegister = moveInstruction.registerA
|
val listRegister = moveInstruction.registerA
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue