feat(reddit): add hide-place-button patch

This commit is contained in:
inotia00
2023-07-25 02:43:10 +09:00
parent f65d9a89b3
commit b3a5631f14
2 changed files with 71 additions and 0 deletions

View File

@ -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;")
}
)

View File

@ -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<OneRegisterInstruction>(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"
}
}