diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYJK.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt similarity index 50% rename from src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYJK.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt index 76250ebae..4f3bb1e0e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYJK.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt @@ -2,30 +2,17 @@ package app.revanced.patches.youtube.misc.hdrbrightness.fingerprints import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility -import org.jf.dexlib2.Opcode -@Name("hdr-brightness-fingerprint-xxz") +@Name("hdr-brightness-fingerprint") @MatchingMethod( - "Lyjk;", "D" + "Lyls;", "c" ) -@FuzzyPatternScanMethod(3) @HDRBrightnessCompatibility @Version("0.0.1") -object HDRBrightnessFingerprintYJK : MethodFingerprint( +object HDRBrightnessFingerprint : MethodFingerprint( "V", - opcodes = listOf( - Opcode.SGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IGET, - Opcode.IPUT, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL - ), - strings = listOf("c.SettingNotFound;", "screen_brightness", "android.mediaview"), + strings = listOf("c.SettingNotFound;", "screen_brightness", "android.mediaview", "lux"), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYEL.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYEL.kt deleted file mode 100644 index 6223dfc03..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintYEL.kt +++ /dev/null @@ -1,43 +0,0 @@ -package app.revanced.patches.youtube.misc.hdrbrightness.fingerprints - -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod -import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.reference.FieldReference - -@Name("hdr-brightness-fingerprint-xxz") -@MatchingMethod( - "Lyel;", "G" -) -@FuzzyPatternScanMethod(3) -@HDRBrightnessCompatibility -@Version("0.0.1") -object HDRBrightnessFingerprintYEL : MethodFingerprint( - "V", AccessFlags.PUBLIC or AccessFlags.FINAL, - listOf("I", "I", "I", "I"), - listOf( - Opcode.SGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IGET, - Opcode.IPUT, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL - ), - customFingerprint = { methodDef -> - methodDef.implementation!!.instructions.any { - ((it as? ReferenceInstruction)?.reference as? FieldReference)?.let { field -> - // iput vx, vy, Landroid/view/WindowManager$LayoutParams;->screenBrightness:F - field.definingClass == "Landroid/view/WindowManager\$LayoutParams;" && field.name == "screenBrightness" - } == true - } - } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch.kt index 3114c3b01..de45669d3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch.kt @@ -11,8 +11,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility -import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprintYEL -import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprintYJK +import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource @@ -28,10 +27,7 @@ import org.jf.dexlib2.iface.reference.FieldReference @Version("0.0.2") @DependsOn([IntegrationsPatch::class, SettingsPatch::class]) class HDRBrightnessPatch : BytecodePatch( - listOf( - HDRBrightnessFingerprintYEL, - HDRBrightnessFingerprintYJK - ) + listOf(HDRBrightnessFingerprint) ) { override fun execute(data: BytecodeData): PatchResult { SettingsPatch.PreferenceScreen.MISC.addPreferences( @@ -44,32 +40,25 @@ class HDRBrightnessPatch : BytecodePatch( ) ) - val result = try { - HDRBrightnessFingerprintYEL.result!! - } catch (e: Exception) { - HDRBrightnessFingerprintYJK.result!! - } + val method = HDRBrightnessFingerprint.result!!.mutableMethod - val method = result.mutableMethod - - method.implementation!!.instructions.filter { - ((it as? ReferenceInstruction)?.reference as? FieldReference)?.let { field -> - // iput vx, vy, Landroid/view/WindowManager$LayoutParams;->screenBrightness:F - field.definingClass == "Landroid/view/WindowManager\$LayoutParams;" && field.name == "screenBrightness" - } == true + method.implementation!!.instructions.filter { instruction -> + val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference + fieldReference?.let { it.name == "screenBrightness" } == true }.forEach { instruction -> - // inject right before the call that sets 'screenBrightness' - val index = method.implementation!!.instructions.indexOf(instruction) + val brightnessRegisterIndex = method.implementation!!.instructions.indexOf(instruction) val register = (instruction as TwoRegisterInstruction).registerA - // inject the call to + val insertIndex = brightnessRegisterIndex + 1 method.addInstructions( - index, """ - invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRAutoBrightnessPatch;->getHDRBrightness(F)F - move-result v$register - """ + insertIndex, + """ + invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRAutoBrightnessPatch;->getHDRBrightness(F)F + move-result v$register + """ ) } + return PatchResultSuccess() } }