Skip to content

Commit

Permalink
fix(Tumblr): Restore compatibility with latest versions (ReVanced#2955)
Browse files Browse the repository at this point in the history
  • Loading branch information
leumasme committed Mar 30, 2024
1 parent 912a77a commit 2954ba7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
@@ -1,9 +1,12 @@
package app.revanced.patches.tumblr.annoyances.popups.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

// This method is responsible for loading and displaying the visual Layout of the Gift Message Popup.
internal object ShowGiftMessagePopupFingerprint : MethodFingerprint(
strings = listOf("activity", "anchorView"),
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("GiftMessagePopup;") }
strings = listOf("activity", "anchorView", "textMessage"),
returnType = "V",
accessFlags = AccessFlags.FINAL or AccessFlags.PUBLIC
)
Expand Up @@ -28,14 +28,17 @@ object OverrideFeatureFlagsPatch : BytecodePatch(
internal lateinit var addOverride: (name: String, value: String) -> Unit private set

override fun execute(context: BytecodeContext) = GetFeatureValueFingerprint.result?.let {
val configurationClass = it.method.definingClass
val featureClass = it.method.parameterTypes[0].toString()

// The method we want to inject into does not have enough registers, so we inject a helper method
// and inject more instructions into it later, see addOverride.
// This is not in an integration since the unused variable would get compiled away and the method would
// get compiled to only have one register, which is not enough for our later injected instructions.
val helperMethod = ImmutableMethod(
it.method.definingClass,
"getValueOverride",
listOf(ImmutableMethodParameter("Lcom/tumblr/configuration/Feature;", null, "feature")),
listOf(ImmutableMethodParameter(featureClass, null, "feature")),
"Ljava/lang/String;",
AccessFlags.PUBLIC or AccessFlags.FINAL,
null,
Expand All @@ -50,7 +53,7 @@ object OverrideFeatureFlagsPatch : BytecodePatch(
0,
"""
# toString() the enum value
invoke-virtual {p1}, Lcom/tumblr/configuration/Feature;->toString()Ljava/lang/String;
invoke-virtual {p1}, $featureClass->toString()Ljava/lang/String;
move-result-object v0
# !!! If you add more instructions above this line, update helperInsertIndex below!
Expand All @@ -75,7 +78,7 @@ object OverrideFeatureFlagsPatch : BytecodePatch(
getFeatureIndex,
"""
# Call the Helper Method with the Feature
invoke-virtual {p0, p1}, Lcom/tumblr/configuration/Configuration;->getValueOverride(Lcom/tumblr/configuration/Feature;)Ljava/lang/String;
invoke-virtual {p0, p1}, $configurationClass->getValueOverride($featureClass)Ljava/lang/String;
move-result-object v0
# If it returned null, skip
if-eqz v0, :is_null
Expand Down
@@ -1,6 +1,8 @@
package app.revanced.patches.tumblr.featureflags.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

// This fingerprint targets the method to get the value of a Feature in the class "com.tumblr.configuration.Feature".
Expand All @@ -19,5 +21,7 @@ internal object GetFeatureValueFingerprint : MethodFingerprint(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT
),
customFingerprint = { method, _ -> method.definingClass == "Lcom/tumblr/configuration/Configuration;" }
returnType = "Ljava/lang/String;",
parameters = listOf("L", "Z"),
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL
)
Expand Up @@ -8,11 +8,11 @@ import app.revanced.patches.tumblr.featureflags.OverrideFeatureFlagsPatch
import app.revanced.patches.tumblr.timelinefilter.TimelineFilterPatch

@Patch(
name = "Disable Tumblr Live",
description = "Disable the Tumblr Live tab button and dashboard carousel.",
dependencies = [OverrideFeatureFlagsPatch::class, TimelineFilterPatch::class],
compatiblePackages = [CompatiblePackage("com.tumblr")],
)
@Deprecated("Tumblr Live was removed and is no longer served in the feed, making this patch useless.")
@Suppress("unused")
object DisableTumblrLivePatch : BytecodePatch(emptySet()) {
override fun execute(context: BytecodeContext) {
Expand Down

0 comments on commit 2954ba7

Please sign in to comment.