fix(Reddit - Remove subreddit dialog): Can't open post from search results

This commit is contained in:
inotia00 2025-04-01 18:49:47 +09:00
parent 3f9edca15d
commit 15db05c636
3 changed files with 21 additions and 44 deletions

View File

@ -33,6 +33,10 @@ public class RemoveSubRedditDialogPatch {
clickViewDelayed(cancelButtonView); clickViewDelayed(cancelButtonView);
} }
public static boolean spoofHasBeenVisitedStatus(boolean hasBeenVisited) {
return Settings.REMOVE_NSFW_DIALOG.get() || hasBeenVisited;
}
public static void dismissNSFWDialog(Object customDialog) { public static void dismissNSFWDialog(Object customDialog) {
if (Settings.REMOVE_NSFW_DIALOG.get() && if (Settings.REMOVE_NSFW_DIALOG.get() &&
customDialog instanceof Dialog dialog) { customDialog instanceof Dialog dialog) {

View File

@ -10,7 +10,6 @@ import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.TypeReference
internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint( internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint(
name = "frequentUpdatesSheetScreenFingerprint", name = "frequentUpdatesSheetScreenFingerprint",
@ -54,13 +53,6 @@ fun listOfIsLoggedInInstruction(method: Method) =
?.reversed() ?.reversed()
?: emptyList() ?: emptyList()
fun indexOfGetOverInstruction(method: Method) =
method.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.name == "getOver18"
}
internal val nsfwAlertEmitFingerprint = legacyFingerprint( internal val nsfwAlertEmitFingerprint = legacyFingerprint(
name = "nsfwAlertEmitFingerprint", name = "nsfwAlertEmitFingerprint",
returnType = "Ljava/lang/Object;", returnType = "Ljava/lang/Object;",
@ -68,24 +60,17 @@ internal val nsfwAlertEmitFingerprint = legacyFingerprint(
strings = listOf("reddit://reddit/r/", "nsfwAlertDelegate"), strings = listOf("reddit://reddit/r/", "nsfwAlertDelegate"),
customFingerprint = { method, _ -> customFingerprint = { method, _ ->
method.name == "emit" && method.name == "emit" &&
indexOfGetOverInstruction(method) >= 0 indexOfHasBeenVisitedInstruction(method) >= 0
} }
) )
internal val nsfwAlertObserverFingerprint = legacyFingerprint( fun indexOfHasBeenVisitedInstruction(method: Method) =
name = "nsfwAlertObserverFingerprint", method.indexOfFirstInstruction {
returnType = "Ljava/lang/Object;", val reference = getReference<MethodReference>()
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, opcode == Opcode.INVOKE_VIRTUAL &&
strings = listOf("nsfwAlertDelegate"), reference?.name == "getHasBeenVisited" &&
customFingerprint = { method, _ -> reference.returnType == "Z"
method.name == "invokeSuspend" &&
indexOfGetOverInstruction(method) >= 0 &&
method.indexOfFirstInstruction {
opcode == Opcode.NEW_INSTANCE &&
getReference<TypeReference>()?.type?.startsWith("Lcom/reddit/frontpage/presentation/detail/DetailHolderPresenter\$showDialogIfNeverVisitedOrSubscribed\$") == true
} >= 0
} }
)
internal val nsfwAlertBuilderFingerprint = legacyFingerprint( internal val nsfwAlertBuilderFingerprint = legacyFingerprint(
name = "nsfwAlertBuilderFingerprint", name = "nsfwAlertBuilderFingerprint",

View File

@ -2,11 +2,9 @@ package app.revanced.patches.reddit.layout.subredditdialog
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.patch.PatchList.REMOVE_SUBREDDIT_DIALOG import app.revanced.patches.reddit.utils.patch.PatchList.REMOVE_SUBREDDIT_DIALOG
@ -17,7 +15,6 @@ import app.revanced.patches.reddit.utils.settings.is_2025_05_or_greater
import app.revanced.patches.reddit.utils.settings.is_2025_06_or_greater import app.revanced.patches.reddit.utils.settings.is_2025_06_or_greater
import app.revanced.patches.reddit.utils.settings.settingsPatch import app.revanced.patches.reddit.utils.settings.settingsPatch
import app.revanced.patches.reddit.utils.settings.updatePatchStatus import app.revanced.patches.reddit.utils.settings.updatePatchStatus
import app.revanced.util.findFreeRegister
import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow import app.revanced.util.fingerprint.mutableClassOrThrow
import app.revanced.util.getReference import app.revanced.util.getReference
@ -80,26 +77,17 @@ val subRedditDialogPatch = bytecodePatch(
} }
if (is_2025_01_or_greater) { if (is_2025_01_or_greater) {
arrayOf( nsfwAlertEmitFingerprint.methodOrThrow().apply {
nsfwAlertEmitFingerprint, val hasBeenVisitedIndex = indexOfHasBeenVisitedInstruction(this)
nsfwAlertObserverFingerprint val hasBeenVisitedRegister =
).forEach { fingerprint -> getInstruction<OneRegisterInstruction>(hasBeenVisitedIndex + 1).registerA
fingerprint.methodOrThrow().apply {
val getOverIndex = indexOfGetOverInstruction(this)
val getOverRegister = getInstruction<FiveRegisterInstruction>(getOverIndex).registerC
val freeRegister = findFreeRegister(getOverIndex, getOverRegister)
val returnIndex = indexOfFirstInstructionOrThrow(getOverIndex, Opcode.RETURN_OBJECT) addInstructions(
val jumpIndex = indexOfFirstInstructionReversedOrThrow(returnIndex, Opcode.SGET_OBJECT) hasBeenVisitedIndex + 2, """
invoke-static {v$hasBeenVisitedRegister}, $EXTENSION_CLASS_DESCRIPTOR->spoofHasBeenVisitedStatus(Z)Z
addInstructionsWithLabels( move-result v$hasBeenVisitedRegister
getOverIndex, """ """
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->removeNSFWDialog()Z )
move-result v$freeRegister
if-nez v$freeRegister, :jump
""", ExternalLabel("jump", getInstruction(jumpIndex))
)
}
} }
var hookCount = 0 var hookCount = 0