mirror of
https://github.com/revanced/revanced-patches
synced 2024-11-10 13:49:25 +01:00
fix(hdr-auto-brightness): increase patching compatibility across versions
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
136e1b7124
commit
f883e72dce
@ -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"),
|
||||
)
|
@ -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
|
||||
}
|
||||
}
|
||||
)
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user