From df8af2838dd5722a08159b43a8e46d4ce691f441 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 13 Oct 2023 23:27:33 +0900 Subject: [PATCH] fix(YouTube/Bypass ambient mode restrictions): apply fingerprint compatible with wider version --- .../misc/ambientmode/PowerSaveModePatch.kt | 21 +++-------- .../PowerSaveModeAlternativeFingerprint.kt | 23 ------------ .../fingerprints/PowerSaveModeFingerprint.kt | 35 ++++++++++++++----- .../utils/resourceid/SharedResourceIdPatch.kt | 2 -- 4 files changed, 31 insertions(+), 50 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeAlternativeFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt index 8ef784d0e..e6af30678 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt @@ -8,9 +8,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.youtube.misc.ambientmode.fingerprints.PowerSaveModeAlternativeFingerprint import app.revanced.patches.youtube.misc.ambientmode.fingerprints.PowerSaveModeFingerprint -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.integrations.Constants.MISC_PATH import com.android.tools.smali.dexlib2.Opcode @@ -21,10 +19,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( name = "Bypass ambient mode restrictions", description = "Bypass ambient mode restrictions in battery saver mode.", - dependencies = [ - SettingsPatch::class, - SharedResourceIdPatch::class - ], + dependencies = [SettingsPatch::class], compatiblePackages = [ CompatiblePackage( "com.google.android.youtube", @@ -46,19 +41,11 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference ) @Suppress("unused") object PowerSaveModePatch : BytecodePatch( - setOf( - PowerSaveModeAlternativeFingerprint, - PowerSaveModeFingerprint - ) + setOf(PowerSaveModeFingerprint) ) { override fun execute(context: BytecodeContext) { - val result = - PowerSaveModeFingerprint.result - ?: PowerSaveModeAlternativeFingerprint.result - ?: throw PowerSaveModeFingerprint.exception - - result.let { + PowerSaveModeFingerprint.result?.let { it.mutableMethod.apply { var insertIndex = -1 @@ -82,7 +69,7 @@ object PowerSaveModePatch : BytecodePatch( if (insertIndex == -1) throw PatchException("Couldn't find PowerManager reference") } - } + } ?: throw PowerSaveModeFingerprint.exception /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeAlternativeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeAlternativeFingerprint.kt deleted file mode 100644 index 1c88dd4e2..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeAlternativeFingerprint.kt +++ /dev/null @@ -1,23 +0,0 @@ -package app.revanced.patches.youtube.misc.ambientmode.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.util.bytecode.isNarrowLiteralExists -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -object PowerSaveModeAlternativeFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("Ljava/lang/Object;"), - opcodes = listOf( - Opcode.IF_GT, - Opcode.IGET, - Opcode.ADD_INT_2ADDR - ), - customFingerprint = { methodDef, _ -> - methodDef.isNarrowLiteralExists(107243) && methodDef.isNarrowLiteralExists( - 140796 - ) && methodDef.name == "accept" - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt index c39df19c2..a36f83b7d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt @@ -2,19 +2,38 @@ package app.revanced.patches.youtube.misc.ambientmode.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.YtBrandBackgroundSolid -import app.revanced.util.bytecode.isWideLiteralExists import com.android.tools.smali.dexlib2.AccessFlags 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 object PowerSaveModeFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("Ljava/lang/Object;"), - opcodes = listOf( - Opcode.IF_GT, - Opcode.IGET, - Opcode.ADD_INT_2ADDR - ), - customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(YtBrandBackgroundSolid) && methodDef.name == "accept" } + customFingerprint = custom@{ methodDef, _ -> + if (methodDef.name != "accept") + return@custom false + + val instructions = methodDef.implementation?.instructions!! + + if (instructions.count() < 20) + return@custom false + + var count = 0; + for (instruction in instructions) { + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) + continue + + val invokeInstruction = instruction as Instruction35c + if ((invokeInstruction.reference as MethodReference).name != "isPowerSaveMode") + continue + + count++ + } + if (count < 2) + return@custom false + + count == 2 + } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 41c6e8fd4..8b712b41b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -82,7 +82,6 @@ object SharedResourceIdPatch : ResourcePatch() { var VideoZoomIndicatorLayout: Long = -1 var WordMarkHeader: Long = -1 var YoutubeControlsOverlay: Long = -1 - var YtBrandBackgroundSolid: Long = -1 var YtOutlineArrowTimeBlack: Long = -1 var YtOutlineFireBlack: Long = -1 var YtOutlineSearchBlack: Long = -1 @@ -163,7 +162,6 @@ object SharedResourceIdPatch : ResourcePatch() { VideoZoomIndicatorLayout = find(ID, "video_zoom_indicator_layout") WordMarkHeader = find(ATTR, "ytWordmarkHeader") YoutubeControlsOverlay = find(ID, "youtube_controls_overlay") - YtBrandBackgroundSolid = find(ATTR, "ytBrandBackgroundSolid") YtOutlineArrowTimeBlack = find(DRAWABLE, "yt_outline_arrow_time_black_24") YtOutlineFireBlack = find(DRAWABLE, "yt_outline_fire_black_24") YtOutlineSearchBlack = find(DRAWABLE, "yt_outline_search_black_24")