diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/annotations/HDRBrightnessCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/annotations/HDRBrightnessCompatibility.kt index e00c9b5d0..035ed5706 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/annotations/HDRBrightnessCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/annotations/HDRBrightnessCompatibility.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.annotation.Package @Compatibility( [Package( - "com.google.android.youtube", arrayOf("17.24.34", "17.24.35", "17.25.34", "17.26.35") + "com.google.android.youtube", arrayOf("17.25.34", "17.26.35") )] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGHZ.kt similarity index 65% rename from src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGHZ.kt index a46d9ad26..d8e150de8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGHZ.kt @@ -11,25 +11,34 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction -@Name("hdrbrightness-fingerprint") +@Name("hdr-brightness-fingerprint-ghz") @MatchingMethod( - "Lghz;", "mZ" + "Lghz;", "g" ) @FuzzyPatternScanMethod(3) @HDRBrightnessCompatibility @Version("0.0.1") -object HDRBrightnessFingerprint : MethodFingerprint( +object HDRBrightnessFingerprintGHZ : MethodFingerprint( "V", AccessFlags.PUBLIC or AccessFlags.FINAL, null, listOf( + /* WindowManager.LayoutParams lp = br.getWindow().getAttributes(); + * lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL; + * br.getWindow().setAttributes(lp); + */ + Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT, Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT, Opcode.CONST_HIGH16, Opcode.IPUT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, Opcode.INVOKE_VIRTUAL ), null, customFingerprint = { methodDef -> - methodDef.implementation!!.instructions.count() == 16 && methodDef.implementation!!.instructions.any {((it as? NarrowLiteralInstruction)?.narrowLiteral == (-1.0f).toRawBits())} + methodDef.implementation!!.instructions.count() == 16 && methodDef.implementation!!.instructions.any { + ((it as? NarrowLiteralInstruction)?.narrowLiteral == (/*BRIGHTNESS_OVERRIDE_FULL*/ 1.0f).toRawBits()) + } } -) \ No newline at end of file +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGUL.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGUL.kt new file mode 100644 index 000000000..e3bfa6477 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintGUL.kt @@ -0,0 +1,44 @@ +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.NarrowLiteralInstruction + +@Name("hdr-brightness-fingerprint-gul") +@MatchingMethod( + "Lgul;", "g" +) +@FuzzyPatternScanMethod(3) +@HDRBrightnessCompatibility +@Version("0.0.1") +object HDRBrightnessFingerprintGUL : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, null, + listOf( + /* WindowManager.LayoutParams lp = br.getWindow().getAttributes(); + * lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL; + * br.getWindow().setAttributes(lp); + */ + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_HIGH16, + Opcode.IPUT, + //Opcode.INVOKE_VIRTUAL, + //Opcode.MOVE_RESULT_OBJECT, + //Opcode.INVOKE_VIRTUAL + ), + null, + customFingerprint = { methodDef -> + methodDef.implementation!!.instructions.count() == 14 && methodDef.implementation!!.instructions.any { + ((it as? NarrowLiteralInstruction)?.narrowLiteral == (/*BRIGHTNESS_OVERRIDE_FULL*/ 1.0f).toRawBits()) + } + } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintTIO.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintTIO.kt new file mode 100644 index 000000000..5d7d35a8e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintTIO.kt @@ -0,0 +1,44 @@ +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.NarrowLiteralInstruction + +@Name("hdr-brightness-fingerprint-tio") +@MatchingMethod( + "Ltio;", "g" +) +@FuzzyPatternScanMethod(3) +@HDRBrightnessCompatibility +@Version("0.0.1") +object HDRBrightnessFingerprintTIO : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, null, + listOf( + /* WindowManager.LayoutParams lp = br.getWindow().getAttributes(); + * lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL; + * br.getWindow().setAttributes(lp); + */ + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_HIGH16, + Opcode.IPUT, + //Opcode.INVOKE_VIRTUAL, + //Opcode.MOVE_RESULT_OBJECT, + //Opcode.INVOKE_VIRTUAL + ), + null, + customFingerprint = { methodDef -> + methodDef.implementation!!.instructions.count() == 22 && methodDef.implementation!!.instructions.any { + ((it as? NarrowLiteralInstruction)?.narrowLiteral == (/*BRIGHTNESS_OVERRIDE_FULL*/ 1.0f).toRawBits()) + } + } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintXXZ.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintXXZ.kt new file mode 100644 index 000000000..06b3b9c7d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/hdrbrightness/fingerprints/HDRBrightnessFingerprintXXZ.kt @@ -0,0 +1,44 @@ +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( + "Lxxz;", "G" +) +@FuzzyPatternScanMethod(3) +@HDRBrightnessCompatibility +@Version("0.0.1") +object HDRBrightnessFingerprintXXZ : 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 + ), + null, + 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 5fdfd6a72..8d85d0251 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 @@ -8,41 +8,49 @@ import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Dependencies 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.HDRBrightnessFingerprint -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprintXXZ +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction +import org.jf.dexlib2.iface.reference.FieldReference -@Patch -@Name("hdr-max-brightness") -@Description("Sets brightness to max for HDR videos in fullscreen mode.") +@Patch(false) +@Name("hdr-auto-brightness") +@Description("Makes the brightness of HDR videos follow the system default.") @HDRBrightnessCompatibility -@Version("0.0.1") +@Version("0.0.2") +@Dependencies([IntegrationsPatch::class]) class HDRBrightnessPatch : BytecodePatch( listOf( - HDRBrightnessFingerprint + HDRBrightnessFingerprintXXZ ) ) { override fun execute(data: BytecodeData): PatchResult { - val result = HDRBrightnessFingerprint.result + val method = HDRBrightnessFingerprintXXZ.result?.mutableMethod ?: return PatchResultError("HDRBrightnessFingerprint could not resolve the method!") + 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 + }.forEach { instruction -> + // inject right before the call that sets 'screenBrightness' + val index = method.implementation!!.instructions.indexOf(instruction) + val register = (instruction as TwoRegisterInstruction).registerA - val method = result.mutableMethod - - //Get the index here, so we know where to inject our code to override -1.0f - val index = method.implementation!!.instructions.indexOfFirst { ((it as? NarrowLiteralInstruction)?.narrowLiteral == (-1.0f).toRawBits()) } - val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA - - method.addInstructions( - index + 1, """ + // inject the call to + method.addInstructions( + index, """ invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRMaxBrightnessPatch;->getHDRBrightness(F)F move-result v$register """ - ) - + ) + } return PatchResultSuccess() } }