diff --git a/CHANGELOG.md b/CHANGELOG.md index 062786bdb3..bfebce7e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,33 +1,3 @@ -## [6.1.1-dev.4](https://github.com/ReVanced/revanced-patches/compare/v6.1.1-dev.3...v6.1.1-dev.4) (2026-03-22) - - -### Bug Fixes - -* **Instagram - Disable signature check:** Set correct return type ([#6918](https://github.com/ReVanced/revanced-patches/issues/6918)) ([4a36d1a](https://github.com/ReVanced/revanced-patches/commit/4a36d1ab569201316ee3b83be9f5ab9539c3336d)) -* **YouTube - Announcements:** Parse announcement correctly by using `Instant` instead of `LocalDateTime` for `archived_at` ([#6889](https://github.com/ReVanced/revanced-patches/issues/6889)) ([77098b2](https://github.com/ReVanced/revanced-patches/commit/77098b2c057e53f375bca8dffd369e801fdaed52)) - -## [6.1.1-dev.3](https://github.com/ReVanced/revanced-patches/compare/v6.1.1-dev.2...v6.1.1-dev.3) (2026-03-20) - - -### Bug Fixes - -* **GmsCore support:** Correct option name ([6cbef5a](https://github.com/ReVanced/revanced-patches/commit/6cbef5a48a83e4a74de578e7d20f7d71a8b1de8e)) -* **GmsCore support:** Correct package name for custom vendor group id ([292728a](https://github.com/ReVanced/revanced-patches/commit/292728a8baddbca87993590db4a8bab60b564432)) - -## [6.1.1-dev.2](https://github.com/ReVanced/revanced-patches/compare/v6.1.1-dev.1...v6.1.1-dev.2) (2026-03-20) - - -### Bug Fixes - -* **Twitter:** Correct extension path to fix crashes ([f4b2545](https://github.com/ReVanced/revanced-patches/commit/f4b2545742e0501ab252c70654993a4e4414319e)) - -## [6.1.1-dev.1](https://github.com/ReVanced/revanced-patches/compare/v6.1.0...v6.1.1-dev.1) (2026-03-19) - - -### Bug Fixes - -* **YouTube - Spoof video streams:** Set `ANDROID_REEL` client as default ([#6878](https://github.com/ReVanced/revanced-patches/issues/6878)) ([a9aeb32](https://github.com/ReVanced/revanced-patches/commit/a9aeb325de1160262c4db9b4b60c6c5e39730620)) - # [6.1.0](https://github.com/ReVanced/revanced-patches/compare/v6.0.1...v6.1.0) (2026-03-18) diff --git a/README.md b/README.md index 0693f1048a..a7a9db8855 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Some of the features the patches provide are: export activities, etc. * ✨ **And much more!** -For a complete list of all available patches, see [this](https://github.com/ReVanced/revanced-documentation/blob/main/docs/revanced-resources/questions.md#5-which-patches-are-available). +For a complete list of all available patches, visit [revanced.app/patches](https://revanced.app/patches). ## 🚀 How to get started diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java index bafdc04163..fb7e68963a 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/GmsCoreSupport.java @@ -105,7 +105,7 @@ public class GmsCoreSupport { return null; } }), - UNKNOWN(getGmsCoreVendorGroupId(), getGmsCoreVendorGroupId() + ".android.gms", () -> null); + UNKNOWN(getGmsCoreVendorGroupId(), getGmsCoreVendorGroupId() + "android.gms", () -> null); private static final String DONT_KILL_MY_APP_URL = "https://dontkillmyapp.com/"; diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/BaseJsonHook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/BaseJsonHook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/BaseJsonHook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/BaseJsonHook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/JsonHook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/JsonHook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/JsonHook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/JsonHook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/JsonHookPatch.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/JsonHookPatch.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/json/JsonHookPatch.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/json/JsonHookPatch.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/Hook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/Hook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/Hook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/Hook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/ads/HideAdsHook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/ads/HideAdsHook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/ads/HideAdsHook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/ads/HideAdsHook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/dummy/DummyHook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/dummy/DummyHook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/dummy/DummyHook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/dummy/DummyHook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/twifucker/TwiFucker.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/twifucker/TwiFucker.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/twifucker/TwiFucker.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/twifucker/TwiFucker.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/twifucker/TwiFuckerUtils.kt b/extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/twifucker/TwiFuckerUtils.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/hook/twifucker/TwiFuckerUtils.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/hook/twifucker/TwiFuckerUtils.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/links/ChangeLinkSharingDomainPatch.java b/extensions/twitter/src/main/java/app/revanced/twitter/patches/links/ChangeLinkSharingDomainPatch.java similarity index 94% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/links/ChangeLinkSharingDomainPatch.java rename to extensions/twitter/src/main/java/app/revanced/twitter/patches/links/ChangeLinkSharingDomainPatch.java index 3eb477e127..0be07403bc 100644 --- a/extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/links/ChangeLinkSharingDomainPatch.java +++ b/extensions/twitter/src/main/java/app/revanced/twitter/patches/links/ChangeLinkSharingDomainPatch.java @@ -1,4 +1,4 @@ -package app.revanced.extension.twitter.patches.links; +package app.revanced.twitter.patches.links; @SuppressWarnings("unused") public final class ChangeLinkSharingDomainPatch { diff --git a/extensions/twitter/src/main/java/app/revanced/twitter/patches/links/OpenLinksWithAppChooserPatch.java b/extensions/twitter/src/main/java/app/revanced/twitter/patches/links/OpenLinksWithAppChooserPatch.java new file mode 100644 index 0000000000..bd0476d8b2 --- /dev/null +++ b/extensions/twitter/src/main/java/app/revanced/twitter/patches/links/OpenLinksWithAppChooserPatch.java @@ -0,0 +1,22 @@ +package app.revanced.twitter.patches.links; + +import android.content.Context; +import android.content.Intent; + +import app.revanced.extension.shared.Logger; + +@SuppressWarnings("unused") +@Deprecated(forRemoval = true) +public final class OpenLinksWithAppChooserPatch { + + /** + * Injection point. + */ + public static void openWithChooser(final Context context, final Intent intent) { + Logger.printInfo(() -> "Opening intent with chooser: " + intent); + + intent.setAction("android.intent.action.VIEW"); + + context.startActivity(Intent.createChooser(intent, null)); + } +} diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/utils/json/JsonUtils.kt b/extensions/twitter/src/main/java/app/revanced/twitter/utils/json/JsonUtils.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/utils/json/JsonUtils.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/utils/json/JsonUtils.kt diff --git a/extensions/twitter/src/main/java/app/revanced/extension/twitter/utils/stream/StreamUtils.kt b/extensions/twitter/src/main/java/app/revanced/twitter/utils/stream/StreamUtils.kt similarity index 100% rename from extensions/twitter/src/main/java/app/revanced/extension/twitter/utils/stream/StreamUtils.kt rename to extensions/twitter/src/main/java/app/revanced/twitter/utils/stream/StreamUtils.kt diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/announcements/AnnouncementsPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/announcements/AnnouncementsPatch.java index 466c87dbf0..8e24d65ec5 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/announcements/AnnouncementsPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/announcements/AnnouncementsPatch.java @@ -20,7 +20,7 @@ import org.json.JSONObject; import java.io.IOException; import java.net.HttpURLConnection; -import java.time.Instant; +import java.time.LocalDateTime; import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.Utils; @@ -116,7 +116,7 @@ public final class AnnouncementsPatch { int id = Settings.ANNOUNCEMENT_LAST_ID.defaultValue; String title; String message; - Instant archivedAt = Instant.MAX; + LocalDateTime archivedAt = LocalDateTime.MAX; Level level = Level.INFO; try { final var announcements = new JSONArray(jsonString); @@ -140,20 +140,20 @@ public final class AnnouncementsPatch { title = announcement.getString("title"); message = announcement.getString("content"); if (!announcement.isNull("archived_at")) { - archivedAt = Instant.parse(announcement.getString("archived_at")); + archivedAt = LocalDateTime.parse(announcement.getString("archived_at")); } if (!announcement.isNull("level")) { level = Level.fromInt(announcement.getInt("level")); } } catch (Throwable ex) { - Logger.printException(() -> "Failed to parse announcement. Falling back to raw string", ex); + Logger.printException(() -> "Failed to parse announcement. Fall-backing to raw string", ex); title = "Announcement"; message = jsonString; } // If the announcement is archived, do not show it. - if (archivedAt.isBefore(Instant.now())) { + if (archivedAt.isBefore(LocalDateTime.now())) { Settings.ANNOUNCEMENT_LAST_ID.save(id); return; } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index cfe0f927d3..d69ed54e2d 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -391,7 +391,7 @@ public class Settings extends YouTubeAndMusicSettings { public static final BooleanSetting EXTERNAL_BROWSER = new BooleanSetting("revanced_external_browser", TRUE, true); public static final BooleanSetting SPOOF_DEVICE_DIMENSIONS = new BooleanSetting("revanced_spoof_device_dimensions", FALSE, true, "revanced_spoof_device_dimensions_user_dialog_message"); - public static final EnumSetting SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client_type", ClientType.ANDROID_REEL, true, parent(SPOOF_VIDEO_STREAMS)); + public static final EnumSetting SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client_type", ClientType.ANDROID_VR_1_43_32, true, parent(SPOOF_VIDEO_STREAMS)); public static final BooleanSetting SPOOF_VIDEO_STREAMS_AV1 = new BooleanSetting("revanced_spoof_video_streams_av1", FALSE, true, "revanced_spoof_video_streams_av1_user_dialog_message", new SpoofClientAv1Availability()); diff --git a/gradle.properties b/gradle.properties index 0ef9f06173..d65f6857e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ org.gradle.parallel = true android.useAndroidX = true android.uniquePackageNames = false kotlin.code.style = official -version = 6.1.1-dev.4 +version = 6.1.0 diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/adb/HideAdbStatusPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/adb/HideAdbStatusPatch.kt index 4c903f0789..71f6777857 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/adb/HideAdbStatusPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/adb/HideAdbStatusPatch.kt @@ -1,11 +1,12 @@ package app.revanced.patches.all.misc.adb -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference import com.android.tools.smali.dexlib2.util.MethodUtil @@ -43,7 +44,7 @@ val hideADBStatusPatch = bytecodePatch( filterMap = filterMap@{ classDef, method, instruction, instructionIndex -> val reference = instruction .takeIf { it.opcode == Opcode.INVOKE_STATIC } - ?.methodReference + ?.getReference() ?.takeIf { reference -> getIntMethodReferences.any { MethodUtil.methodSignaturesMatch(it, reference) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch.kt index ee3e0d2c31..567df9f7e0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/build/BaseSpoofBuildInfoPatch.kt @@ -1,11 +1,12 @@ package app.revanced.patches.all.misc.build -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference private const val BUILD_CLASS_DESCRIPTOR = "Landroid/os/Build;" @@ -74,7 +75,7 @@ fun baseSpoofBuildInfoPatch(buildInfoSupplier: () -> BuildInfo) = bytecodePatch dependsOn( transformInstructionsPatch( filterMap = filterMap@{ _, _, instruction, instructionIndex -> - val reference = instruction.fieldReference ?: return@filterMap null + val reference = instruction.getReference() ?: return@filterMap null if (reference.definingClass != BUILD_CLASS_DESCRIPTOR) return@filterMap null return@filterMap replacements[reference.name]?.let { instructionIndex to it } diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/connectivity/location/hide/HideMockLocationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/connectivity/location/hide/HideMockLocationPatch.kt index 9b5afef4a2..8c69bfad07 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/connectivity/location/hide/HideMockLocationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/connectivity/location/hide/HideMockLocationPatch.kt @@ -1,12 +1,13 @@ package app.revanced.patches.all.misc.connectivity.location.hide -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.IMethodCall import app.revanced.patches.all.misc.transformation.fromMethodReference import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val hideMockLocationPatch = bytecodePatch( @@ -17,7 +18,7 @@ val hideMockLocationPatch = bytecodePatch( dependsOn( transformInstructionsPatch( filterMap = filter@{ _, _, instruction, instructionIndex -> - val reference = instruction.methodReference ?: return@filter null + val reference = instruction.getReference() ?: return@filter null if (fromMethodReference(reference) == null) return@filter null instruction to instructionIndex diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/play/DisablePlayIntegrity.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/play/DisablePlayIntegrity.kt index 186eec96b6..dd5dad79e4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/play/DisablePlayIntegrity.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/play/DisablePlayIntegrity.kt @@ -1,10 +1,11 @@ package app.revanced.patches.all.misc.play -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference import com.android.tools.smali.dexlib2.util.MethodUtil @@ -29,7 +30,7 @@ val disablePlayIntegrityPatch = bytecodePatch( transformInstructionsPatch( filterMap = filterMap@{ classDef, method, instruction, instructionIndex -> val reference = instruction - .methodReference + .getReference() ?.takeIf { MethodUtil.methodSignaturesMatch(CONTEXT_BIND_SERVICE_METHOD_REFERENCE, it) } diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/play/SpoofPlayAgeSignals.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/play/SpoofPlayAgeSignals.kt index d11e3cf84b..ccb41b81b4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/play/SpoofPlayAgeSignals.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/play/SpoofPlayAgeSignals.kt @@ -2,12 +2,14 @@ package app.revanced.patches.all.misc.play import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstructions import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.intOption +import app.revanced.patcher.patch.option import app.revanced.util.forEachInstructionAsSequence +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference @@ -44,7 +46,7 @@ val spoofPlayAgeSignalsPatch = bytecodePatch( if (classDef.type.startsWith("Lcom/google/android/play/agesignals/")) return@forEachInstructionAsSequence null // Keep method calls only. - val reference = instruction.methodReference + val reference = instruction.getReference() ?: return@forEachInstructionAsSequence null val match = MethodCall.entries.firstOrNull { diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt index f0c3aa92b4..93092b5f3e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt @@ -1,10 +1,11 @@ package app.revanced.patches.all.misc.screenshot -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference import com.android.tools.smali.dexlib2.util.MethodUtil @@ -38,7 +39,7 @@ val preventScreenshotDetectionPatch = bytecodePatch( filterMap = { _, _, instruction, instructionIndex -> if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@transformInstructionsPatch null - val reference = instruction.methodReference ?: return@transformInstructionsPatch null + val reference = instruction.getReference() ?: return@transformInstructionsPatch null instructionIndex.takeIf { MethodUtil.methodSignaturesMatch(reference, registerScreenCaptureCallbackMethodReference) || diff --git a/patches/src/main/kotlin/app/revanced/patches/cricbuzz/ads/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/cricbuzz/ads/DisableAdsPatch.kt index 322794cc68..6dde6e7257 100644 --- a/patches/src/main/kotlin/app/revanced/patches/cricbuzz/ads/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/cricbuzz/ads/DisableAdsPatch.kt @@ -1,14 +1,15 @@ package app.revanced.patches.cricbuzz.ads import app.revanced.patcher.extensions.addInstruction -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.cricbuzz.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/cricbuzz/ads/HideAdsPatch;" @@ -26,7 +27,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") { cb11ConstructorMethod.addInstruction(0, "const/4 p7, 0x0") getBottomBarMethod.apply { val getIndex = indexOfFirstInstructionOrThrow { - opcode == Opcode.IGET_OBJECT && fieldReference?.name == "bottomBar" + opcode == Opcode.IGET_OBJECT && getReference()?.name == "bottomBar" } val getRegister = getInstruction(getIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/crunchyroll/ads/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/crunchyroll/ads/HideAdsPatch.kt index 290da66397..3a697c3b75 100644 --- a/patches/src/main/kotlin/app/revanced/patches/crunchyroll/ads/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/crunchyroll/ads/HideAdsPatch.kt @@ -1,15 +1,16 @@ package app.revanced.patches.crunchyroll.ads import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import app.revanced.util.removeFlags import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Suppress("unused") val hideAdsPatch = bytecodePatch("Hide ads") { @@ -21,7 +22,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") { val stringIndex = videoUrlReadyToStringMethodMatch[-1] val fieldIndex = it.indexOfFirstInstruction(stringIndex, Opcode.IGET_BOOLEAN) - it.getInstruction(fieldIndex).fieldReference!! + it.getInstruction(fieldIndex).getReference()!! } // Remove final access flag on field. diff --git a/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt b/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt index e7793ec9ec..3096647525 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt @@ -2,20 +2,23 @@ package app.revanced.patches.googlenews.misc.extension.hooks import app.revanced.patcher.definingClass import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.methodReference +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke import app.revanced.patcher.name import app.revanced.patcher.opcodes import app.revanced.patches.shared.misc.extension.extensionHook +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private var getApplicationContextIndex = -1 internal val startActivityInitHook = extensionHook( getInsertIndex = { getApplicationContextIndex = indexOfFirstInstructionOrThrow { - methodReference?.name == "getApplicationContext" + getReference()?.name == "getApplicationContext" } getApplicationContextIndex + 2 // Below the move-result-object instruction. diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Hooks.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Hooks.kt index 08b805b4df..8ed9937cff 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Hooks.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Hooks.kt @@ -2,20 +2,23 @@ package app.revanced.patches.googlephotos.misc.extension import app.revanced.patcher.definingClass import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.methodReference +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke import app.revanced.patcher.name import app.revanced.patcher.opcodes import app.revanced.patches.shared.misc.extension.extensionHook +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private var getApplicationContextIndex = -1 internal val homeActivityInitHook = extensionHook( getInsertIndex = { getApplicationContextIndex = indexOfFirstInstructionOrThrow { - methodReference?.name == "getApplicationContext" + getReference()?.name == "getApplicationContext" } getApplicationContextIndex + 2 // Below the move-result-object instruction. diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt index 4ea5eca910..71046d14eb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt @@ -2,11 +2,12 @@ package app.revanced.patches.googlephotos.misc.features import app.revanced.patcher.extensions.instructions import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.stringsOption +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference @Suppress("unused") val spoofFeaturesPatch = bytecodePatch( @@ -61,7 +62,7 @@ val spoofFeaturesPatch = bytecodePatch( initializeFeaturesEnumMethod.apply { instructions.filter { it.opcode == Opcode.CONST_STRING }.forEach { - val feature = it.stringReference!!.string + val feature = it.getReference()!!.string val spoofedFeature = when (feature) { in featuresToEnable -> "android.hardware.wifi" diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/gms/GmsCoreSupportPatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/gms/GmsCoreSupportPatch.kt index 7537158302..65ae7572c4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/gms/GmsCoreSupportPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/gms/GmsCoreSupportPatch.kt @@ -7,6 +7,10 @@ import app.revanced.patches.googlephotos.misc.extension.extensionPatch import app.revanced.patches.googlephotos.misc.gms.Constants.PHOTOS_PACKAGE_NAME import app.revanced.patches.googlephotos.misc.gms.Constants.REVANCED_PHOTOS_PACKAGE_NAME import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow +import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow @Suppress("unused") diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt index 5f927822b0..c998611255 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/feed/LimitFeedToFollowedProfiles.kt @@ -9,8 +9,10 @@ import app.revanced.patcher.immutableClassDef import app.revanced.patcher.name import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/instagram/feed/LimitFeedToFollowedProfiles;" @@ -38,7 +40,7 @@ val limitFeedToFollowedProfilesPatch = bytecodePatch( reference?.type == "Ljava/util/Map;" && reference.definingClass == mainFeedRequestClassMethod.classDef.type }.let { instructionIndex -> - getInstruction(instructionIndex).fieldReference!!.name + getInstruction(instructionIndex).getReference()!!.name } } @@ -47,7 +49,7 @@ val limitFeedToFollowedProfilesPatch = bytecodePatch( }.apply { // Finds the instruction where the map is being initialized in the constructor val getHeaderIndex = indexOfFirstInstructionOrThrow { - fieldReference.let { + getReference().let { it?.name == mainFeedRequestHeaderFieldName } } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt index fdf9cae6f8..ef4070c62a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/navigation/HideNavigationButtons.kt @@ -1,6 +1,5 @@ package app.revanced.patches.instagram.hide.navigation -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.firstMethodDeclaratively import app.revanced.patcher.immutableClassDef @@ -10,10 +9,12 @@ import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference import java.util.logging.Logger private const val EXTENSION_CLASS_DESCRIPTOR = @@ -81,7 +82,7 @@ val hideNavigationButtonsPatch = bytecodePatch( opcode == Opcode.IPUT_OBJECT && (this as TwoRegisterInstruction).registerA == 2 // p2 register. }.let { - method.getInstruction(it).fieldReference!!.name + method.getInstruction(it).getReference()!!.name } } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/signature/SignatureCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/signature/SignatureCheckPatch.kt index 972a6f6028..3ee3f82380 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/misc/signature/SignatureCheckPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/misc/signature/SignatureCheckPatch.kt @@ -14,6 +14,6 @@ val disableSignatureCheckPatch = bytecodePatch( compatibleWith("com.instagram.android") apply { - isValidSignatureMethodMethod.immutableClassDef.getIsValidSignatureClassMethod().returnEarly() + isValidSignatureMethodMethod.immutableClassDef.getIsValidSignatureClassMethod().returnEarly(true) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt index fdb15699cb..ff6b5326a5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.music.layout.branding import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.typeReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.music.misc.extension.sharedExtensionPatch import app.revanced.patches.music.misc.gms.Constants.MUSIC_MAIN_ACTIVITY_NAME @@ -13,10 +12,12 @@ import app.revanced.patches.shared.layout.branding.EXTENSION_CLASS_DESCRIPTOR import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch import app.revanced.patches.shared.misc.mapping.ResourceType import app.revanced.patches.shared.misc.mapping.resourceMappingPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.TypeReference private val disableSplashAnimationPatch = bytecodePatch { @@ -36,7 +37,7 @@ private val disableSplashAnimationPatch = bytecodePatch { ) val checkCastIndex = indexOfFirstInstructionOrThrow(literalIndex) { opcode == Opcode.CHECK_CAST && - typeReference?.type == "Lcom/airbnb/lottie/LottieAnimationView;" + getReference()?.type == "Lcom/airbnb/lottie/LottieAnimationView;" } val register = getInstruction(checkCastIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt index 3699860112..d8f78efe2f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt @@ -4,7 +4,6 @@ package app.revanced.patches.music.layout.miniplayercolor import app.revanced.patcher.accessFlags import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.firstMethodDeclaratively import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.bytecodePatch @@ -21,6 +20,7 @@ import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/music/patches/ChangeMiniplayerColorPatch;" @@ -72,7 +72,7 @@ val changeMiniplayerColorPatch = bytecodePatch( val colorGreyIndex = miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionReversedOrThrow { - methodReference?.name == "getColor" + getReference()?.name == "getColor" } val iPutIndex = miniPlayerConstructorMethodMatch.immutableMethod.indexOfFirstInstructionOrThrow( diff --git a/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt b/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt index 888d364892..d2242b172c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt @@ -1,14 +1,15 @@ package app.revanced.patches.openinghours.misc.fix.crash import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.newLabel import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21t import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.Instruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val fixCrashPatch = bytecodePatch( @@ -77,7 +78,7 @@ val fixCrashPatch = bytecodePatch( } private fun isInvokeInstruction(instruction: Instruction, className: String, methodName: String): Boolean { - val methodRef = instruction.methodReference ?: return false + val methodRef = instruction.getReference() ?: return false return methodRef.definingClass == className && methodRef.name == methodName } diff --git a/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt index 38a32991f6..d37280e454 100644 --- a/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt @@ -3,10 +3,11 @@ package app.revanced.patches.piccomafr.tracking import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.instructions import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference @Suppress("unused") val disableTrackingPatch = bytecodePatch( @@ -47,7 +48,7 @@ val disableTrackingPatch = bytecodePatch( firebaseInstallMethod.instructions.filter { it.opcode == Opcode.CONST_STRING }.filter { - it.stringReference?.string == "firebaseinstallations.googleapis.com" + it.getReference()?.string == "firebaseinstallations.googleapis.com" }.forEach { instruction -> instruction as OneRegisterInstruction diff --git a/patches/src/main/kotlin/app/revanced/patches/primevideo/ads/SkipAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/primevideo/ads/SkipAdsPatch.kt index e9ed08b8c7..a78fcf1269 100644 --- a/patches/src/main/kotlin/app/revanced/patches/primevideo/ads/SkipAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/primevideo/ads/SkipAdsPatch.kt @@ -2,13 +2,14 @@ package app.revanced.patches.primevideo.ads import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.primevideo.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val skipAdsPatch = bytecodePatch( @@ -31,7 +32,7 @@ val skipAdsPatch = bytecodePatch( // move-result-object { playerRegister } val getPlayerIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_VIRTUAL && - methodReference?.name == "getPrimaryPlayer" + getReference()?.name == "getPrimaryPlayer" } val playerRegister = getInstruction(getPlayerIndex + 1).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/primevideo/video/speed/PlaybackSpeedPatch.kt b/patches/src/main/kotlin/app/revanced/patches/primevideo/video/speed/PlaybackSpeedPatch.kt index 7797be1f66..cce68b6c13 100644 --- a/patches/src/main/kotlin/app/revanced/patches/primevideo/video/speed/PlaybackSpeedPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/primevideo/video/speed/PlaybackSpeedPatch.kt @@ -1,13 +1,14 @@ package app.revanced.patches.primevideo.video.speed import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.primevideo.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/primevideo/videoplayer/PlaybackSpeedPatch;" @@ -29,7 +30,7 @@ val playbackSpeedPatch = bytecodePatch( playbackUserControlsInitializeMethod.apply { val getIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.IPUT_OBJECT && - fieldReference?.name == "mUserControls" + getReference()?.name == "mUserControls" } val getRegister = getInstruction(getIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt index 59aa93e76c..79bc78ec1a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt +++ b/patches/src/main/kotlin/app/revanced/patches/protonvpn/splittunneling/UnlockSplitTunneling.kt @@ -1,12 +1,13 @@ package app.revanced.patches.protonvpn.splittunneling import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val unlockSplitTunnelingPatch = bytecodePatch("Unlock split tunneling") { @@ -21,7 +22,7 @@ val unlockSplitTunnelingPatch = bytecodePatch("Unlock split tunneling") { initializeSplitTunnelingSettingsUIMethod.apply { val initSettingsIndex = indexOfFirstInstructionOrThrow { - methodReference?.name == "getSplitTunneling" + getReference()?.name == "getSplitTunneling" } removeInstruction(initSettingsIndex - 1) } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt index 4269a5284d..8cf4a3aa67 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt @@ -1,16 +1,17 @@ package app.revanced.patches.reddit.ad.general import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.reddit.ad.comments.hideCommentAdsPatch import app.revanced.patches.reddit.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val hideAdsPatch = bytecodePatch("Hide ads") { @@ -56,7 +57,7 @@ val hideAdsPatch = bytecodePatch("Hide ads") { // By removing the appending instruction no ad posts gets appended to the feed. val index = newAdPostMethod.indexOfFirstInstruction { - val reference = methodReference ?: return@indexOfFirstInstruction false + val reference = getReference() ?: return@indexOfFirstInstruction false reference.name == "add" && reference.definingClass == "Ljava/util/ArrayList;" } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/fix/redgifs/FixRedgifsApiPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/fix/redgifs/FixRedgifsApiPatch.kt index 709cf7d24b..3d3e6e3ed6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/fix/redgifs/FixRedgifsApiPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/fix/redgifs/FixRedgifsApiPatch.kt @@ -1,16 +1,17 @@ package app.revanced.patches.reddit.customclients.baconreader.fix.redgifs import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstructions import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.extensions.typeReference import app.revanced.patches.reddit.customclients.INSTALL_NEW_CLIENT_METHOD import app.revanced.patches.reddit.customclients.baconreader.misc.extension.sharedExtensionPatch import app.revanced.patches.reddit.customclients.fixRedgifsApiPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/baconreader/FixRedgifsApiPatch;" @@ -33,7 +34,7 @@ val fixRedgifsApi = fixRedgifsApiPatch( getOkHttpClientMethod.removeInstructions(originalInterceptorInstallIndex, 5) val index = getOkHttpClientMethod.indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.name == "build" && reference.definingClass == $$"Lokhttp3/OkHttpClient$Builder;" } val register = getOkHttpClientMethod.getInstruction(index).registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt index d5fac16131..b99df9d8e2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt @@ -2,12 +2,13 @@ package app.revanced.patches.reddit.customclients.boostforreddit.api import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patches.reddit.customclients.spoofClientPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference @Suppress("unused") val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption -> @@ -29,7 +30,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" val userAgentTemplateIndex = buildUserAgentMethod.indexOfFirstInstructionOrThrow { - opcode == Opcode.CONST_STRING && stringReference?.string == "%s:%s:%s (by /u/%s)" + opcode == Opcode.CONST_STRING && getReference()?.string == "%s:%s:%s (by /u/%s)" } val register = buildUserAgentMethod.getInstruction(userAgentTemplateIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt index 536e363178..95bd1ccd5d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt @@ -3,11 +3,12 @@ package app.revanced.patches.reddit.customclients.redditisfun.api import app.revanced.patcher.CompositeMatch import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patches.reddit.customclients.spoofClientPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference @Suppress("unused") val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { clientIdOption -> @@ -63,7 +64,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl // Replace old.reddit.com with www.reddit.com to fix this. buildAuthorizationStringMethodMatch.method.apply { val index = indexOfFirstInstructionOrThrow { - stringReference?.contains("old.reddit.com") == true + getReference()?.contains("old.reddit.com") == true } val targetRegister = getInstruction(index).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/redgifs/FixRedgifsApiPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/redgifs/FixRedgifsApiPatch.kt index c5e64b6929..e4ae3a322e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/redgifs/FixRedgifsApiPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/redgifs/FixRedgifsApiPatch.kt @@ -2,13 +2,14 @@ package app.revanced.patches.reddit.customclients.sync.syncforreddit.fix.redgifs import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patches.reddit.customclients.INSTALL_NEW_CLIENT_METHOD import app.revanced.patches.reddit.customclients.fixRedgifsApiPatch import app.revanced.patches.reddit.customclients.sync.syncforreddit.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/syncforreddit/FixRedgifsApiPatch;" @@ -26,7 +27,7 @@ val fixRedgifsApi = fixRedgifsApiPatch( // region Patch Redgifs OkHttp3 client. val index = createOkHttpClientMethod.indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.name == "build" && reference.definingClass == $$"Lokhttp3/OkHttpClient$Builder;" } val register = createOkHttpClientMethod.getInstruction(index).registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/samsung/radio/restrictions/device/BypassDeviceChecksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/samsung/radio/restrictions/device/BypassDeviceChecksPatch.kt index cabec25adc..f3b2e9f080 100644 --- a/patches/src/main/kotlin/app/revanced/patches/samsung/radio/restrictions/device/BypassDeviceChecksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/samsung/radio/restrictions/device/BypassDeviceChecksPatch.kt @@ -2,11 +2,12 @@ package app.revanced.patches.samsung.radio.restrictions.device import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.removeInstructions -import app.revanced.patcher.extensions.stringReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.reference.StringReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/samsung/radio/restrictions/device/BypassDeviceChecksPatch;" @@ -24,7 +25,7 @@ val bypassDeviceChecksPatch = bytecodePatch( // Find the first string that start with "SM-", that's the list of incompatible devices. val firstStringIndex = checkDeviceMethod.indexOfFirstInstructionOrThrow { opcode == Opcode.CONST_STRING && - stringReference?.string?.startsWith("SM-") == true + getReference()?.string?.startsWith("SM-") == true } // Find the following filled-new-array (or filled-new-array/range) instruction. diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt index 0c4a27d759..9a583e2c7a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt @@ -2,9 +2,7 @@ package app.revanced.patches.shared.layout.branding import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod import app.revanced.patcher.extensions.addInstruction -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.typeReference import app.revanced.patcher.patch.* import app.revanced.patches.all.misc.packagename.setOrGetFallbackPackageName import app.revanced.patches.all.misc.resources.addResources @@ -16,6 +14,8 @@ import app.revanced.util.* import app.revanced.util.Utils.trimIndentMultiline import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.TypeReference import org.w3c.dom.Element import org.w3c.dom.NodeList import java.io.File @@ -125,22 +125,22 @@ internal fun baseCustomBrandingPatch( val getBuilderIndex = if (isYouTubeMusic) { // YT Music the field is not a plain object type. indexOfFirstInstructionOrThrow { - fieldReference?.type == $$"Landroid/app/Notification$Builder;" + getReference()?.type == $$"Landroid/app/Notification$Builder;" } } else { // Find the field name of the notification builder. Field is an Object type. val builderCastIndex = indexOfFirstInstructionOrThrow { - val reference = typeReference + val reference = getReference() opcode == Opcode.CHECK_CAST && reference?.type == $$"Landroid/app/Notification$Builder;" } indexOfFirstInstructionReversedOrThrow(builderCastIndex) { - fieldReference?.type == "Ljava/lang/Object;" + getReference()?.type == "Ljava/lang/Object;" } } val builderFieldName = getInstruction(getBuilderIndex) - .fieldReference + .getReference() findInstructionIndicesReversedOrThrow( Opcode.RETURN_VOID, diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt index 9bc4b2b8ea..0a356a1a7c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt @@ -65,9 +65,10 @@ fun gmsCoreSupportPatch( "using a GmsCore instead of Google Play Services.", ) { val gmsCoreVendorGroupIdOption = stringOption( - name = "GmsCore vendor group ID", + key = "gmsCoreVendorGroupId", default = "app.revanced", values = mapOf("ReVanced" to "app.revanced"), + title = "GmsCore vendor group ID", description = "The vendor's group ID for GmsCore.", required = true, ) { it!!.matches(Regex(PACKAGE_NAME_REGEX_PATTERN)) } diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt index c7d39f73de..1c918b8104 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt @@ -20,6 +20,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter @@ -122,7 +123,7 @@ internal fun spoofVideoStreamsPatch( val resultMethodType = createStreamingDataMethodMatch.classDef.type val videoDetailsIndex = createStreamingDataMethodMatch[-1] val videoDetailsRegister = getInstruction(videoDetailsIndex).registerA - val videoDetailsClass = getInstruction(videoDetailsIndex).fieldReference!!.type + val videoDetailsClass = getInstruction(videoDetailsIndex).getReference()!!.type addInstruction( videoDetailsIndex + 1, @@ -134,15 +135,15 @@ internal fun spoofVideoStreamsPatch( val setStreamingDataIndex = createStreamingDataMethodMatch[0] val playerProtoClass = getInstruction(setStreamingDataIndex + 1) - .fieldReference!!.definingClass + .getReference()!!.definingClass - val setStreamingDataField = getInstruction(setStreamingDataIndex).fieldReference + val setStreamingDataField = getInstruction(setStreamingDataIndex).getReference() val getStreamingDataField = getInstruction( indexOfFirstInstructionOrThrow { - opcode == Opcode.IGET_OBJECT && fieldReference?.definingClass == playerProtoClass + opcode == Opcode.IGET_OBJECT && getReference()?.definingClass == playerProtoClass }, - ).fieldReference + ).getReference() // Use a helper method to avoid the need of picking out multiple free registers from the hooked code. createStreamingDataMethodMatch.classDef.methods.add( @@ -274,7 +275,7 @@ internal fun spoofVideoStreamsPatch( val mediaFetchEnumClass = definingClass val sabrFieldIndex = indexOfFirstInstructionOrThrow(disabledBySABRStreamingUrlString) { opcode == Opcode.SPUT_OBJECT && - fieldReference?.type == mediaFetchEnumClass + getReference()?.type == mediaFetchEnumClass } Pair( diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/UserAgentClientSpoofPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/UserAgentClientSpoofPatch.kt index d41c58dd61..e512578bd8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/UserAgentClientSpoofPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/UserAgentClientSpoofPatch.kt @@ -1,15 +1,16 @@ package app.revanced.patches.shared.misc.spoof import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patches.all.misc.transformation.IMethodCall import app.revanced.patches.all.misc.transformation.filterMapInstruction35c import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.android.tools.smali.dexlib2.iface.reference.StringReference private const val USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE = "Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;" @@ -36,7 +37,7 @@ fun userAgentClientSpoofPatch(originalPackageName: String) = transformInstructio // IndexOutOfBoundsException is technically possible here, // but no such occurrences are present in the app. - val referee = getInstruction(instructionIndex + 2).methodReference?.toString() + val referee = getInstruction(instructionIndex + 2).getReference()?.toString() // Only replace string builder usage. if (referee != USER_AGENT_STRING_BUILDER_APPEND_METHOD_REFERENCE) { @@ -47,7 +48,7 @@ fun userAgentClientSpoofPatch(originalPackageName: String) = transformInstructio // Changing these package names will result in playback limitations, // particularly Android VR background audio only playback. val resourceOrGmsStringInstructionIndex = indexOfFirstInstruction { - val reference = stringReference + val reference = getReference() opcode == Opcode.CONST_STRING && (reference?.string == "android.resource://" || reference?.string == "gcore_") } diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt index afb6566349..a6ba7a12e9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt @@ -1,11 +1,12 @@ package app.revanced.patches.shared.misc.string import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.extensions.stringReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.ReferenceType import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference import kotlin.text.contains fun replaceStringPatch( @@ -19,7 +20,7 @@ fun replaceStringPatch( filterMap = filterMap@{ _, _, instruction, instructionIndex -> if (instruction.opcode.referenceType != ReferenceType.STRING) return@filterMap null - val stringReference = instruction.stringReference!!.string + val stringReference = instruction.getReference()!!.string if (from !in stringReference) return@filterMap null Triple(instructionIndex, instruction as OneRegisterInstruction, stringReference) diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt index f3ed6ac6d3..7fd1114419 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt @@ -3,8 +3,10 @@ package app.revanced.patches.soundcloud.offlinesync import app.revanced.patcher.extensions.* import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.soundcloud.shared.featureConstructorMethod +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Suppress("unused") val enableOfflineSyncPatch = bytecodePatch("Enable offline sync") { @@ -38,7 +40,7 @@ val enableOfflineSyncPatch = bytecodePatch("Enable offline sync") { val getEndpointsEnumFieldInstruction = getInstruction(getEndpointsEnumFieldIndex) val targetRegister = getEndpointsEnumFieldInstruction.registerA - val endpointsType = getEndpointsEnumFieldInstruction.fieldReference!!.type + val endpointsType = getEndpointsEnumFieldInstruction.getReference()!!.type replaceInstruction( getEndpointsEnumFieldIndex, diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt index c08907e4a4..6b859d3e05 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt @@ -2,15 +2,16 @@ package app.revanced.patches.spotify.layout.theme import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.booleanOption import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.resourcePatch import app.revanced.patcher.patch.stringOption import app.revanced.patches.spotify.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import org.w3c.dom.Element private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/spotify/layout/theme/CustomThemePatch;" @@ -38,7 +39,7 @@ private val customThemeBytecodePatch = bytecodePatch { // including the solid color of it. parseLottieJsonMethod.apply { val invokeParseColorIndex = indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Landroid/graphics/Color;" && reference.name == "parseColor" } @@ -59,7 +60,7 @@ private val customThemeBytecodePatch = bytecodePatch { // Lottie animated color parser. parseAnimatedColorMethod.apply { val invokeArgbIndex = indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Landroid/graphics/Color;" && reference.name == "argb" } diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/extension/Hooks.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/extension/Hooks.kt index 7da96936b0..60726251d5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/extension/Hooks.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/extension/Hooks.kt @@ -1,14 +1,15 @@ package app.revanced.patches.spotify.misc.extension -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.string import app.revanced.patcher.instructions import app.revanced.patcher.invoke import app.revanced.patches.shared.misc.extension.activityOnCreateExtensionHook import app.revanced.patches.shared.misc.extension.extensionHook +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference internal val mainActivityOnCreateHook = activityOnCreateExtensionHook( "Lcom/spotify/music/SpotifyMainActivity;" @@ -24,7 +25,7 @@ internal val loadOrbitLibraryHook = extensionHook( }, getContextRegister = { contextReferenceIndex = indexOfFirstInstruction { - fieldReference?.type == "Landroid/content/Context;" + getReference()?.type == "Landroid/content/Context;" } val contextRegister = getInstruction(contextReferenceIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/ChangeLyricsProviderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/ChangeLyricsProviderPatch.kt index a3638464c8..020399c703 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/ChangeLyricsProviderPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/ChangeLyricsProviderPatch.kt @@ -4,7 +4,6 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.firstMethodDeclaratively import app.revanced.patcher.instructions @@ -13,10 +12,13 @@ import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.stringOption import app.revanced.patcher.returnType +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference import java.net.InetAddress import java.net.URI @@ -68,10 +70,10 @@ val changeLyricsProviderPatch = bytecodePatch( val patchedHttpClientBuilderMethod = with(httpClientBuilderMethod) { val invokeBuildUrlIndex = indexOfFirstInstructionOrThrow { - methodReference?.returnType == "Lokhttp3/HttpUrl;" + getReference()?.returnType == "Lokhttp3/HttpUrl;" } val setUrlBuilderHostIndex = indexOfFirstInstructionReversedOrThrow(invokeBuildUrlIndex) { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Lokhttp3/HttpUrl${"$"}Builder;" && reference.parameterTypes.firstOrNull() == "Ljava/lang/String;" } @@ -101,7 +103,7 @@ val changeLyricsProviderPatch = bytecodePatch( getLyricsHttpClientMethod.apply { val getLyricsHttpClientIndex = indexOfFirstInstructionOrThrow { - methodReference == httpClientBuilderMethod + getReference() == httpClientBuilderMethod } val getLyricsHttpClientInstruction = getInstruction(getLyricsHttpClientIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/Fingerprints.kt index a681ebdbaa..ee60ea884f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/misc/lyrics/Fingerprints.kt @@ -1,7 +1,12 @@ package app.revanced.patches.spotify.misc.lyrics import app.revanced.patcher.gettingFirstImmutableMethod +import app.revanced.patcher.gettingFirstImmutableMethodDeclaratively +import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext - +import app.revanced.patcher.returnType +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal val BytecodePatchContext.httpClientBuilderMethod by gettingFirstImmutableMethod("client == null", "scheduler == null") diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/groupkudos/AddGiveGroupKudosButtonToGroupActivityPatch.kt b/patches/src/main/kotlin/app/revanced/patches/strava/groupkudos/AddGiveGroupKudosButtonToGroupActivityPatch.kt index b789e47da7..9d4756f455 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/groupkudos/AddGiveGroupKudosButtonToGroupActivityPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/groupkudos/AddGiveGroupKudosButtonToGroupActivityPatch.kt @@ -4,12 +4,12 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.typeReference import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.resourcePatch import app.revanced.util.childElementsSequence import app.revanced.util.findElementByAttributeValueOrThrow +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.AccessFlags.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation @@ -18,6 +18,7 @@ import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction31i import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction +import com.android.tools.smali.dexlib2.iface.reference.TypeReference import com.android.tools.smali.dexlib2.immutable.ImmutableClassDef import com.android.tools.smali.dexlib2.immutable.ImmutableField import com.android.tools.smali.dexlib2.immutable.ImmutableMethod @@ -114,7 +115,7 @@ val addGiveGroupKudosButtonToGroupActivityPatch = bytecodePatch( val checkCastButtonInstruction = getInstruction(constLeaveIdInstruction.location.index + 3) - val buttonClassName = checkCastButtonInstruction.typeReference!!.type + val buttonClassName = checkCastButtonInstruction.getReference()!!.type addInstructions( constLeaveIdInstruction.location.index, diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/media/download/AddMediaDownloadPatch.kt b/patches/src/main/kotlin/app/revanced/patches/strava/media/download/AddMediaDownloadPatch.kt index e295a45e6e..a3905c139a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/media/download/AddMediaDownloadPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/media/download/AddMediaDownloadPatch.kt @@ -4,18 +4,19 @@ import app.revanced.patcher.extensions.ExternalLabel import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.typeReference import app.revanced.patcher.firstImmutableClassDef import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.shared.misc.mapping.ResourceType import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.strava.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import app.revanced.util.writeRegister import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction22c +import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.TypeReference private const val ACTION_CLASS_DESCRIPTOR = "Lcom/strava/bottomsheet/Action;" private const val MEDIA_CLASS_DESCRIPTOR = "Lcom/strava/photos/data/Media;" @@ -44,7 +45,7 @@ val addMediaDownloadPatch = bytecodePatch( } val actionRegistrarRegister = getInstruction(setTrueIndex).registerB val actionRegister = instructions.first { instruction -> - instruction.typeReference?.type == ACTION_CLASS_DESCRIPTOR + instruction.getReference()?.type == ACTION_CLASS_DESCRIPTOR }.writeRegister!! fun addMenuItem(actionId: String, string: String, color: String, drawable: String) = addInstructions( @@ -73,7 +74,7 @@ val addMediaDownloadPatch = bytecodePatch( // Move media to last parameter of `Action` constructor. val getMediaInstruction = instructions.first { instruction -> - instruction.fieldReference?.type == MEDIA_CLASS_DESCRIPTOR + instruction.getReference()?.type == MEDIA_CLASS_DESCRIPTOR } addInstruction( getMediaInstruction.location.index + 1, diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt index 75b3a4d906..3150c6a190 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt @@ -6,9 +6,11 @@ import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch import app.revanced.patches.tiktok.misc.settings.settingsPatch import app.revanced.patches.tiktok.misc.settings.settingsStatusLoadMethod import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/tiktok/download/DownloadsPatch;" @@ -48,7 +50,7 @@ val downloadsPatch = bytecodePatch( // Change the download path patch. downloadUriMethod.apply { findInstructionIndicesReversedOrThrow { - fieldReference.let { + getReference().let { it?.definingClass == "Landroid/os/Environment;" && it.name.startsWith("DIRECTORY_") } }.forEach { fieldIndex -> diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt index 738eab47ec..9ad16de080 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt @@ -4,13 +4,15 @@ import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference +import app.revanced.patcher.firstClassDef import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.tiktok.shared.getEnterFromMethod import app.revanced.patches.tiktok.shared.onRenderFirstFrameMethod +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction11x +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Suppress("unused") val playbackSpeedPatch = bytecodePatch( @@ -26,7 +28,7 @@ val playbackSpeedPatch = bytecodePatch( apply { getSpeedMethod.apply { val injectIndex = - indexOfFirstInstructionOrThrow { methodReference?.returnType == "F" } + 2 + indexOfFirstInstructionOrThrow { getReference()?.returnType == "F" } + 2 val register = getInstruction(injectIndex - 1).registerA addInstruction( diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/share/SanitizeShareUrlsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/share/SanitizeShareUrlsPatch.kt index c81fbc61ad..da6e6aaacc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/share/SanitizeShareUrlsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/share/SanitizeShareUrlsPatch.kt @@ -2,10 +2,10 @@ package app.revanced.patches.tiktok.misc.share import app.revanced.patcher.extensions.addInstructionsWithLabels import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -30,7 +30,7 @@ val sanitizeSharingLinksPatch = bytecodePatch( apply { urlShorteningMethod.apply { val invokeIndex = indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.name == "LIZ" && reference.definingClass.startsWith("LX/") } @@ -43,7 +43,7 @@ val sanitizeSharingLinksPatch = bytecodePatch( .reference.toString() val observableFactoryIndex = indexOfFirstInstructionOrThrow { - val ref = methodReference + val ref = getReference() ref?.name == "LJ" && ref.definingClass.startsWith("LX/") } val observableFactoryRef = getInstruction(observableFactoryIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt index 4f8b5d7e98..77660b0118 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt @@ -14,7 +14,7 @@ import java.net.InetAddress import java.net.UnknownHostException import java.util.logging.Logger -internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/twitter/patches/links/ChangeLinkSharingDomainPatch;" +internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/twitter/patches/links/ChangeLinkSharingDomainPatch;" internal val domainNameOption = stringOption( default = "fxtwitter.com", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt index 560de817b4..208151e344 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt @@ -14,8 +14,10 @@ import app.revanced.patches.youtube.misc.playservice.versionCheckPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.findInstructionIndicesReversed +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;" @@ -43,7 +45,7 @@ val enableSlideToSeekPatch = bytecodePatch( val checkIndex = slideToSeekMethodMatch[0] val checkReference = slideToSeekMethodMatch.method.getInstruction(checkIndex) - .methodReference!! + .getReference()!! val extensionMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->isSlideToSeekDisabled(Z)Z" diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableTapToSeekPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableTapToSeekPatch.kt index d96878c680..610d923c26 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableTapToSeekPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableTapToSeekPatch.kt @@ -3,7 +3,6 @@ package app.revanced.patches.youtube.interaction.seekbar import app.revanced.patcher.extensions.ExternalLabel import app.revanced.patcher.extensions.addInstructionsWithLabels import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -13,6 +12,8 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.findFreeRegister import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/TapToSeekPatch;" @@ -34,7 +35,8 @@ val enableTapToSeekPatch = bytecodePatch( // Find the required methods to tap the seekbar. val tapToSeekMethods = onTouchEventHandlerMethodMatch.let { - fun getReference(index: Int) = it.method.getInstruction(index).methodReference!! + fun getReference(index: Int) = it.method.getInstruction(index) + .reference as MethodReference listOf( getReference(it[0]), diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationBarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationBarPatch.kt index 3121a666f6..64df88bb37 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationBarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationBarPatch.kt @@ -26,11 +26,13 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.insertLiteralOverride import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import kotlin.collections.plusAssign private const val EXTENSION_CLASS_DESCRIPTOR = @@ -233,7 +235,7 @@ val navigationBarPatch = bytecodePatch( // Fix missing left padding when using wide searchbar. wideSearchbarLayoutMethod.apply { findInstructionIndicesReversedOrThrow { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Landroid/view/LayoutInflater;" && reference.name == "inflate" }.forEach { inflateIndex -> val register = diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index 8768e09781..2af8a1177a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -17,11 +17,12 @@ import app.revanced.util.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/HidePlayerOverlayButtonsPatch;" -@Suppress("unused") +@Suppress("ObjectPropertyName") val hidePlayerOverlayButtonsPatch = bytecodePatch( name = "Hide player overlay buttons", description = "Adds options to hide the player Cast, Autoplay, Captions, Previous & Next buttons, and the player " + @@ -120,7 +121,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( // Add a conditional branch around the code that inflates and adds the auto-repeat button. val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) { - val parameterTypes = methodReference?.parameterTypes + val parameterTypes = getReference()?.parameterTypes opcode == Opcode.INVOKE_VIRTUAL && parameterTypes?.size == 2 && parameterTypes.first() == "Landroid/view/ViewStub;" diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt index bb9aaa39d1..00cf27fe76 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.youtube.layout.hide.fullscreenambientmode import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -10,8 +9,10 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/DisableFullscreenAmbientModePatch;" @@ -50,7 +51,7 @@ val disableFullscreenAmbientModePatch = bytecodePatch( setFullScreenBackgroundColorMethod.apply { val insertIndex = indexOfFirstInstructionReversedOrThrow { - methodReference?.name == "setBackgroundColor" + getReference()?.name == "setBackgroundColor" } val register = getInstruction(insertIndex).registerD diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt index 9c8b2f15fb..ea7fd4c919 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt @@ -21,6 +21,7 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.findFreeRegister import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -30,6 +31,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter @@ -487,7 +489,7 @@ val hideLayoutComponentsPatch = hideLayoutComponentsPatch( yoodlesImageViewMethod.apply { findInstructionIndicesReversedOrThrow { - methodReference?.name == "setImageDrawable" + getReference()?.name == "setImageDrawable" }.forEach { insertIndex -> val drawableRegister = getInstruction(insertIndex).registerD val imageViewRegister = getInstruction(insertIndex).registerC @@ -510,7 +512,7 @@ val hideLayoutComponentsPatch = hideLayoutComponentsPatch( // Find the instruction where the text dimension is retrieved. val applyDimensionIndex = indexOfFirstInstructionReversedOrThrow { - val reference = methodReference + val reference = getReference() opcode == Opcode.INVOKE_STATIC && reference?.definingClass == "Landroid/util/TypedValue;" && reference.returnType == "F" && diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt index 1b6cc63117..0ef561d714 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt @@ -7,9 +7,7 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.bytecodePatch @@ -31,6 +29,8 @@ import com.android.tools.smali.dexlib2.iface.ClassDef import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter @@ -269,7 +269,7 @@ val miniplayerPatch = bytecodePatch( it.apply { if (AccessFlags.CONSTRUCTOR.isSet(accessFlags)) { val iPutIndex = indexOfFirstInstructionOrThrow { - this.opcode == Opcode.IPUT && this.fieldReference?.type == "I" + this.opcode == Opcode.IPUT && this.getReference()?.type == "I" } insertModernMiniplayerTypeOverride(iPutIndex) @@ -394,7 +394,7 @@ val miniplayerPatch = bytecodePatch( if (is_20_31_or_greater) { miniplayerSetIconsMethod.apply { findInstructionIndicesReversedOrThrow { - val reference = methodReference + val reference = getReference() opcode == Opcode.INVOKE_INTERFACE && reference?.returnType == "Z" && reference.parameterTypes.isEmpty() }.forEach { index -> diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt index 6709ae898d..801fc83880 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt @@ -5,7 +5,6 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan import app.revanced.patcher.* import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.shared.layout.theme.lithoColorHookPatch @@ -19,12 +18,14 @@ import app.revanced.patches.youtube.misc.playservice.is_21_02_or_greater import app.revanced.patches.youtube.misc.playservice.versionCheckPatch import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.insertLiteralOverride import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter @@ -157,7 +158,7 @@ val seekbarColorPatch = bytecodePatch( val setAnimationIntMethodName = lottieAnimationViewSetAnimationIntMethod.name findInstructionIndicesReversedOrThrow { - val reference = methodReference + val reference = getReference() reference?.definingClass == LOTTIE_ANIMATION_VIEW_CLASS_TYPE && reference.name == setAnimationIntMethodName }.forEach { index -> diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt index caf2e6f0e2..63fa21a216 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt @@ -5,7 +5,6 @@ import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.immutableClassDef @@ -21,19 +20,22 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/ShortsAutoplayPatch;" -@Suppress("unused") +@Suppress("ObjectPropertyName") val shortsAutoplayPatch = bytecodePatch( name = "Shorts autoplay", description = "Adds options to automatically play the next Short.", @@ -97,7 +99,7 @@ val shortsAutoplayPatch = bytecodePatch( reelPlaybackRepeatMethod.apply { // The behavior enums are looked up from an ordinal value to an enum type. findInstructionIndicesReversedOrThrow { - val reference = methodReference + val reference = getReference() reference?.definingClass == reelEnumClass && reference.parameterTypes.firstOrNull() == "I" && reference.returnType == reelEnumClass @@ -127,12 +129,12 @@ val shortsAutoplayPatch = bytecodePatch( // Find the first call modified by extension code above. val extensionReturnResultIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_STATIC && - methodReference?.definingClass == EXTENSION_CLASS_DESCRIPTOR + getReference()?.definingClass == EXTENSION_CLASS_DESCRIPTOR } + 1 val enumRegister = getInstruction(extensionReturnResultIndex).registerA val getReelSequenceControllerIndex = indexOfFirstInstructionOrThrow { - val reference = fieldReference + val reference = getReference() opcode == Opcode.IGET_OBJECT && reference?.definingClass == definingClass && reference.type == reelSequenceControllerMethodReference.definingClass diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt index ed706d3311..518902cab2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsplayer/OpenShortsInRegularPlayerPatch.kt @@ -24,11 +24,13 @@ import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod import app.revanced.patches.youtube.video.information.playbackStartDescriptorToStringMethodMatch import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.findInstructionIndicesReversedOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/OpenShortsInRegularPlayerPatch;" @@ -147,14 +149,14 @@ val openShortsInRegularPlayerPatch = bytecodePatch( // Method call for Activity.finish() val finishIndexFirst = indexOfFirstInstructionOrThrow { - val reference = methodReference + val reference = getReference() reference?.name == "finish" } // Second Activity.finish() call. Has been present since 19.x but started // to interfere with back to exit fullscreen around 20.47. val finishIndexSecond = indexOfFirstInstruction(finishIndexFirst + 1) { - val reference = methodReference + val reference = getReference() reference?.name == "finish" } val getBooleanFieldIndex = indexOfFirstInstructionReversedOrThrow(finishIndexSecond) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt index a59fda9908..41c049d821 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt @@ -2,9 +2,7 @@ package app.revanced.patches.youtube.layout.sponsorblock import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.resourcePatch @@ -35,6 +33,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private val sponsorBlockResourcePatch = resourcePatch { dependsOn( @@ -158,7 +157,7 @@ val sponsorBlockPatch = bytecodePatch( val rectangleIndex = indexOfFirstInstructionReversedOrThrow( it[0], ) { - fieldReference?.type == "Landroid/graphics/Rect;" + getReference()?.type == "Landroid/graphics/Rect;" } rectangleFieldName = getInstruction(rectangleIndex).reference as FieldReference @@ -183,7 +182,7 @@ val sponsorBlockPatch = bytecodePatch( // Find the drawCircle call and draw the segment before it. val drawCircleIndex = indexOfFirstInstructionReversedOrThrow { - methodReference?.name == "drawCircle" + getReference()?.name == "drawCircle" } val drawCircleInstruction = getInstruction(drawCircleIndex) val canvasInstanceRegister = drawCircleInstruction.registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt index c7887afad1..c727aa8267 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.youtube.layout.startupshortsreset import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -15,9 +14,11 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/DisableResumingStartupShortsPlayerPatch;" @@ -77,8 +78,8 @@ val disableResumingShortsOnStartupPatch = bytecodePatch( userWasInShortsLegacyMethod.apply { val listenableInstructionIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_INTERFACE && - methodReference?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" && - methodReference?.name == "isDone" + getReference()?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" && + getReference()?.name == "isDone" } val freeRegister = findFreeRegister(listenableInstructionIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/toolbar/ToolbarHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/toolbar/ToolbarHookPatch.kt index 1c266dde71..b01a440873 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/toolbar/ToolbarHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/toolbar/ToolbarHookPatch.kt @@ -3,13 +3,13 @@ package app.revanced.patches.youtube.layout.toolbar import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.getInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.shared.getToolBarButtonMethodMatch import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow @@ -17,6 +17,7 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/ToolbarPatch;" @@ -32,14 +33,14 @@ val toolbarHookPatch = bytecodePatch { fun indexOfGetDrawableInstruction(method: Method) = method.indexOfFirstInstruction { opcode == Opcode.INVOKE_VIRTUAL && - methodReference?.toString() == "Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;" + getReference()?.toString() == "Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;" } getToolBarButtonMethodMatch().method.apply { val getDrawableIndex = indexOfGetDrawableInstruction(this) val enumOrdinalIndex = indexOfFirstInstructionReversedOrThrow(getDrawableIndex) { opcode == Opcode.INVOKE_INTERFACE && - methodReference?.returnType == "I" + getReference()?.returnType == "I" } val replaceReference = getInstruction(enumOrdinalIndex).reference val replaceRegister = getInstruction(enumOrdinalIndex).registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt index a9c3489a25..6f4944eaa4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.youtube.misc.backgroundplayback import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -21,6 +20,7 @@ import app.revanced.patches.youtube.video.information.videoInformationPatch import app.revanced.util.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal var prefBackgroundAndOfflineCategoryId = -1L private set @@ -86,7 +86,7 @@ val removeBackgroundPlaybackRestrictionsPatch = bytecodePatch( // Enable background playback option in YouTube settings backgroundPlaybackSettingsMethod.apply { val booleanCalls = instructions.withIndex().filter { - it.value.methodReference?.returnType == "Z" + it.value.getReference()?.returnType == "Z" } val settingsBooleanIndex = booleanCalls.elementAt(1).index diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/engagement/EngagementPanelHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/engagement/EngagementPanelHookPatch.kt index b0f49d64db..dc274c3b64 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/engagement/EngagementPanelHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/engagement/EngagementPanelHookPatch.kt @@ -9,7 +9,9 @@ import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.shared.getEngagementPanelControllerMethodMatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference import kotlin.properties.Delegates private const val EXTENSION_CLASS_DESCRIPTOR = diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt index 75b6cea642..a8615c1d50 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt @@ -1,12 +1,13 @@ package app.revanced.patches.youtube.misc.fix.backtoexitgesture import app.revanced.patcher.extensions.addInstruction -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.youtube.shared.mainActivityOnBackPressedMethod import app.revanced.util.addInstructionsAtControlFlowLabel +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/FixBackToExitGesturePatch;" @@ -25,7 +26,7 @@ internal val fixBackToExitGesturePatch = bytecodePatch( with(scrollPositionMethodMatch) { navigate(immutableMethod).to(scrollPositionMethodMatch[0] + 1).stop().apply { val index = indexOfFirstInstructionOrThrow { - opcode == Opcode.INVOKE_VIRTUAL && methodReference?.definingClass == + opcode == Opcode.INVOKE_VIRTUAL && getReference()?.definingClass == "Landroid/support/v7/widget/RecyclerView;" } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playbackspeed/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playbackspeed/Fingerprints.kt index 860617bd6f..728ad0fef0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playbackspeed/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playbackspeed/Fingerprints.kt @@ -2,16 +2,18 @@ package app.revanced.patches.youtube.misc.fix.playbackspeed import app.revanced.patcher.accessFlags import app.revanced.patcher.custom -import app.revanced.patcher.extensions.fieldReference +import app.revanced.patcher.gettingFirstImmutableMethodDeclaratively import app.revanced.patcher.gettingFirstMethodDeclaratively import app.revanced.patcher.opcodes import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.returnType +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversed import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.iface.reference.FieldReference /** * This method is usually used to set the initial speed (1.0x) when playback starts from the feed. @@ -38,5 +40,5 @@ internal val BytecodePatchContext.playbackSpeedInFeedsMethod by gettingFirstMeth internal fun indexOfGetPlaybackSpeedInstruction(method: Method) = method.indexOfFirstInstructionReversed { opcode == Opcode.IGET && - fieldReference?.type == "F" + getReference()?.type == "F" } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt index 9144593e02..f1d569e459 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt @@ -5,11 +5,11 @@ import app.revanced.com.android.tools.smali.dexlib2.mutable.MutableMethod.Compan import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.fieldReference import app.revanced.patcher.extensions.instructions import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation @@ -40,7 +40,7 @@ val cronetImageURLHookPatch = bytecodePatch( // The URL is required for the failure callback hook, but the URL field is obfuscated. // Add a helper get method that returns the URL field. val urlFieldInstruction = requestMethod.instructions.first { - val reference = it.fieldReference + val reference = it.getReference() it.opcode == Opcode.IPUT_OBJECT && reference?.type == "Ljava/lang/String;" } as ReferenceInstruction diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt index 290439908b..705539bd40 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt @@ -7,7 +7,6 @@ import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.reference import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.PatchException @@ -21,14 +20,19 @@ import app.revanced.patches.youtube.shared.mainActivityOnBackPressedMethod import app.revanced.util.ResourceGroup import app.revanced.util.copyResources import app.revanced.util.findFreeRegister +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.Instruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.util.MethodUtil +import java.util.logging.Logger internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/shared/NavigationBar;" @@ -80,14 +84,14 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig val navigationEnumClassName = navigationEnumMethod.classDef.type addHook(NavigationHook.SET_LAST_APP_NAVIGATION_ENUM) { opcode == Opcode.INVOKE_STATIC && - methodReference?.definingClass == navigationEnumClassName + getReference()?.definingClass == navigationEnumClassName } // Hook the creation of navigation tab views. val drawableTabMethod = pivotBarButtonsCreateDrawableViewMethod addHook(NavigationHook.NAVIGATION_TAB_LOADED) predicate@{ MethodUtil.methodSignaturesMatch( - methodReference ?: return@predicate false, + getReference() ?: return@predicate false, drawableTabMethod, ) } @@ -95,7 +99,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig if (is_20_21_or_greater && !is_20_28_or_greater) { addHook(NavigationHook.NAVIGATION_TAB_LOADED) predicate@{ MethodUtil.methodSignaturesMatch( - methodReference ?: return@predicate false, + getReference() ?: return@predicate false, pivotBarButtonsCreateResourceIntViewMethod, ) } @@ -103,7 +107,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig addHook(NavigationHook.NAVIGATION_IMAGE_RESOURCE_TAB_LOADED) predicate@{ MethodUtil.methodSignaturesMatch( - methodReference ?: return@predicate false, + getReference() ?: return@predicate false, pivotBarButtonsCreateResourceStyledViewMethod, ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/codecs/DisableVideoCodecsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/codecs/DisableVideoCodecsPatch.kt index 691426ed92..7e3360dde0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/codecs/DisableVideoCodecsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/codecs/DisableVideoCodecsPatch.kt @@ -1,7 +1,6 @@ package app.revanced.patches.youtube.video.codecs import app.revanced.patcher.extensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.methodReference import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources @@ -11,7 +10,9 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch +import app.revanced.util.getReference import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/DisableVideoCodecsPatch;" @@ -34,7 +35,7 @@ val disableVideoCodecsPatch = bytecodePatch( return@filterMap null } - val reference = instruction.methodReference + val reference = instruction.getReference() if (reference?.definingClass == "Landroid/view/Display\$HdrCapabilities;" && reference.name == "getSupportedHdrTypes") { return@filterMap instruction to instructionIndex } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index ab86563445..26117af4df 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -23,6 +23,7 @@ import app.revanced.patches.youtube.video.videoid.hookVideoId import app.revanced.patches.youtube.video.videoid.videoIdPatch import app.revanced.util.addInstructionsAtControlFlowLabel import app.revanced.util.addStaticFieldToExtension +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.patcher.patch.PatchException import com.android.tools.smali.dexlib2.AccessFlags @@ -104,7 +105,7 @@ val videoInformationPatch = bytecodePatch( // Find the location of the first invoke-direct call // and extract the register storing the 'this' object reference. val initThisIndex = playerInitMethod.indexOfFirstInstructionOrThrow { - opcode == Opcode.INVOKE_DIRECT && methodReference?.name == "" + opcode == Opcode.INVOKE_DIRECT && getReference()?.name == "" } playerInitInsertRegister = playerInitMethod.getInstruction(initThisIndex).registerC @@ -122,7 +123,7 @@ val videoInformationPatch = bytecodePatch( mdxInitMethod = classDef.methods.first { MethodUtil.isConstructor(it) } val initThisIndex = mdxInitMethod.indexOfFirstInstructionOrThrow { - opcode == Opcode.INVOKE_DIRECT && methodReference?.name == "" + opcode == Opcode.INVOKE_DIRECT && getReference()?.name == "" } mdxInitInsertRegister = mdxInitMethod.getInstruction(initThisIndex).registerC @@ -200,7 +201,7 @@ val videoInformationPatch = bytecodePatch( setPlaybackSpeedMethodReference = getInstruction( indexOfFirstInstructionOrThrow(speedSelectionValueInstructionIndex) { - val reference = methodReference + val reference = getReference() reference?.parameterTypes?.size == 1 && reference.parameterTypes.first() == "F" } ).reference as MethodReference @@ -230,7 +231,7 @@ val videoInformationPatch = bytecodePatch( setPlaybackSpeedClassFieldReference = getInstruction( indexOfFirstInstructionOrThrow(speedSelectionValueInstructionIndex) { - fieldReference?.type?.startsWith("L") == true + getReference()?.type?.startsWith("L") == true } ).reference as FieldReference @@ -397,6 +398,7 @@ val videoInformationPatch = bytecodePatch( // Detect video quality changes and override the current quality. videoQualitySetterMethod.immutableClassDef.getSetVideoQualityMethod().let { + it // This instruction refers to the field with the type that contains the setQuality method. val onItemClickListenerClassReference = it.getInstruction(0).reference diff --git a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index 775189b74a..5694608dfe 100644 --- a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -21,7 +21,9 @@ import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.MethodParameter import com.android.tools.smali.dexlib2.iface.instruction.* import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.Reference +import com.android.tools.smali.dexlib2.iface.reference.StringReference import com.android.tools.smali.dexlib2.iface.value.* import com.android.tools.smali.dexlib2.immutable.ImmutableField import com.android.tools.smali.dexlib2.immutable.ImmutableMethod @@ -38,7 +40,7 @@ import kotlin.collections.remove */ private fun Method.findInstructionIndexFromToString(fieldName: String): Int { val stringIndex = indexOfFirstInstruction { - val reference = stringReference + val reference = getReference() reference?.string?.contains(fieldName) == true } if (stringIndex < 0) { @@ -48,7 +50,7 @@ private fun Method.findInstructionIndexFromToString(fieldName: String): Int { // Find use of the string with a StringBuilder. val stringUsageIndex = indexOfFirstInstruction(stringIndex) { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Ljava/lang/StringBuilder;" && (this as? FiveRegisterInstruction)?.registerD == stringRegister } @@ -58,7 +60,7 @@ private fun Method.findInstructionIndexFromToString(fieldName: String): Int { // Find the next usage of StringBuilder, which should be the desired field. val fieldUsageIndex = indexOfFirstInstruction(stringUsageIndex + 1) { - val reference = methodReference + val reference = getReference() reference?.definingClass == "Ljava/lang/StringBuilder;" && reference.name == "append" } if (fieldUsageIndex < 0) { @@ -102,7 +104,7 @@ internal fun Method.findMethodFromToString(fieldName: String): MutableMethod { */ internal fun Method.findFieldFromToString(fieldName: String): FieldReference { val methodUsageIndex = findInstructionIndexFromToString(fieldName) - return getInstruction(methodUsageIndex).fieldReference!! + return getInstruction(methodUsageIndex).getReference()!! } /** @@ -378,8 +380,6 @@ fun BytecodePatchContext.traverseClassHierarchy(targetClass: MutableClassDef, ca * if the [Instruction] is not a [ReferenceInstruction] or the [Reference] is not of type [T]. * @see ReferenceInstruction */ -@Deprecated("Instead use `methodReference`, `fieldReference`, `typeReference` or `stringReference`") -@Suppress("unused") inline fun Instruction.getReference() = (this as? ReferenceInstruction)?.reference as? T /** diff --git a/patches/src/main/kotlin/app/revanced/util/FreeRegisterProvider.kt b/patches/src/main/kotlin/app/revanced/util/FreeRegisterProvider.kt index b2dc14bccb..c309e05368 100644 --- a/patches/src/main/kotlin/app/revanced/util/FreeRegisterProvider.kt +++ b/patches/src/main/kotlin/app/revanced/util/FreeRegisterProvider.kt @@ -2,7 +2,6 @@ package app.revanced.util import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.extensions.reference import app.revanced.util.FreeRegisterProvider.Companion.conditionalBranchOpcodes import app.revanced.util.FreeRegisterProvider.Companion.logFreeRegisterSearch import app.revanced.util.FreeRegisterProvider.Companion.returnOpcodes @@ -346,7 +345,7 @@ private fun Method.findFreeRegistersInternal( // If it appears more than once, it's also read. if (occurrences <= 1) { if (logFreeRegisterSearch) println("Found free register at $i: $writeRegister " + - "opcode: " + instruction.opcode + " reference: " + (instruction.reference)) + "opcode: " + instruction.opcode + " reference: " + (instruction.getReference())) freeRegisters.add(writeRegister) // If the requested number of free registers is found and this is not a branch, // then no additional searching is needed.