refactor: improve weak fingerprints

This commit is contained in:
inotia00
2023-04-09 00:36:14 +09:00
parent 4e8c8a63c6
commit 1e4cf284c3
7 changed files with 80 additions and 33 deletions

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.layout.player.previousnextbutton.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction
object SupportsNextPreviousFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("Z"),
opcodes = listOf(Opcode.OR_INT_LIT8),
customFingerprint = { methodDef ->
methodDef.implementation!!.instructions.any {
((it as? NarrowLiteralInstruction)?.narrowLiteral == 64)
}
}
)

View File

@ -6,7 +6,6 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -15,6 +14,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint
import app.revanced.patches.youtube.layout.player.previousnextbutton.fingerprints.SupportsNextPreviousFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.PLAYER
@ -29,18 +29,14 @@ class HidePreviousNextButtonPatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext): PatchResult {
val controlsOverlayStyleClassDef = ControlsOverlayStyleFingerprint.result?.classDef?: return ControlsOverlayStyleFingerprint.toErrorResult()
val previousNextButtonVisibleFingerprint =
object : MethodFingerprint(returnType = "V", parameters = listOf("Z"), customFingerprint = { it.name == "j" }) {}
previousNextButtonVisibleFingerprint.resolve(context, controlsOverlayStyleClassDef)
previousNextButtonVisibleFingerprint.result?.mutableMethod?.addInstructions(
0, """
invoke-static {p1}, $PLAYER->hidePreviousNextButton(Z)Z
move-result p1
"""
)?: return previousNextButtonVisibleFingerprint.toErrorResult()
ControlsOverlayStyleFingerprint.result?.let { parentResult ->
SupportsNextPreviousFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstructions(
0, """
invoke-static {p1}, $PLAYER->hidePreviousNextButton(Z)Z
move-result p1
"""
) ?: return SupportsNextPreviousFingerprint.toErrorResult()
} ?: return ControlsOverlayStyleFingerprint.toErrorResult()
/*
* Add settings

View File

@ -0,0 +1,10 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object ProgressColorFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("I"),
opcodes = listOf(Opcode.OR_INT_LIT8)
)

View File

@ -6,7 +6,6 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
@ -15,6 +14,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.ProgressColorFingerprint
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.SeekbarColorFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
@ -57,17 +57,14 @@ class SeekbarColorPatch : BytecodePatch(
}
} ?: return SeekbarColorFingerprint.toErrorResult()
val controlsOverlayStyleClassDef = ControlsOverlayStyleFingerprint.result?.classDef?: return ControlsOverlayStyleFingerprint.toErrorResult()
val progressColorFingerprint =
object : MethodFingerprint(returnType = "V", parameters = listOf("I"), customFingerprint = { it.name == "e" }) {}
progressColorFingerprint.resolve(context, controlsOverlayStyleClassDef)
progressColorFingerprint.result?.mutableMethod?.addInstructions(
0, """
invoke-static {p1}, $SEEKBAR->enableCustomSeekbarColor(I)I
move-result p1
"""
)?: return progressColorFingerprint.toErrorResult()
ControlsOverlayStyleFingerprint.result?.let { parentResult ->
ProgressColorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstructions(
0, """
invoke-static {p1}, $SEEKBAR->enableCustomSeekbarColor(I)I
move-result p1
"""
) ?: return ProgressColorFingerprint.toErrorResult()
} ?: return ControlsOverlayStyleFingerprint.toErrorResult()
/*
* Add settings