Skip to content

Commit 512b252

Browse files
committed
chore: Lint code
1 parent b32301f commit 512b252

File tree

17 files changed

+223
-146
lines changed

17 files changed

+223
-146
lines changed

patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ val changeVersionCodePatch = resourcePatch(
4949
"Invalid versionCode: $versionCodeString, " +
5050
"Version code should be larger than 1 and smaller than $MAX_VALUE."
5151
)
52+
5253
val versionCodeString = versionCodeOption.valueOrThrow()
5354
val versionCode: Int
5455

patches/src/main/kotlin/app/revanced/patches/music/actionbar/components/ActionBarComponentsPatch.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ val actionBarComponentsPatch = bytecodePatch(
116116
.endsWith("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;-><init>(Landroid/content/Context;)V")
117117
} - 2
118118
val replaceInstruction = getInstruction<TwoRegisterInstruction>(replaceIndex)
119-
val replaceReference = getInstruction<ReferenceInstruction>(replaceIndex).reference
119+
val replaceReference =
120+
getInstruction<ReferenceInstruction>(replaceIndex).reference
120121

121122
addInstructionsWithLabels(
122123
replaceIndex + 1, """
@@ -140,7 +141,8 @@ val actionBarComponentsPatch = bytecodePatch(
140141
}
141142
val spannedRegister =
142143
getInstruction<FiveRegisterInstruction>(spannedIndex).registerC
143-
val spannedReference = getInstruction<ReferenceInstruction>(spannedIndex).reference
144+
val spannedReference =
145+
getInstruction<ReferenceInstruction>(spannedIndex).reference
144146

145147
addInstructionsWithLabels(
146148
spannedIndex + 1, """

patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ internal val dislikeButtonOnClickListenerFingerprint = legacyFingerprint(
1212
parameters = listOf("Landroid/view/View;"),
1313
customFingerprint = { method, _ ->
1414
method.name == "onClick" &&
15-
(method.containsLiteralInstruction(53465L) || method.containsLiteralInstruction(98173L))
15+
(method.containsLiteralInstruction(53465L) || method.containsLiteralInstruction(
16+
98173L
17+
))
1618
}
1719
)
1820

patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,14 @@ val customBrandingIconPatch = resourcePatch(
252252
}
253253

254254
mapOf(
255-
ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher_release.xml", "background"),
256-
ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher_release.xml", "foreground")
255+
ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile(
256+
"res/mipmap-anydpi/ic_launcher_release.xml",
257+
"background"
258+
),
259+
ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile(
260+
"res/mipmap-anydpi/ic_launcher_release.xml",
261+
"foreground"
262+
)
257263
).forEach { (oldIconResourceFile, newIconResourceFile) ->
258264
if (oldIconResourceFile != newIconResourceFile) {
259265
mipmapDirectories.forEach {

patches/src/main/kotlin/app/revanced/patches/music/misc/drc/DrcAudioPatch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ val DrcAudioPatch = bytecodePatch(
4040
fingerprint.matchOrThrow(formatStreamModelConstructorFingerprint).let {
4141
it.method.apply {
4242
val insertIndex = it.patternMatch!!.endIndex
43-
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex - 1).registerA
43+
val insertRegister =
44+
getInstruction<TwoRegisterInstruction>(insertIndex - 1).registerA
4445

4546
addInstructions(
4647
insertIndex,

patches/src/main/kotlin/app/revanced/patches/music/player/components/PlayerComponentsPatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ val playerComponentsPatch = bytecodePatch(
823823
// region patch for remember repeat state
824824

825825
val (repeatTrackMethod, repeatTrackIndex) = repeatTrackFingerprint.matchOrThrow().let {
826-
with (it.method) {
826+
with(it.method) {
827827
val targetIndex = it.patternMatch!!.endIndex
828828
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
829829

patches/src/main/kotlin/app/revanced/patches/music/utils/fix/client/SpoofClientPatch.kt

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ val spoofClientPatch = bytecodePatch(
8080
val clientInfoVersionIndex = result.stringMatches!!.first().index
8181
val clientInfoVersionRegister =
8282
getInstruction<OneRegisterInstruction>(clientInfoVersionIndex).registerA
83-
val clientInfoClientVersionFieldIndex = indexOfFirstInstructionOrThrow(clientInfoVersionIndex) {
84-
opcode == Opcode.IPUT_OBJECT &&
85-
(this as TwoRegisterInstruction).registerA == clientInfoVersionRegister
86-
}
83+
val clientInfoClientVersionFieldIndex =
84+
indexOfFirstInstructionOrThrow(clientInfoVersionIndex) {
85+
opcode == Opcode.IPUT_OBJECT &&
86+
(this as TwoRegisterInstruction).registerA == clientInfoVersionRegister
87+
}
8788

8889
// Client info object's client version field.
8990
val clientInfoClientVersionField =
@@ -95,27 +96,30 @@ val spoofClientPatch = bytecodePatch(
9596
}
9697
}
9798

98-
val clientInfoClientModelField = with (createPlayerRequestBodyWithModelFingerprint.methodOrThrow()) {
99-
// The next IPUT_OBJECT instruction after getting the client model is setting the client model field.
100-
val clientInfoClientModelIndex = indexOfFirstInstructionOrThrow(indexOfModelInstruction(this)) {
101-
val reference = getReference<FieldReference>()
102-
opcode == Opcode.IPUT_OBJECT &&
103-
reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR &&
104-
reference.type == "Ljava/lang/String;"
99+
val clientInfoClientModelField =
100+
with(createPlayerRequestBodyWithModelFingerprint.methodOrThrow()) {
101+
// The next IPUT_OBJECT instruction after getting the client model is setting the client model field.
102+
val clientInfoClientModelIndex =
103+
indexOfFirstInstructionOrThrow(indexOfModelInstruction(this)) {
104+
val reference = getReference<FieldReference>()
105+
opcode == Opcode.IPUT_OBJECT &&
106+
reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR &&
107+
reference.type == "Ljava/lang/String;"
108+
}
109+
getInstruction<ReferenceInstruction>(clientInfoClientModelIndex).reference
105110
}
106-
getInstruction<ReferenceInstruction>(clientInfoClientModelIndex).reference
107-
}
108111

109-
val clientInfoOsVersionField = with (createPlayerRequestBodyWithVersionReleaseFingerprint.methodOrThrow()) {
110-
val buildIndex = indexOfBuildInstruction(this)
111-
val clientInfoOsVersionIndex = indexOfFirstInstructionOrThrow(buildIndex - 5) {
112-
val reference = getReference<FieldReference>()
113-
opcode == Opcode.IPUT_OBJECT &&
114-
reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR &&
115-
reference.type == "Ljava/lang/String;"
112+
val clientInfoOsVersionField =
113+
with(createPlayerRequestBodyWithVersionReleaseFingerprint.methodOrThrow()) {
114+
val buildIndex = indexOfBuildInstruction(this)
115+
val clientInfoOsVersionIndex = indexOfFirstInstructionOrThrow(buildIndex - 5) {
116+
val reference = getReference<FieldReference>()
117+
opcode == Opcode.IPUT_OBJECT &&
118+
reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR &&
119+
reference.type == "Ljava/lang/String;"
120+
}
121+
getInstruction<ReferenceInstruction>(clientInfoOsVersionIndex).reference
116122
}
117-
getInstruction<ReferenceInstruction>(clientInfoOsVersionIndex).reference
118-
}
119123

120124
// endregion
121125

@@ -229,15 +233,17 @@ val spoofClientPatch = bytecodePatch(
229233
reference?.returnType == "V" &&
230234
reference.parameterTypes.firstOrNull()?.startsWith("[L") == true
231235
}
232-
val createPlaybackSpeedMenuItemMethod = getWalkerMethod(createPlaybackSpeedMenuItemIndex)
236+
val createPlaybackSpeedMenuItemMethod =
237+
getWalkerMethod(createPlaybackSpeedMenuItemIndex)
233238
createPlaybackSpeedMenuItemMethod.apply {
234239
val shouldCreateMenuIndex = indexOfFirstInstructionOrThrow {
235240
val reference = getReference<MethodReference>()
236241
opcode == Opcode.INVOKE_VIRTUAL &&
237242
reference?.returnType == "Z" &&
238243
reference.parameterTypes.isEmpty()
239244
} + 2
240-
val shouldCreateMenuRegister = getInstruction<OneRegisterInstruction>(shouldCreateMenuIndex - 1).registerA
245+
val shouldCreateMenuRegister =
246+
getInstruction<OneRegisterInstruction>(shouldCreateMenuIndex - 1).registerA
241247

242248
addInstructions(
243249
shouldCreateMenuIndex,

patches/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ private val sponsorBlockBytecodePatch = bytecodePatch(
111111
rectangleFieldName =
112112
musicPlaybackControlsTimeBarOnMeasureFingerprint.matchOrThrow().let {
113113
with(it.method) {
114-
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(it.patternMatch!!.endIndex) {
115-
opcode == Opcode.IGET_OBJECT &&
116-
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
117-
}
114+
val rectangleIndex =
115+
indexOfFirstInstructionReversedOrThrow(it.patternMatch!!.endIndex) {
116+
opcode == Opcode.IGET_OBJECT &&
117+
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
118+
}
118119
val rectangleReference =
119120
getInstruction<ReferenceInstruction>(rectangleIndex).reference
120121
(rectangleReference as FieldReference).name

patches/src/main/kotlin/app/revanced/patches/shared/gms/GmsCoreSupportPatch.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ fun gmsCoreSupportPatch(
8484
key = "gmsCoreVendorGroupId",
8585
default = "app.revanced",
8686
values =
87-
mapOf(
88-
"ReVanced" to "app.revanced",
89-
),
87+
mapOf(
88+
"ReVanced" to "app.revanced",
89+
),
9090
title = "GmsCore vendor group ID",
9191
description = "The vendor's group ID for GmsCore.",
9292
required = true,

patches/src/main/kotlin/app/revanced/patches/shared/spoof/streamingdata/BaseSpoofStreamingDataPatch.kt

Lines changed: 93 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -81,50 +81,59 @@ fun baseSpoofStreamingDataPatch(
8181

8282
// region Replace the streaming data.
8383

84-
createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint).let { result ->
85-
result.method.apply {
86-
val setStreamDataMethodName = "patch_setStreamingData"
87-
val resultMethodType = result.classDef.type
88-
val setStreamingDataIndex = result.patternMatch!!.startIndex
89-
val setStreamingDataField =
90-
getInstruction(setStreamingDataIndex).getReference<FieldReference>().toString()
91-
92-
val playerProtoClass =
93-
getInstruction(setStreamingDataIndex + 1).getReference<FieldReference>()!!.definingClass
94-
val protobufClass =
95-
protobufClassParseByteBufferFingerprint.definingClassOrThrow()
96-
97-
val getStreamingDataField = instructions.find { instruction ->
98-
instruction.opcode == Opcode.IGET_OBJECT &&
99-
instruction.getReference<FieldReference>()?.definingClass == playerProtoClass
100-
}?.getReference<FieldReference>()
101-
?: throw PatchException("Could not find getStreamingDataField")
102-
103-
val videoDetailsIndex = result.patternMatch!!.endIndex
104-
val videoDetailsRegister = getInstruction<TwoRegisterInstruction>(videoDetailsIndex).registerA
105-
val videoDetailsClass =
106-
getInstruction(videoDetailsIndex).getReference<FieldReference>()!!.type
107-
108-
addInstruction(
109-
videoDetailsIndex + 1,
110-
"invoke-direct { p0, v$videoDetailsRegister }, " +
111-
"$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V",
112-
)
113-
114-
result.classDef.methods.add(
115-
ImmutableMethod(
116-
resultMethodType,
117-
setStreamDataMethodName,
118-
listOf(ImmutableMethodParameter(videoDetailsClass, annotations, "videoDetails")),
119-
"V",
120-
AccessFlags.PRIVATE.value or AccessFlags.FINAL.value,
121-
annotations,
122-
null,
123-
MutableMethodImplementation(9),
124-
).toMutable().apply {
125-
addInstructionsWithLabels(
126-
0,
127-
"""
84+
createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint)
85+
.let { result ->
86+
result.method.apply {
87+
val setStreamDataMethodName = "patch_setStreamingData"
88+
val resultMethodType = result.classDef.type
89+
val setStreamingDataIndex = result.patternMatch!!.startIndex
90+
val setStreamingDataField =
91+
getInstruction(setStreamingDataIndex).getReference<FieldReference>()
92+
.toString()
93+
94+
val playerProtoClass =
95+
getInstruction(setStreamingDataIndex + 1).getReference<FieldReference>()!!.definingClass
96+
val protobufClass =
97+
protobufClassParseByteBufferFingerprint.definingClassOrThrow()
98+
99+
val getStreamingDataField = instructions.find { instruction ->
100+
instruction.opcode == Opcode.IGET_OBJECT &&
101+
instruction.getReference<FieldReference>()?.definingClass == playerProtoClass
102+
}?.getReference<FieldReference>()
103+
?: throw PatchException("Could not find getStreamingDataField")
104+
105+
val videoDetailsIndex = result.patternMatch!!.endIndex
106+
val videoDetailsRegister =
107+
getInstruction<TwoRegisterInstruction>(videoDetailsIndex).registerA
108+
val videoDetailsClass =
109+
getInstruction(videoDetailsIndex).getReference<FieldReference>()!!.type
110+
111+
addInstruction(
112+
videoDetailsIndex + 1,
113+
"invoke-direct { p0, v$videoDetailsRegister }, " +
114+
"$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V",
115+
)
116+
117+
result.classDef.methods.add(
118+
ImmutableMethod(
119+
resultMethodType,
120+
setStreamDataMethodName,
121+
listOf(
122+
ImmutableMethodParameter(
123+
videoDetailsClass,
124+
annotations,
125+
"videoDetails"
126+
)
127+
),
128+
"V",
129+
AccessFlags.PRIVATE.value or AccessFlags.FINAL.value,
130+
annotations,
131+
null,
132+
MutableMethodImplementation(9),
133+
).toMutable().apply {
134+
addInstructionsWithLabels(
135+
0,
136+
"""
128137
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled()Z
129138
move-result v0
130139
if-eqz v0, :disabled
@@ -153,44 +162,52 @@ fun baseSpoofStreamingDataPatch(
153162
:disabled
154163
return-void
155164
""",
156-
)
157-
},
158-
)
159-
}
160-
}
161-
162-
videoStreamingDataConstructorFingerprint.methodOrThrow(videoStreamingDataToStringFingerprint).apply {
163-
val formatStreamModelInitIndex = indexOfFormatStreamModelInitInstruction(this)
164-
val getVideoIdIndex = indexOfFirstInstructionReversedOrThrow(formatStreamModelInitIndex) {
165-
val reference = getReference<FieldReference>()
166-
opcode == Opcode.IGET_OBJECT &&
167-
reference?.type == "Ljava/lang/String;" &&
168-
reference.definingClass == definingClass
169-
}
170-
val getVideoIdReference = getInstruction<ReferenceInstruction>(getVideoIdIndex).reference
171-
val insertIndex = indexOfFirstInstructionReversedOrThrow(getVideoIdIndex) {
172-
opcode == Opcode.IGET_OBJECT &&
173-
getReference<FieldReference>()?.definingClass == STREAMING_DATA_INTERFACE
174-
}
175-
176-
val (freeRegister, streamingDataRegister) = with(getInstruction<TwoRegisterInstruction>(insertIndex)) {
177-
Pair(registerA, registerB)
165+
)
166+
},
167+
)
168+
}
178169
}
179-
val definingClassRegister = getInstruction<TwoRegisterInstruction>(getVideoIdIndex).registerB
180-
val insertReference = getInstruction<ReferenceInstruction>(insertIndex).reference
181170

182-
replaceInstruction(
183-
insertIndex,
184-
"iget-object v$freeRegister, v$freeRegister, $insertReference"
185-
)
186-
addInstructions(
187-
insertIndex, """
171+
videoStreamingDataConstructorFingerprint.methodOrThrow(videoStreamingDataToStringFingerprint)
172+
.apply {
173+
val formatStreamModelInitIndex = indexOfFormatStreamModelInitInstruction(this)
174+
val getVideoIdIndex =
175+
indexOfFirstInstructionReversedOrThrow(formatStreamModelInitIndex) {
176+
val reference = getReference<FieldReference>()
177+
opcode == Opcode.IGET_OBJECT &&
178+
reference?.type == "Ljava/lang/String;" &&
179+
reference.definingClass == definingClass
180+
}
181+
val getVideoIdReference =
182+
getInstruction<ReferenceInstruction>(getVideoIdIndex).reference
183+
val insertIndex = indexOfFirstInstructionReversedOrThrow(getVideoIdIndex) {
184+
opcode == Opcode.IGET_OBJECT &&
185+
getReference<FieldReference>()?.definingClass == STREAMING_DATA_INTERFACE
186+
}
187+
188+
val (freeRegister, streamingDataRegister) = with(
189+
getInstruction<TwoRegisterInstruction>(
190+
insertIndex
191+
)
192+
) {
193+
Pair(registerA, registerB)
194+
}
195+
val definingClassRegister =
196+
getInstruction<TwoRegisterInstruction>(getVideoIdIndex).registerB
197+
val insertReference = getInstruction<ReferenceInstruction>(insertIndex).reference
198+
199+
replaceInstruction(
200+
insertIndex,
201+
"iget-object v$freeRegister, v$freeRegister, $insertReference"
202+
)
203+
addInstructions(
204+
insertIndex, """
188205
iget-object v$freeRegister, v$definingClassRegister, $getVideoIdReference
189206
invoke-static { v$freeRegister, v$streamingDataRegister }, $EXTENSION_CLASS_DESCRIPTOR->getOriginalStreamingData(Ljava/lang/String;$STREAMING_DATA_INTERFACE)$STREAMING_DATA_INTERFACE
190207
move-result-object v$freeRegister
191208
"""
192-
)
193-
}
209+
)
210+
}
194211

195212
// endregion
196213

0 commit comments

Comments
 (0)