From b3a5631f1426ca6429e3d662f9ede5e92ebfb974 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 25 Jul 2023 02:43:10 +0900 Subject: [PATCH] feat(reddit): add `hide-place-button` patch --- .../HomePagerScreenFingerprint.kt | 15 +++++ .../layout/place/patch/PlaceButtonPatch.kt | 56 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/place/fingerprints/HomePagerScreenFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/place/patch/PlaceButtonPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/place/fingerprints/HomePagerScreenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/place/fingerprints/HomePagerScreenFingerprint.kt new file mode 100644 index 0000000000..7306c0acc6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/place/fingerprints/HomePagerScreenFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.reddit.layout.place.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object HomePagerScreenFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Landroid/view/LayoutInflater;", "Landroid/view/ViewGroup;"), + strings = listOf("view.findViewById(Search\u2026nav_search_cta_container)"), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/HomePagerScreen;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/place/patch/PlaceButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/place/patch/PlaceButtonPatch.kt new file mode 100644 index 0000000000..02087f63a1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/place/patch/PlaceButtonPatch.kt @@ -0,0 +1,56 @@ +package app.revanced.patches.reddit.layout.place.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.place.fingerprints.HomePagerScreenFingerprint +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getStringIndex +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("Hide place button") +@Description("Hide r/place button in toolbar.") +@DependsOn([SettingsPatch::class]) +@RedditCompatibility +@Version("0.0.1") +class PlaceButtonPatch : BytecodePatch( + listOf(HomePagerScreenFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + HomePagerScreenFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getStringIndex("view.findViewById(Search\u2026nav_search_cta_container)") + val targetRegister = + getInstruction(targetIndex - 1).registerA + + addInstruction( + targetIndex, + "invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR" + ) + } + } ?: return HomePagerScreenFingerprint.toErrorResult() + + updateSettingsStatus("PlaceButton") + + return PatchResultSuccess() + } + + companion object { + const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/PlaceButtonPatch;" + + "->hidePlaceButton(Landroid/view/View;)V" + } +}