From e062bea3917d92d45a3fcced0c17f843ccaceb0e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 2 May 2024 03:18:41 +0900 Subject: [PATCH] fix(Reddit): remove test code --- .../reddit/utils/fix/BrokenResourcePatch.kt | 162 ------------------ .../utils/settings/SettingsBytecodePatch.kt | 31 +--- .../ResourceProviderFingerprint.kt | 11 -- .../reddit/fix/host/values/attrs.xml | 63 ------- 4 files changed, 1 insertion(+), 266 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/utils/fix/BrokenResourcePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/utils/settings/fingerprints/ResourceProviderFingerprint.kt delete mode 100644 src/main/resources/reddit/fix/host/values/attrs.xml diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/fix/BrokenResourcePatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/fix/BrokenResourcePatch.kt deleted file mode 100644 index 4ed344d1c..000000000 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/fix/BrokenResourcePatch.kt +++ /dev/null @@ -1,162 +0,0 @@ -package app.revanced.patches.reddit.utils.fix - -import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.util.copyXmlNode -import app.revanced.util.doRecursively -import org.w3c.dom.Element - -@Patch( - description = "Replace resource formats that APKTool does not yet support decoding with hardcoded values.\n" + - "This method is not ideal, please remove this patch if APKTool will support decoding." -) -@Suppress("DEPRECATION", "unused") -object BrokenResourcePatch : ResourcePatch() { - private val attrsName = arrayOf( - "cornerFamily", - "cornerFamilyBottomLeft", - "cornerFamilyBottomRight", - "cornerFamilyTopLeft", - "labelBehavior", - "labelVisibilityMode", - "layout_constraintHorizontal_chainStyle", - "layout_constraintVertical_chainStyle", - "redditBaseTheme", - "showAsAction", - "surface_type" - ) - - private val styleMap = mapOf( - "redditBaseTheme\">0<" to "redditBaseTheme\">AlienBlue<", - "cornerFamilyBottomRight\">1<" to "cornerFamilyBottomRight\">cut<", - "cornerFamily\">1<" to "cornerFamily\">cut<", - "cornerFamilyTopLeft\">1<" to "cornerFamilyTopLeft\">cut<" - ) - - private val layoutXml = arrayOf( - "award_sheet_footer.xml", - "bottom_nav_item_normal.xml", - "comment_header.xml", - "comment_header_two_line.xml", - "custom_feed_community_list_item.xml", - "custom_feed_user_list_item.xml", - "dialog_award_info.xml", - "dialog_edit_overlay_text.xml", - "dialog_user_modal.xml", - "home_empty.xml", - "include_edit_ugc_custom_actions.xml", - "item_carousel_large.xml", - "item_comment_two_line_header.xml", - "item_community.xml", - "item_create_community.xml", - "item_pick_community.xml", - "item_subreddit.xml", - "item_topic.xml", - "layout_community_type.xml", - "layout_webembed_error.xml", - "legacy_comment_header.xml", - "link_carousel_item_subreddit_header.xml", - "link_carousel_subreddit_header.xml", - "listitem_community.xml", - "listitem_modtools_user_v2.xml", - "listitem_subreddit_with_status.xml", - "listitem_user_flair.xml", - "merge_button_wear_all.xml", - "merge_equipped_fab.xml", - "merge_link_footer.xml", - "merge_link_header_metadata.xml", - "merge_link_header_minimized_metadata.xml", - "post_header_card.xml", - "premium_marketing_perk_list_item.xml", - "premium_marketing_perk_tile.xml", - "premium_marketing_perk_tile_wide_highlighted.xml", - "promoted_user_post_list_item.xml", - "question_input_slider.xml", - "reddit_video_controls.xml", - "screen_confirm_recommended_snoovatar.xml", - "screen_copy_snoovatar.xml", - "screen_custom_feed.xml", - "screen_default_two_button_dialog.xml", - "screen_fullbleed_video.xml", - "screen_ratingsurvey_tag.xml", - "screen_share_and_download.xml", - "screen_vault_feed_empty_content.xml", - "setting_subredditnotiflevel.xml", - "toast.xml", - "trophy_item.xml", - "vault_toast.xml", - "video_user_profile_card.xml", - "view_video_controls.xml" - ) - private lateinit var context: ResourceContext - - override fun execute(context: ResourceContext) { - this.context = context - } - - internal fun fixBrokenResource() { - try { - styleMap.forEach { (from, to) -> - context["res/values/styles.xml"].apply { - writeText( - readText() - .replace( - from, - to - ) - ) - } - } - - layoutXml.forEach { file -> - val targetXml = context["res"].resolve("layout").resolve(file) - if (targetXml.exists()) { - context["res/layout/$file"].apply { - writeText( - readText() - .replace( - "chainStyle=\"2\"", - "chainStyle=\"packed\"" - ) - ) - } - } - } - - arrayOf( - "experiments_override_menu.xml", - "menu_protect_vault.xml" - ).forEach { file -> - val targetXml = context["res"].resolve("menu").resolve(file) - if (targetXml.exists()) { - context.xmlEditor["res/menu/$file"].use { editor -> - editor.file.doRecursively loop@{ - if (it !is Element) return@loop - - it.getAttributeNode("app:showAsAction")?.let { attribute -> - attribute.textContent = "ifRoom|withText" - } - } - } - } - } - - context.xmlEditor["res/values/attrs.xml"].use { editor -> - editor.file.doRecursively loop@{ - if (it !is Element) return@loop - - it.getAttributeNode("name")?.let { attribute -> - if (attrsName.indexOf(attribute.textContent) >= 0) { - it.parentNode?.removeChild(it) - } - } - } - } - } catch (_: Exception) { - } - - context.copyXmlNode("reddit/fix/host", "values/attrs.xml", "resources") - } - -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt index 85593adac..a0541bf9c 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt @@ -8,34 +8,24 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.reddit.utils.fix.BrokenResourcePatch import app.revanced.patches.reddit.utils.integrations.Constants.INTEGRATIONS_PATH import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.LabelAcknowledgements import app.revanced.patches.reddit.utils.settings.fingerprints.AcknowledgementsLabelBuilderFingerprint import app.revanced.patches.reddit.utils.settings.fingerprints.OssLicensesMenuActivityOnCreateFingerprint -import app.revanced.patches.reddit.utils.settings.fingerprints.ResourceProviderFingerprint import app.revanced.patches.reddit.utils.settings.fingerprints.SettingsStatusLoadFingerprint import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprint import app.revanced.util.getTargetIndex import app.revanced.util.getWideLiteralInstructionIndex -import app.revanced.util.indexOfFirstInstruction import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -@Patch( - dependencies = [ - BrokenResourcePatch::class, - SharedResourceIdPatch::class - ] -) +@Patch(dependencies = [SharedResourceIdPatch::class]) object SettingsBytecodePatch : BytecodePatch( setOf( AcknowledgementsLabelBuilderFingerprint, OssLicensesMenuActivityOnCreateFingerprint, - ResourceProviderFingerprint, SharedSettingFingerprint, SettingsStatusLoadFingerprint ) @@ -103,24 +93,5 @@ object SettingsBytecodePatch : BytecodePatch( } settingsStatusLoadMethod = SettingsStatusLoadFingerprint.resultOrThrow().mutableMethod - - /** - * Check version - */ - ResourceProviderFingerprint.result?.mutableMethod?.apply { - val versionIndex = indexOfFirstInstruction { - opcode == Opcode.CONST_STRING - && (this as? BuilderInstruction21c)?.reference.toString().startsWith("202") - } - if (versionIndex > -1) { - val versionNumber = getInstruction(versionIndex).reference.toString().replace(".", "").toInt() - val upward2024180 = versionNumber >= 2024180 - - if (upward2024180) { - BrokenResourcePatch.fixBrokenResource() - } - } - } - } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/fingerprints/ResourceProviderFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/fingerprints/ResourceProviderFingerprint.kt deleted file mode 100644 index e3b890bfd..000000000 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/fingerprints/ResourceProviderFingerprint.kt +++ /dev/null @@ -1,11 +0,0 @@ -package app.revanced.patches.reddit.utils.settings.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags - -internal object ResourceProviderFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - customFingerprint = { _, classDef -> classDef.sourceFile == "RedditInternalFeatures.kt" } -) \ No newline at end of file diff --git a/src/main/resources/reddit/fix/host/values/attrs.xml b/src/main/resources/reddit/fix/host/values/attrs.xml deleted file mode 100644 index f8885be8d..000000000 --- a/src/main/resources/reddit/fix/host/values/attrs.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -