Skip to content

Commit

Permalink
fix(hdr-auto-brightness): increase patching compatibility across vers…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
oSumAtrIX committed Sep 18, 2022
1 parent b9b1526 commit bc5c8c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 85 deletions.
Expand Up @@ -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"),
)

This file was deleted.

Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -44,32 +40,25 @@ class HDRBrightnessPatch : BytecodePatch(
)
)

val result = try {
HDRBrightnessFingerprintYEL.result!!
} catch (e: Exception) {
HDRBrightnessFingerprintYJK.result!!
}

val method = result.mutableMethod
val method = HDRBrightnessFingerprint.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()
}
}

0 comments on commit bc5c8c1

Please sign in to comment.