chore: lint code

This commit is contained in:
inotia00 2024-09-15 20:21:41 +09:00
parent 80727591ae
commit 5e8d280294
11 changed files with 48 additions and 28 deletions

View File

@ -198,7 +198,11 @@ object CustomBrandingIconPatch : BaseResourcePatch(
if (oldSplashIconNotExists) { if (oldSplashIconNotExists) {
splashIconResourceGroups.let { resourceGroups -> splashIconResourceGroups.let { resourceGroups ->
resourceGroups.forEach { resourceGroups.forEach {
context.copyResources("$youtubeMusicIconResourcePath/splash", it, createDirectoryIfNotExist = true) context.copyResources(
"$youtubeMusicIconResourcePath/splash",
it,
createDirectoryIfNotExist = true
)
} }
} }
} }

View File

@ -32,6 +32,11 @@ abstract class BaseAdsPatch(
VideoAdsFingerprint VideoAdsFingerprint
) )
) { ) {
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$PATCHES_PATH/FullscreenAdsPatch;"
}
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
MusicAdsFingerprint.resultOrThrow().let { MusicAdsFingerprint.resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
@ -119,9 +124,4 @@ abstract class BaseAdsPatch(
) )
} }
} }
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$PATCHES_PATH/FullscreenAdsPatch;"
}
} }

View File

@ -180,7 +180,8 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
"invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->setWideSearchBarLayout(Landroid/view/View;)V" "invoke-static {v$viewRegister}, $GENERAL_CLASS_DESCRIPTOR->setWideSearchBarLayout(Landroid/view/View;)V"
) )
val targetIndex = ActionBarRingoBackgroundFingerprint.indexOfStaticInstruction(this) + 1 val targetIndex =
ActionBarRingoBackgroundFingerprint.indexOfStaticInstruction(this) + 1
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
injectSearchBarHook( injectSearchBarHook(

View File

@ -2,8 +2,8 @@ package app.revanced.patches.youtube.general.toolbar.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoTextFingerprint.indexOfStaticInstruction
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoTextFingerprint.indexOfStartDelayInstruction import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoTextFingerprint.indexOfStartDelayInstruction
import app.revanced.patches.youtube.general.toolbar.fingerprints.ActionBarRingoTextFingerprint.indexOfStaticInstruction
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionReversed import app.revanced.util.indexOfFirstInstructionReversed
@ -26,7 +26,7 @@ internal object ActionBarRingoTextFingerprint : MethodFingerprint(
} }
fun indexOfStaticInstruction(methodDef: Method) = fun indexOfStaticInstruction(methodDef: Method) =
methodDef.indexOfFirstInstructionReversed (indexOfStartDelayInstruction(methodDef)) { methodDef.indexOfFirstInstructionReversed(indexOfStartDelayInstruction(methodDef)) {
val reference = getReference<MethodReference>() val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_STATIC && opcode == Opcode.INVOKE_STATIC &&
reference?.parameterTypes?.size == 1 && reference?.parameterTypes?.size == 1 &&

View File

@ -45,7 +45,7 @@ object BackgroundPlaybackPatch : BaseBytecodePatch(
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
BackgroundPlaybackManagerFingerprint.resultOrThrow().mutableMethod.apply { BackgroundPlaybackManagerFingerprint.resultOrThrow().mutableMethod.apply {
findOpcodeIndicesReversed(Opcode.RETURN).forEach{ index -> findOpcodeIndicesReversed(Opcode.RETURN).forEach { index ->
val register = getInstruction<OneRegisterInstruction>(index).registerA val register = getInstruction<OneRegisterInstruction>(index).registerA
// Replace to preserve control flow label. // Replace to preserve control flow label.
@ -54,7 +54,8 @@ object BackgroundPlaybackPatch : BaseBytecodePatch(
"invoke-static { v$register }, $MISC_PATH/BackgroundPlaybackPatch;->allowBackgroundPlayback(Z)Z" "invoke-static { v$register }, $MISC_PATH/BackgroundPlaybackPatch;->allowBackgroundPlayback(Z)Z"
) )
addInstructions(index + 1, addInstructions(
index + 1,
""" """
move-result v$register move-result v$register
return v$register return v$register

View File

@ -10,8 +10,9 @@ internal object PlayerResponseModelUtils {
const val PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR = const val PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR =
"Lcom/google/android/libraries/youtube/innertube/model/player/PlayerResponseModel;" "Lcom/google/android/libraries/youtube/innertube/model/player/PlayerResponseModel;"
fun indexOfPlayerResponseModelInstruction(methodDef: Method) = methodDef.indexOfFirstInstruction { fun indexOfPlayerResponseModelInstruction(methodDef: Method) =
opcode == Opcode.INVOKE_INTERFACE && methodDef.indexOfFirstInstruction {
getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR opcode == Opcode.INVOKE_INTERFACE &&
} getReference<MethodReference>()?.definingClass == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
}
} }

View File

@ -222,7 +222,7 @@ object SpoofStreamingDataPatch : BaseBytecodePatch(
// region Append spoof info. // region Append spoof info.
NerdsStatsVideoFormatBuilderFingerprint.resultOrThrow().mutableMethod.apply { NerdsStatsVideoFormatBuilderFingerprint.resultOrThrow().mutableMethod.apply {
findOpcodeIndicesReversed(Opcode.RETURN_OBJECT).forEach{ index -> findOpcodeIndicesReversed(Opcode.RETURN_OBJECT).forEach { index ->
val register = getInstruction<OneRegisterInstruction>(index).registerA val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions( addInstructions(

View File

@ -18,7 +18,6 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.addFieldAndInstructions import app.revanced.util.addFieldAndInstructions
import app.revanced.util.getStringInstructionIndex import app.revanced.util.getStringInstructionIndex
import app.revanced.util.getTargetIndexOrThrow import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
import app.revanced.util.resultOrThrow import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction

View File

@ -274,10 +274,13 @@ object VideoInformationPatch : BytecodePatch(
/** /**
* Set current video information * Set current video information
*/ */
channelIdMethodCall = ChannelIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;") channelIdMethodCall =
channelNameMethodCall = ChannelNameFingerprint.getPlayerResponseInstruction("Ljava/lang/String;") ChannelIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
channelNameMethodCall =
ChannelNameFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
videoIdMethodCall = VideoIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;") videoIdMethodCall = VideoIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
videoTitleMethodCall = VideoTitleFingerprint.getPlayerResponseInstruction("Ljava/lang/String;") videoTitleMethodCall =
VideoTitleFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
videoLengthMethodCall = VideoLengthFingerprint.getPlayerResponseInstruction("J") videoLengthMethodCall = VideoLengthFingerprint.getPlayerResponseInstruction("J")
videoIsLiveMethodCall = ChannelIdFingerprint.getPlayerResponseInstruction("Z") videoIsLiveMethodCall = ChannelIdFingerprint.getPlayerResponseInstruction("Z")

View File

@ -20,8 +20,9 @@ internal object PlaybackInitializationFingerprint : MethodFingerprint(
indexOfPlayerResponseModelInstruction(methodDef) >= 0 indexOfPlayerResponseModelInstruction(methodDef) >= 0
} }
) { ) {
fun indexOfPlayerResponseModelInstruction(methodDef: Method) = methodDef.indexOfFirstInstruction { fun indexOfPlayerResponseModelInstruction(methodDef: Method) =
opcode == Opcode.INVOKE_DIRECT && methodDef.indexOfFirstInstruction {
getReference<MethodReference>()?.returnType == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR opcode == Opcode.INVOKE_DIRECT &&
} getReference<MethodReference>()?.returnType == PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR
}
} }

View File

@ -291,7 +291,10 @@ fun Method.indexOfFirstInstructionReversed(startIndex: Int? = null, targetOpcode
* @return -1 if the instruction is not found. * @return -1 if the instruction is not found.
* @see indexOfFirstInstructionReversedOrThrow * @see indexOfFirstInstructionReversedOrThrow
*/ */
fun Method.indexOfFirstInstructionReversed(startIndex: Int? = null, predicate: Instruction.() -> Boolean): Int { fun Method.indexOfFirstInstructionReversed(
startIndex: Int? = null,
predicate: Instruction.() -> Boolean
): Int {
var instructions = this.implementation!!.instructions var instructions = this.implementation!!.instructions
if (startIndex != null) { if (startIndex != null) {
instructions = instructions.take(startIndex + 1) instructions = instructions.take(startIndex + 1)
@ -308,7 +311,10 @@ fun Method.indexOfFirstInstructionReversed(startIndex: Int? = null, predicate: I
* @return -1 if the instruction is not found. * @return -1 if the instruction is not found.
* @see indexOfFirstInstructionReversed * @see indexOfFirstInstructionReversed
*/ */
fun Method.indexOfFirstInstructionReversedOrThrow(startIndex: Int? = null, targetOpcode: Opcode): Int = fun Method.indexOfFirstInstructionReversedOrThrow(
startIndex: Int? = null,
targetOpcode: Opcode
): Int =
indexOfFirstInstructionReversedOrThrow(startIndex) { indexOfFirstInstructionReversedOrThrow(startIndex) {
opcode == targetOpcode opcode == targetOpcode
} }
@ -321,7 +327,10 @@ fun Method.indexOfFirstInstructionReversedOrThrow(startIndex: Int? = null, targe
* @return -1 if the instruction is not found. * @return -1 if the instruction is not found.
* @see indexOfFirstInstructionReversed * @see indexOfFirstInstructionReversed
*/ */
fun Method.indexOfFirstInstructionReversedOrThrow(startIndex: Int? = null, predicate: Instruction.() -> Boolean): Int { fun Method.indexOfFirstInstructionReversedOrThrow(
startIndex: Int? = null,
predicate: Instruction.() -> Boolean
): Int {
val index = indexOfFirstInstructionReversed(startIndex, predicate) val index = indexOfFirstInstructionReversed(startIndex, predicate)
if (index < 0) { if (index < 0) {
@ -424,7 +433,8 @@ inline fun <reified T : Reference> Instruction.getReference() =
* @param predicate The predicate to match. * @param predicate The predicate to match.
* @return The index of the first [Instruction] that matches the predicate. * @return The index of the first [Instruction] that matches the predicate.
*/ */
fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) = indexOfFirstInstruction(0, predicate) fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) =
indexOfFirstInstruction(0, predicate)
/** /**
* Get the index of the first [Instruction] that matches the predicate, starting from [startIndex]. * Get the index of the first [Instruction] that matches the predicate, starting from [startIndex].