chore: lint code

This commit is contained in:
inotia00
2024-06-07 21:44:22 +09:00
parent e374fa306b
commit ecd6fbdf5b
95 changed files with 804 additions and 405 deletions

View File

@ -45,13 +45,15 @@ object AmbientModeSwitchPatch : BaseBytecodePatch(
PowerSaveModeSyntheticFingerprint to true
).forEach { (fingerprint, reversed) ->
fingerprint.resultOrThrow().mutableMethod.apply {
val stringIndex = getStringInstructionIndex("android.os.action.POWER_SAVE_MODE_CHANGED")
val stringIndex =
getStringInstructionIndex("android.os.action.POWER_SAVE_MODE_CHANGED")
val targetIndex =
if (reversed)
getTargetIndexReversed(stringIndex, Opcode.INVOKE_DIRECT)
else
getTargetIndex(stringIndex, Opcode.INVOKE_DIRECT)
val targetClass = (getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference).definingClass
val targetClass =
(getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference).definingClass
syntheticClassList += targetClass
}

View File

@ -126,16 +126,20 @@ object PlayerButtonsPatch : BaseBytecodePatch(
TitleAnchorFingerprint.resultOrThrow().mutableMethod.apply {
val titleAnchorConstIndex = getWideLiteralInstructionIndex(TitleAnchor)
val titleAnchorIndex = getTargetIndex(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
val titleAnchorRegister = getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA
val titleAnchorRegister =
getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA
addInstruction(
titleAnchorIndex + 1,
"invoke-static {v$titleAnchorRegister}, $PLAYER_CLASS_DESCRIPTOR->setTitleAnchorStartMargin(Landroid/view/View;)V"
)
val playerCollapseButtonConstIndex = getWideLiteralInstructionIndex(PlayerCollapseButton)
val playerCollapseButtonIndex = getTargetIndex(playerCollapseButtonConstIndex, Opcode.CHECK_CAST)
val playerCollapseButtonRegister = getInstruction<OneRegisterInstruction>(playerCollapseButtonIndex).registerA
val playerCollapseButtonConstIndex =
getWideLiteralInstructionIndex(PlayerCollapseButton)
val playerCollapseButtonIndex =
getTargetIndex(playerCollapseButtonConstIndex, Opcode.CHECK_CAST)
val playerCollapseButtonRegister =
getInstruction<OneRegisterInstruction>(playerCollapseButtonIndex).registerA
addInstruction(
playerCollapseButtonIndex + 1,

View File

@ -37,6 +37,7 @@ object CommentsComponentPatch : BaseBytecodePatch(
) {
private const val FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/CommentsFilter;"
override fun execute(context: BytecodeContext) {
// region patch for emoji picker button in shorts
@ -44,7 +45,7 @@ object CommentsComponentPatch : BaseBytecodePatch(
ShortsLiveStreamEmojiPickerOpacityFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
val insertRegister= getInstruction<OneRegisterInstruction>(insertIndex).registerA
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstruction(
insertIndex,
@ -56,12 +57,15 @@ object CommentsComponentPatch : BaseBytecodePatch(
ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492)
val emojiPickerOnClickListenerIndex = getTargetIndex(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
val emojiPickerOnClickListenerMethod = getWalkerMethod(context, emojiPickerOnClickListenerIndex)
val emojiPickerOnClickListenerIndex =
getTargetIndex(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT)
val emojiPickerOnClickListenerMethod =
getWalkerMethod(context, emojiPickerOnClickListenerIndex)
emojiPickerOnClickListenerMethod.apply {
val insertIndex = getTargetIndex(Opcode.IF_EQZ)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex, """

View File

@ -170,7 +170,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
LayoutCircleFingerprint,
LayoutIconFingerprint,
LayoutVideoFingerprint
).forEach{ fingerprint ->
).forEach { fingerprint ->
fingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
@ -205,9 +205,10 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val insertIndex = getTargetIndexReversed(constIndex, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex = implementation!!.instructions.let { instruction ->
insertIndex + instruction.subList(insertIndex, instruction.size - 1).indexOfFirst { instructions ->
instructions.opcode == Opcode.GOTO || instructions.opcode == Opcode.GOTO_16
}
insertIndex + instruction.subList(insertIndex, instruction.size - 1)
.indexOfFirst { instructions ->
instructions.opcode == Opcode.GOTO || instructions.opcode == Opcode.GOTO_16
}
}
val replaceInstruction = getInstruction<TwoRegisterInstruction>(insertIndex)
@ -270,7 +271,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val insertIndex = getWideLiteralInstructionIndex(SeekUndoEduOverlayStub)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val onClickListenerIndex = getTargetIndexWithMethodReferenceName(insertIndex, "setOnClickListener")
val onClickListenerIndex =
getTargetIndexWithMethodReferenceName(insertIndex, "setOnClickListener")
val constComponent = getConstComponent(insertIndex, onClickListenerIndex - 1)
if (constComponent.isNotEmpty()) {
@ -315,8 +317,10 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableClass.methods.find { method ->
method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;")
}?.apply {
val setOnClickListenerIndex = getTargetIndexWithMethodReferenceName("setOnClickListener")
val setOnClickListenerRegister = getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceName("setOnClickListener")
val setOnClickListenerRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC
addInstruction(
setOnClickListenerIndex + 1,

View File

@ -110,8 +110,10 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
EngagementPanelTitleParentFingerprint.resultOrThrow().classDef
)
EngagementPanelTitleFingerprint.resultOrThrow().mutableMethod.apply {
val contentDescriptionIndex = getTargetIndexWithMethodReferenceName("setContentDescription")
val contentDescriptionRegister = getInstruction<FiveRegisterInstruction>(contentDescriptionIndex).registerD
val contentDescriptionIndex =
getTargetIndexWithMethodReferenceName("setContentDescription")
val contentDescriptionRegister =
getInstruction<FiveRegisterInstruction>(contentDescriptionIndex).registerD
addInstruction(
contentDescriptionIndex,

View File

@ -2,7 +2,7 @@ package app.revanced.patches.youtube.player.flyoutmenu.hide.fingerprints
import app.revanced.util.fingerprint.LiteralValueFingerprint
/**
/**
* This fingerprint is compatible with YouTube v18.39.xx+
*/
internal object PiPModeConfigFingerprint : LiteralValueFingerprint(

View File

@ -46,11 +46,14 @@ object ChangeTogglePatch : BaseBytecodePatch(
) {
override fun execute(context: BytecodeContext) {
val additionalSettingsConfigMethod = AdditionalSettingsConfigFingerprint.resultOrThrow().mutableMethod
val methodToCall = additionalSettingsConfigMethod.definingClass + "->" + additionalSettingsConfigMethod.name + "()Z"
val additionalSettingsConfigMethod =
AdditionalSettingsConfigFingerprint.resultOrThrow().mutableMethod
val methodToCall =
additionalSettingsConfigMethod.definingClass + "->" + additionalSettingsConfigMethod.name + "()Z"
// Resolves fingerprints
val playbackLoopOnClickListenerResult = PlaybackLoopOnClickListenerFingerprint.resultOrThrow()
val playbackLoopOnClickListenerResult =
PlaybackLoopOnClickListenerFingerprint.resultOrThrow()
PlaybackLoopInitFingerprint.resolve(context, playbackLoopOnClickListenerResult.classDef)
var fingerprintArray = arrayOf(
@ -90,7 +93,8 @@ object ChangeTogglePatch : BaseBytecodePatch(
it.mutableMethod.apply {
val referenceIndex = indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL
&& (this as ReferenceInstruction).reference.toString().endsWith(methodToCall)
&& (this as ReferenceInstruction).reference.toString()
.endsWith(methodToCall)
}
if (referenceIndex > 0) {
val insertRegister =
@ -117,12 +121,14 @@ object ChangeTogglePatch : BaseBytecodePatch(
val stringReferenceIndex = stableVolumeMethod.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL
&& (this as ReferenceInstruction).reference.toString().endsWith("(Ljava/lang/String;Ljava/lang/String;)V")
&& (this as ReferenceInstruction).reference.toString()
.endsWith("(Ljava/lang/String;Ljava/lang/String;)V")
}
if (stringReferenceIndex < 0)
throw PatchException("Target reference was not found in ${StableVolumeFingerprint.javaClass.simpleName}.")
val stringReference = stableVolumeMethod.getInstruction<ReferenceInstruction>(stringReferenceIndex).reference
val stringReference =
stableVolumeMethod.getInstruction<ReferenceInstruction>(stringReferenceIndex).reference
CinematicLightingFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
@ -135,15 +141,20 @@ object ChangeTogglePatch : BaseBytecodePatch(
val stringIndex = getStringInstructionIndex("menu_item_cinematic_lighting")
val checkCastIndex = getTargetIndexReversed(stringIndex, Opcode.CHECK_CAST)
val iGetObjectPrimaryIndex = getTargetIndexReversed(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectPrimaryIndex =
getTargetIndexReversed(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectSecondaryIndex = getTargetIndex(checkCastIndex, Opcode.IGET_OBJECT)
val checkCastReference = getInstruction<ReferenceInstruction>(checkCastIndex).reference
val iGetObjectPrimaryReference = getInstruction<ReferenceInstruction>(iGetObjectPrimaryIndex).reference
val iGetObjectSecondaryReference = getInstruction<ReferenceInstruction>(iGetObjectSecondaryIndex).reference
val checkCastReference =
getInstruction<ReferenceInstruction>(checkCastIndex).reference
val iGetObjectPrimaryReference =
getInstruction<ReferenceInstruction>(iGetObjectPrimaryIndex).reference
val iGetObjectSecondaryReference =
getInstruction<ReferenceInstruction>(iGetObjectSecondaryIndex).reference
val invokeVirtualIndex = getTargetIndex(stringIndex, Opcode.INVOKE_VIRTUAL)
val invokeVirtualInstruction = getInstruction<FiveRegisterInstruction>(invokeVirtualIndex)
val invokeVirtualInstruction =
getInstruction<FiveRegisterInstruction>(invokeVirtualIndex)
val freeRegisterC = invokeVirtualInstruction.registerC
val freeRegisterD = invokeVirtualInstruction.registerD
val freeRegisterE = invokeVirtualInstruction.registerE

View File

@ -182,7 +182,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
val walkerMethod = getWalkerMethod(context, walkerIndex)
walkerMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
val targetRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val targetRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex, """
@ -288,7 +289,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
LandScapeModeConfigFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex, """
@ -300,7 +302,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
BroadcastReceiverFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val stringIndex = getStringInstructionIndex("android.intent.action.SCREEN_ON")
val stringIndex =
getStringInstructionIndex("android.intent.action.SCREEN_ON")
val insertIndex = getTargetIndex(stringIndex, Opcode.IF_EQZ) + 1
addInstruction(

View File

@ -89,22 +89,29 @@ object OverlayButtonsBytecodePatch : BytecodePatch(
&& getReference<FieldReference>()?.definingClass == definingClass
&& (this as TwoRegisterInstruction).registerA == registerResolver
}
val invokerObjectReference = getInstruction<ReferenceInstruction>(invokerObjectIndex).reference
val invokerObjectReference =
getInstruction<ReferenceInstruction>(invokerObjectIndex).reference
val onClickListenerReferenceIndex = getTargetIndexWithReference("<init>(Ljava/lang/Object;I[B)V")
val onClickListenerReference = getInstruction<ReferenceInstruction>(onClickListenerReferenceIndex).reference
val onClickListenerClass = context.findClass((onClickListenerReference as MethodReference).definingClass)!!.mutableClass
val onClickListenerReferenceIndex =
getTargetIndexWithReference("<init>(Ljava/lang/Object;I[B)V")
val onClickListenerReference =
getInstruction<ReferenceInstruction>(onClickListenerReferenceIndex).reference
val onClickListenerClass =
context.findClass((onClickListenerReference as MethodReference).definingClass)!!.mutableClass
var invokeInterfaceReference = ""
onClickListenerClass.methods.find { method -> method.name == "onClick" }
?.apply {
val invokeInterfaceIndex = getTargetIndexWithReference(invokerObjectReference.toString()) + 1
val invokeInterfaceIndex =
getTargetIndexWithReference(invokerObjectReference.toString()) + 1
if (getInstruction(invokeInterfaceIndex).opcode != Opcode.INVOKE_INTERFACE)
throw PatchException("Opcode does not match")
invokeInterfaceReference = getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference.toString()
invokeInterfaceReference =
getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference.toString()
} ?: throw PatchException("Could not find onClick method")
val alwaysRepeatMutableClass = context.findClass(INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR)!!.mutableClass
val alwaysRepeatMutableClass =
context.findClass(INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR)!!.mutableClass
val smaliInstructions =
"""

View File

@ -129,7 +129,10 @@ object OverlayButtonsPatch : BaseResourcePatch(
val resources = commonResources + specificResources
resources.forEach { resource ->
val folderName = if (resource.endsWith(".xml")) "drawable" else "drawable-xxhdpi"
context.copyResources("youtube/overlaybuttons/$iconValue", ResourceGroup(folderName, resource))
context.copyResources(
"youtube/overlaybuttons/$iconValue",
ResourceGroup(folderName, resource)
)
}
}

View File

@ -11,6 +11,7 @@ internal object OfflineVideoEndpointFingerprint : MethodFingerprint(
"Ljava/util/Map;",
"L",
"Ljava/lang/String", // VideoId
"L"),
"L"
),
strings = listOf("Object is not an offlineable video: ")
)

View File

@ -133,7 +133,8 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
TotalTimeFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val charSequenceIndex = getTargetIndexWithMethodReferenceName("getString") + 1
val charSequenceRegister = getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA
val charSequenceRegister =
getInstruction<OneRegisterInstruction>(charSequenceIndex).registerA
val textViewIndex = getTargetIndexWithMethodReferenceName("getText")
val textViewRegister =
getInstruction<FiveRegisterInstruction>(textViewIndex).registerC
@ -162,7 +163,8 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
}
ControlsOverlayStyleFingerprint.resultOrThrow().let {
val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1)
val walkerMethod =
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1)
walkerMethod.apply {
val colorRegister = getInstruction<TwoRegisterInstruction>(0).registerA
@ -221,18 +223,19 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
// region patch for hide seekbar
SeekbarFingerprint.resultOrThrow().mutableClass.let { mutableClass ->
SeekbarOnDrawFingerprint.also { it.resolve(context, mutableClass) }.resultOrThrow().let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0, """
SeekbarOnDrawFingerprint.also { it.resolve(context, mutableClass) }.resultOrThrow()
.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->hideSeekbar()Z
move-result v0
if-eqz v0, :show
return-void
""", ExternalLabel("show", getInstruction(0))
)
)
}
}
}
}
// endregion
@ -240,7 +243,8 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
// region patch for hide time stamp
PlayerSeekbarColorFingerprint.resultOrThrow().let { parentResult ->
TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) }.resultOrThrow().let {
TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) }
.resultOrThrow().let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0, """
@ -274,7 +278,8 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
"SETTINGS: RESTORE_OLD_SEEKBAR_THUMBNAILS"
)
)
} ?: println("WARNING: Restore old seekbar thumbnails setting is not supported in this version. Use YouTube 19.16.39 or earlier.")
}
?: println("WARNING: Restore old seekbar thumbnails setting is not supported in this version. Use YouTube 19.16.39 or earlier.")
// endregion

View File

@ -49,7 +49,8 @@ object SpeedOverlayPatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext) {
val restoreSlideToSeekBehaviorFingerprintResult = RestoreSlideToSeekBehaviorFingerprint.result
val restoreSlideToSeekBehaviorFingerprintResult =
RestoreSlideToSeekBehaviorFingerprint.result
val speedOverlayFingerprintResult = SpeedOverlayFingerprint.result
val speedOverlayValueFingerprintResult = SpeedOverlayValueFingerprint.result
@ -130,7 +131,8 @@ object SpeedOverlayPatch : BytecodePatch(
val jumpIndex = scanResult.endIndex + 1
val insertIndex = scanResult.endIndex - 1
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
val insertRegister =
getInstruction<TwoRegisterInstruction>(insertIndex).registerA
hook(insertIndex, insertRegister, jumpIndex)
}
@ -150,7 +152,8 @@ object SpeedOverlayPatch : BytecodePatch(
constructorMethod.apply {
val syntheticIndex = getTargetIndexReversed(Opcode.NEW_INSTANCE)
val syntheticClass = getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
val syntheticClass =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
val syntheticMethod =
context.findClass(syntheticClass)?.mutableClass
@ -170,8 +173,12 @@ object SpeedOverlayPatch : BytecodePatch(
"""
)
insertIndex = getTargetIndexWithMethodReferenceNameReversed(speedOverlayValueIndex, "removeCallbacks") + 1
insertRegister = getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
insertIndex = getTargetIndexWithMethodReferenceNameReversed(
speedOverlayValueIndex,
"removeCallbacks"
) + 1
insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
jumpIndex = getTargetIndex(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1
hook(insertIndex, insertRegister, jumpIndex)
}
@ -181,7 +188,8 @@ object SpeedOverlayPatch : BytecodePatch(
SpeedOverlayTextValueFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val targetRegister =
getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstructions(
targetIndex + 1, """