Skip to content

Commit

Permalink
feat(Tumblr): Add Disable dashboard ads patch (#2979)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
leumasme and oSumAtrIX committed Sep 11, 2023
1 parent f6ac4da commit 07c267a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.patches.tumblr.ads.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

// The Tumblr app sends a request to /v2/timeline/dashboard which replies with an array of elements
// to show in the user dashboard. These element have different type ids (post, title, carousel, etc.)
// The standard dashboard Ad has the id client_side_ad_waterfall, and this string has to be in the code
// to handle ads and provide their appearance.
// If we just replace this string in the tumblr code with anything else, it will fail to recognize the
// dashboard object type and just skip it. This is a bit weird, but it shouldn't break
// unless they change the api (unlikely) or explicitly Change the tumblr code to prevent this.
object AdWaterfallFingerprint : MethodFingerprint(strings = listOf("client_side_ad_waterfall"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package app.revanced.patches.tumblr.ads.patch

import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Package
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.tumblr.ads.fingerprints.AdWaterfallFingerprint
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch
@Name("Disable dashboard ads")
@Description("Disables ads in the dashboard.")
@Compatibility([Package("com.tumblr")])
class DisableDashboardAds : BytecodePatch(
listOf(AdWaterfallFingerprint)
) {
override fun execute(context: BytecodeContext) = AdWaterfallFingerprint.result?.let {
it.scanResult.stringsScanResult!!.matches.forEach { match ->
// We just replace all occurrences of "client_side_ad_waterfall" with anything else
// so the app fails to handle ads in the timeline elements array and just skips them.
// See AdWaterfallFingerprint for more info.
val stringRegister = it.mutableMethod.getInstruction<OneRegisterInstruction>(match.index).registerA
it.mutableMethod.replaceInstruction(
match.index, "const-string v$stringRegister, \"dummy\""
)
}
} ?: throw AdWaterfallFingerprint.exception
}

0 comments on commit 07c267a

Please sign in to comment.