chore: lint code

This commit is contained in:
inotia00
2024-06-23 14:09:48 +09:00
parent b99c6218f7
commit 8186e9c8b2
28 changed files with 123 additions and 43 deletions

View File

@ -284,7 +284,8 @@ object LayoutComponentsPatch : BaseBytecodePatch(
)
SearchBarFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val setVisibilityIndex = getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setVisibility")
val setVisibilityInstruction =
getInstruction<FiveRegisterInstruction>(setVisibilityIndex)

View File

@ -42,7 +42,8 @@ object DislikeRedirectionPatch : BaseBytecodePatch(
PendingIntentReceiverFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val startIndex = getStringInstructionIndex("YTM Dislike")
val onClickRelayIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickRelayIndex =
getTargetIndexReversedOrThrow(startIndex, Opcode.INVOKE_VIRTUAL)
val onClickRelayMethod = getWalkerMethod(context, onClickRelayIndex)
onClickRelayMethod.apply {

View File

@ -133,7 +133,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
colorMathPlayerMethodParameter = parameters
val relativeIndex = it.scanResult.patternScanResult!!.endIndex + 1
val invokeVirtualIndex = getTargetIndexOrThrow(relativeIndex, Opcode.INVOKE_VIRTUAL)
val invokeVirtualIndex =
getTargetIndexOrThrow(relativeIndex, Opcode.INVOKE_VIRTUAL)
val iGetIndex = getTargetIndexOrThrow(relativeIndex, Opcode.IGET)
colorMathPlayerInvokeVirtualReference =

View File

@ -33,7 +33,10 @@ object RestoreOldHeaderPatch : BytecodePatch(
HeaderSwitchConfigFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexOrThrow(getWideLiteralInstructionIndex(45617851), Opcode.MOVE_RESULT)
getTargetIndexOrThrow(
getWideLiteralInstructionIndex(45617851),
Opcode.MOVE_RESULT
)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -79,7 +79,8 @@ object SponsorBlockBytecodePatch : BytecodePatch(
)
// Draw segment
val drawCircleIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("drawCircle")
val drawCircleIndex =
getTargetIndexWithMethodReferenceNameReversedOrThrow("drawCircle")
val drawCircleInstruction = getInstruction<FiveRegisterInstruction>(drawCircleIndex)
addInstruction(
drawCircleIndex,

View File

@ -138,7 +138,8 @@ object VideoInformationPatch : BytecodePatch(
)
VideoLengthFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val invalidateIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val invalidateIndex =
getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversedOrThrow(
invalidateIndex + 1,
"Landroid/graphics/Rect;"

View File

@ -138,7 +138,8 @@ abstract class BaseGmsCoreSupportPatch(
getTargetIndexWithReference(GET_PACKAGE_NAME_METHOD_REFERENCE)
if (getPackageNameIndex > -1) {
val targetRegister = (getInstruction(getPackageNameIndex) as FiveRegisterInstruction).registerC
val targetRegister =
(getInstruction(getPackageNameIndex) as FiveRegisterInstruction).registerC
replaceInstruction(
getPackageNameIndex,

View File

@ -142,7 +142,8 @@ object LithoFilterPatch : BytecodePatch(
val emptyStringIndex = getStringInstructionIndex("")
val identifierIndex = getTargetIndexReversedOrThrow(emptyStringIndex, Opcode.IPUT_OBJECT)
val identifierIndex =
getTargetIndexReversedOrThrow(emptyStringIndex, Opcode.IPUT_OBJECT)
val identifierRegister =
getInstruction<TwoRegisterInstruction>(identifierIndex).registerA

View File

@ -37,7 +37,10 @@ object AudioTracksPatch : BaseBytecodePatch(
"Ljava/util/List;->add(Ljava/lang/Object;)Z"
)
val insertIndex =
getTargetIndexWithReferenceOrThrow(arrayListIndex, "Ljava/util/List;->isEmpty()Z") + 2
getTargetIndexWithReferenceOrThrow(
arrayListIndex,
"Ljava/util/List;->isEmpty()Z"
) + 2
val formatStreamModelRegister =
getInstruction<OneRegisterInstruction>(formatStreamModelIndex).registerA

View File

@ -349,7 +349,10 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply {
val startIndex = getWideLiteralInstructionIndex(VoiceSearch)
val setOnClickListenerIndex =
getTargetIndexWithMethodReferenceNameOrThrow(startIndex, "setOnClickListener")
getTargetIndexWithMethodReferenceNameOrThrow(
startIndex,
"setOnClickListener"
)
val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

View File

@ -125,7 +125,8 @@ object PlayerButtonsPatch : BaseBytecodePatch(
TitleAnchorFingerprint.resultOrThrow().mutableMethod.apply {
val titleAnchorConstIndex = getWideLiteralInstructionIndex(TitleAnchor)
val titleAnchorIndex = getTargetIndexOrThrow(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
val titleAnchorIndex =
getTargetIndexOrThrow(titleAnchorConstIndex, Opcode.MOVE_RESULT_OBJECT)
val titleAnchorRegister =
getInstruction<OneRegisterInstruction>(titleAnchorIndex).registerA

View File

@ -203,7 +203,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
it.mutableMethod.apply {
val constIndex = getWideLiteralInstructionIndex(FadeDurationFast)
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
val insertIndex = getTargetIndexReversedOrThrow(constIndex, Opcode.INVOKE_VIRTUAL) + 1
val insertIndex =
getTargetIndexReversedOrThrow(constIndex, Opcode.INVOKE_VIRTUAL) + 1
val jumpIndex = implementation!!.instructions.let { instruction ->
insertIndex + instruction.subList(insertIndex, instruction.size - 1)
.indexOfFirst { instructions ->

View File

@ -94,7 +94,8 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
if (SettingsPatch.upward1902) {
TextViewComponentFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val insertIndex = getTargetIndexWithMethodReferenceNameOrThrow("setTextIsSelectable")
val insertIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setTextIsSelectable")
val insertInstruction = getInstruction<FiveRegisterInstruction>(insertIndex)
replaceInstruction(

View File

@ -144,7 +144,8 @@ object ChangeTogglePatch : BaseBytecodePatch(
val checkCastIndex = getTargetIndexReversedOrThrow(stringIndex, Opcode.CHECK_CAST)
val iGetObjectPrimaryIndex =
getTargetIndexReversedOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectSecondaryIndex = getTargetIndexOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val iGetObjectSecondaryIndex =
getTargetIndexOrThrow(checkCastIndex, Opcode.IGET_OBJECT)
val checkCastReference =
getInstruction<ReferenceInstruction>(checkCastIndex).reference

View File

@ -182,7 +182,8 @@ object FullscreenComponentsPatch : BaseBytecodePatch(
YouTubeControlsOverlayFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getTargetIndexWithMethodReferenceNameOrThrow("setFocusableInTouchMode")
val targetIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setFocusableInTouchMode")
val walkerIndex = getTargetIndexOrThrow(targetIndex, Opcode.INVOKE_STATIC)
val walkerMethod = getWalkerMethod(context, walkerIndex)

View File

@ -179,7 +179,8 @@ object SpeedOverlayPatch : BytecodePatch(
) + 1
insertRegister =
getInstruction<FiveRegisterInstruction>(insertIndex - 1).registerC
jumpIndex = getTargetIndexOrThrow(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1
jumpIndex =
getTargetIndexOrThrow(speedOverlayValueIndex, Opcode.RETURN_VOID) + 1
hook(insertIndex, insertRegister, jumpIndex)
}
}

View File

@ -157,7 +157,8 @@ object ShortsComponentPatch : BaseBytecodePatch(
(instruction.value as? WideLiteralInstruction)?.wideLiteral == ReelPivotButton
}
val targetIndex = constCalls.elementAt(constCalls.size - 1).index
val insertIndex = getTargetIndexReversedOrThrow(targetIndex, Opcode.INVOKE_STATIC) + 1
val insertIndex =
getTargetIndexReversedOrThrow(targetIndex, Opcode.INVOKE_STATIC) + 1
if (insertIndex == 0)
throw PatchException("insert index not found")

View File

@ -33,7 +33,10 @@ object CairoSettingsPatch : BytecodePatch(
CarioFragmentConfigFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexOrThrow(getWideLiteralInstructionIndex(45532100), Opcode.MOVE_RESULT)
getTargetIndexOrThrow(
getWideLiteralInstructionIndex(45532100),
Opcode.MOVE_RESULT
)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -27,7 +27,10 @@ object ConversionContextObfuscationPatch : BytecodePatch(
ObfuscationConfigFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexOrThrow(getWideLiteralInstructionIndex(45631264), Opcode.MOVE_RESULT)
getTargetIndexOrThrow(
getWideLiteralInstructionIndex(45631264),
Opcode.MOVE_RESULT
)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -28,7 +28,10 @@ object ShortsPlaybackPatch : BytecodePatch(
ShortsPlaybackFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex =
getTargetIndexOrThrow(getWideLiteralInstructionIndex(45387052), Opcode.MOVE_RESULT)
getTargetIndexOrThrow(
getWideLiteralInstructionIndex(45387052),
Opcode.MOVE_RESULT
)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(

View File

@ -128,7 +128,8 @@ object PlayerTypeHookPatch : BytecodePatch(
// Insert before the first ViewGroup method call after inflating,
// so this works regardless which layout is used.
ActionBarSearchResultsFingerprint.resultOrThrow().mutableMethod.apply {
val instructionIndex = getTargetIndexWithMethodReferenceNameOrThrow("setLayoutDirection")
val instructionIndex =
getTargetIndexWithMethodReferenceNameOrThrow("setLayoutDirection")
val viewRegister = getInstruction<FiveRegisterInstruction>(instructionIndex).registerC
addInstruction(

View File

@ -36,8 +36,10 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch(
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val isDisLikesBooleanIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_BOOLEAN)
val textViewFieldIndex = getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_OBJECT)
val isDisLikesBooleanIndex =
getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_BOOLEAN)
val textViewFieldIndex =
getTargetIndexReversedOrThrow(startIndex, Opcode.IGET_OBJECT)
// If the field is true, the TextView is for a dislike button.
val isDisLikesBooleanReference =

View File

@ -146,7 +146,8 @@ object SponsorBlockBytecodePatch : BytecodePatch(
// Replace strings
RectangleFieldInvalidatorFingerprint.resultOrThrow().let { result ->
result.mutableMethod.apply {
val invalidateIndex = getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val invalidateIndex =
getTargetIndexWithMethodReferenceNameReversedOrThrow("invalidate")
val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversedOrThrow(
invalidateIndex + 1,
"Landroid/graphics/Rect;"

View File

@ -8,6 +8,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.storyboard.fingerprints.PlayerResponseModelGeneralStoryboardRendererFingerprint
import app.revanced.patches.youtube.utils.storyboard.fingerprints.PlayerResponseModelLiveStreamStoryboardRendererFingerprint
import app.revanced.patches.youtube.utils.storyboard.fingerprints.PlayerResponseModelStoryboardRecommendedLevelFingerprint
@ -16,7 +17,6 @@ import app.revanced.patches.youtube.utils.storyboard.fingerprints.StoryboardRend
import app.revanced.patches.youtube.utils.storyboard.fingerprints.StoryboardRendererSpecFingerprint
import app.revanced.patches.youtube.utils.storyboard.fingerprints.StoryboardThumbnailFingerprint
import app.revanced.patches.youtube.utils.storyboard.fingerprints.StoryboardThumbnailParentFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

View File

@ -281,7 +281,10 @@ object VideoInformationPatch : BytecodePatch(
val speedSelectionValueInstructionIndex = getTargetIndexOrThrow(Opcode.IGET)
val setPlaybackSpeedContainerClassFieldIndex =
getTargetIndexReversedOrThrow(speedSelectionValueInstructionIndex, Opcode.IGET_OBJECT)
getTargetIndexReversedOrThrow(
speedSelectionValueInstructionIndex,
Opcode.IGET_OBJECT
)
val setPlaybackSpeedContainerClassFieldReference =
getInstruction<ReferenceInstruction>(setPlaybackSpeedContainerClassFieldIndex).reference.toString()

View File

@ -111,7 +111,7 @@ object VideoPlaybackPatch : BaseBytecodePatch(
val stringIndex = getStringInstructionIndex("av1_profile_main_10_hdr_10_plus_supported")
val walkerIndex = indexOfFirstInstructionOrThrow(stringIndex) {
val reference = getReference<MethodReference>()
reference?.parameterTypes == listOf("I", "Landroid/view/Display;")
reference?.parameterTypes == listOf("I", "Landroid/view/Display;")
&& reference.returnType == "Z"
}

View File

@ -22,9 +22,9 @@ object PlayerResponseMethodHookPatch :
// Registers used to pass the parameters to integrations.
private var playerResponseMethodCopyRegisters = false
private lateinit var REGISTER_VIDEO_ID : String
private lateinit var REGISTER_PLAYER_PARAMETER : String
private lateinit var REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING : String
private lateinit var REGISTER_VIDEO_ID: String
private lateinit var REGISTER_PLAYER_PARAMETER: String
private lateinit var REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING: String
private lateinit var playerResponseMethod: MutableMethod
private var numberOfInstructionsAdded = 0
@ -86,7 +86,8 @@ object PlayerResponseMethodHookPatch :
if (playerResponseMethodCopyRegisters) {
playerResponseMethod.apply {
addInstructions(
0, """
0,
"""
move-object/from16 $REGISTER_VIDEO_ID, p$PARAMETER_VIDEO_ID
move-object/from16 $REGISTER_PLAYER_PARAMETER, p$PARAMETER_PLAYER_PARAMETER
move/from16 $REGISTER_IS_SHORT_AND_OPENING_OR_PLAYING, p$PARAMETER_IS_SHORT_AND_OPENING_OR_PLAYING

View File

@ -359,10 +359,20 @@ fun MutableMethod.getTargetIndexWithFieldReferenceNameOrThrow(startIndex: Int, f
checkIndex(getTargetIndexWithFieldReferenceName(startIndex, filedName), startIndex, filedName)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversedOrThrow(returnType: String) =
getTargetIndexWithFieldReferenceNameReversedOrThrow(implementation!!.instructions.lastIndex, returnType)
getTargetIndexWithFieldReferenceNameReversedOrThrow(
implementation!!.instructions.lastIndex,
returnType
)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversedOrThrow(startIndex: Int, returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceNameReversed(startIndex, returnType), startIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversedOrThrow(
startIndex: Int,
returnType: String
) =
checkIndex(
getTargetIndexWithFieldReferenceNameReversed(startIndex, returnType),
startIndex,
returnType
)
fun Method.getTargetIndexWithFieldReferenceTypeOrThrow(returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceType(returnType), 0, returnType)
@ -371,22 +381,49 @@ fun MutableMethod.getTargetIndexWithFieldReferenceTypeOrThrow(startIndex: Int, r
checkIndex(getTargetIndexWithFieldReferenceType(startIndex, returnType), startIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeReversedOrThrow(returnType: String) =
getTargetIndexWithFieldReferenceTypeReversedOrThrow(implementation!!.instructions.lastIndex, returnType)
getTargetIndexWithFieldReferenceTypeReversedOrThrow(
implementation!!.instructions.lastIndex,
returnType
)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeReversedOrThrow(startIndex: Int, returnType: String) =
checkIndex(getTargetIndexWithFieldReferenceTypeReversed(startIndex, returnType), startIndex, returnType)
fun MutableMethod.getTargetIndexWithFieldReferenceTypeReversedOrThrow(
startIndex: Int,
returnType: String
) =
checkIndex(
getTargetIndexWithFieldReferenceTypeReversed(startIndex, returnType),
startIndex,
returnType
)
fun Method.getTargetIndexWithMethodReferenceNameOrThrow(methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceName(methodName), 0, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameOrThrow(startIndex: Int, methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceName(startIndex, methodName), startIndex, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameOrThrow(
startIndex: Int,
methodName: String
) =
checkIndex(
getTargetIndexWithMethodReferenceName(startIndex, methodName),
startIndex,
methodName
)
fun MutableMethod.getTargetIndexWithMethodReferenceNameReversedOrThrow(methodName: String) =
getTargetIndexWithMethodReferenceNameReversedOrThrow(implementation!!.instructions.lastIndex, methodName)
getTargetIndexWithMethodReferenceNameReversedOrThrow(
implementation!!.instructions.lastIndex,
methodName
)
fun MutableMethod.getTargetIndexWithMethodReferenceNameReversedOrThrow(startIndex: Int, methodName: String) =
checkIndex(getTargetIndexWithMethodReferenceNameReversed(startIndex, methodName), startIndex, methodName)
fun MutableMethod.getTargetIndexWithMethodReferenceNameReversedOrThrow(
startIndex: Int,
methodName: String
) =
checkIndex(
getTargetIndexWithMethodReferenceNameReversed(startIndex, methodName),
startIndex,
methodName
)
fun Method.getTargetIndexWithReferenceOrThrow(reference: String) =
checkIndex(getTargetIndexWithReference(reference), 0, reference)
@ -450,7 +487,10 @@ fun MutableMethod.getTargetIndexWithFieldReferenceName(startIndex: Int, filedNam
}
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(returnType: String) =
getTargetIndexWithFieldReferenceTypeReversed(implementation!!.instructions.lastIndex, returnType)
getTargetIndexWithFieldReferenceTypeReversed(
implementation!!.instructions.lastIndex,
returnType
)
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(
startIndex: Int,