Skip to content

Commit

Permalink
feat: hdr-max-brightness patch (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 3, 2022
1 parent 31a767a commit 1310573
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.extensions.removeInstructions
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.hdrbrightness.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.24.34", "17.24.35", "17.25.34")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class HDRBrightnessCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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("hdrbrightness-fingerprint")
@MatchingMethod(
"Lghz;", "mZ"
)
@FuzzyPatternScanMethod(3)
@HDRBrightnessCompatibility
@Version("0.0.1")
object HDRBrightnessFingerprint : MethodFingerprint(
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, null,
listOf(
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST_HIGH16,
Opcode.IPUT,
Opcode.INVOKE_VIRTUAL
),
null,
customFingerprint = { methodDef ->
methodDef.implementation!!.instructions.count() == 16 && methodDef.implementation!!.instructions.any {((it as? NarrowLiteralInstruction)?.narrowLiteral == (-1.0f).toRawBits())}
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package app.revanced.patches.youtube.misc.hdrbrightness.patch;

import app.revanced.patcher.annotation.Description;
import app.revanced.patcher.annotation.Name;
import app.revanced.patcher.annotation.Version;
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.removeInstruction
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch;
import app.revanced.patcher.patch.impl.BytecodePatch;
import app.revanced.patcher.util.smali.toBuilderInstruction
import app.revanced.patches.youtube.misc.hdrbrightness.annotations.HDRBrightnessCompatibility;
import app.revanced.patches.youtube.misc.hdrbrightness.fingerprints.HDRBrightnessFingerprint
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction

@Patch
@Name("hdr-max-brightness")
@Description("Set brightness to max for HDR videos in fullscreen mode.")
@HDRBrightnessCompatibility
@Version("0.0.1")
class HDRBrightnessPatch : BytecodePatch(
listOf(
HDRBrightnessFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
val result = HDRBrightnessFingerprint.result
?: return PatchResultError("HDRBrightnessFingerprint could not resolve the method!")


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, """
invoke-static {v$register}, Lapp/revanced/integrations/patches/HDRMaxBrightnessPatch;->getHDRBrightness(F)F
move-result v$register
"""
)

return PatchResultSuccess()
}
}

0 comments on commit 1310573

Please sign in to comment.