Skip to content

Commit

Permalink
chore: remove obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Sep 25, 2024
1 parent 42d2846 commit 0752ff0
Show file tree
Hide file tree
Showing 31 changed files with 504 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.flyoutmenu.components.fingerprints.DialogSolidFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.EndButtonsContainerFingerprint
Expand All @@ -20,11 +19,13 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.integrations.Constants.FLYOUT_CLASS_DESCRIPTOR
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.EndButtonsContainer
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TrimSilenceSwitch
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand Down Expand Up @@ -95,40 +96,40 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
TrimSilenceSwitchFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constIndex =
indexOfFirstWideLiteralInstructionValueOrThrow(SharedResourceIdPatch.TrimSilenceSwitch)
indexOfFirstWideLiteralInstructionValueOrThrow(TrimSilenceSwitch)
val onCheckedChangedListenerIndex =
indexOfFirstInstructionOrThrow(constIndex, Opcode.INVOKE_DIRECT)
val onCheckedChangedListenerReference =
getInstruction<ReferenceInstruction>(onCheckedChangedListenerIndex).reference
val onCheckedChangedListenerDefiningClass =
(onCheckedChangedListenerReference as MethodReference).definingClass
val onCheckedChangedListenerClass =
context.findClass(onCheckedChangedListenerDefiningClass)!!.mutableClass

onCheckedChangedListenerClass.methods.find { method -> method.name == "onCheckedChanged" }
?.apply {
val walkerIndex = indexOfFirstInstructionOrThrow {
val reference =
((this as? ReferenceInstruction)?.reference as? MethodReference)
val onCheckedChangedMethod =
context.findMethodOrThrow(onCheckedChangedListenerDefiningClass) {
name == "onCheckedChanged"
}

opcode == Opcode.INVOKE_VIRTUAL
&& reference?.returnType == "V"
&& reference.parameterTypes.size == 1
&& reference.parameterTypes[0] == "Z"
}
getWalkerMethod(context, walkerIndex).apply {
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT)
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
val onCheckedChangedWalkerIndex =
onCheckedChangedMethod.indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL
&& reference?.returnType == "V"
&& reference.parameterTypes.size == 1
&& reference.parameterTypes[0] == "Z"
}

addInstructions(
insertIndex + 1, """
invoke-static {v$insertRegister}, $FLYOUT_CLASS_DESCRIPTOR->enableTrimSilenceSwitch(Z)Z
move-result v$insertRegister
"""
)
}
} ?: throw PatchException("onClickClass not found!")
getWalkerMethod(context, onCheckedChangedWalkerIndex).apply {
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT)
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA

addInstructions(
insertIndex + 1, """
invoke-static {v$insertRegister}, $FLYOUT_CLASS_DESCRIPTOR->enableTrimSilenceSwitch(Z)Z
move-result v$insertRegister
"""
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.alsoResolve
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand Down Expand Up @@ -539,7 +540,7 @@ object PlayerComponentsPatch : BaseBytecodePatch(
opcode == Opcode.INVOKE_VIRTUAL
&& reference?.definingClass == "Lcom/google/android/material/bottomsheet/BottomSheetBehavior;"
&& reference.parameterTypes.first() == "Z"
}
}
val freeRegister =
getInstruction<FiveRegisterInstruction>(bottomSheetBehaviorIndex).registerD

Expand Down Expand Up @@ -908,7 +909,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
MppWatchWhileLayoutFingerprint.resultOrThrow().mutableMethod.apply {
val callableIndex =
MppWatchWhileLayoutFingerprint.indexOfCallableInstruction(this)
val insertIndex = indexOfFirstInstructionReversedOrThrow(callableIndex, Opcode.NEW_INSTANCE)
val insertIndex =
indexOfFirstInstructionReversedOrThrow(callableIndex, Opcode.NEW_INSTANCE)
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA

addInstructionsWithLabels(
Expand All @@ -929,7 +931,8 @@ object PlayerComponentsPatch : BaseBytecodePatch(
).let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val targetRegister =
getInstruction<OneRegisterInstruction>(targetIndex).registerA

addInstructions(
targetIndex + 1, """
Expand Down Expand Up @@ -1095,16 +1098,13 @@ object PlayerComponentsPatch : BaseBytecodePatch(
val onClickReference = getInstruction<ReferenceInstruction>(onClickIndex).reference
val onClickReferenceDefiningClass = (onClickReference as MethodReference).definingClass

val onClickClass =
context.findClass(onClickReferenceDefiningClass)!!.mutableClass

onClickClass.methods.find { method -> method.name == "<init>" }
?.apply {
context.findMethodOrThrow(onClickReferenceDefiningClass)
.apply {
addInstruction(
implementation!!.instructions.lastIndex,
"sput-object p0, $PLAYER_CLASS_DESCRIPTOR->$fieldName:$onClickReferenceDefiningClass"
)
} ?: throw PatchException("onClickClass not found!")
}

PlayerPatchConstructorFingerprint.resultOrThrow().let {
val mutableClass = it.mutableClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.utils.flyoutmenu.fingerprints.PlaybackRateBottomSheetClassFingerprint
import app.revanced.patches.music.utils.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
import app.revanced.util.addFieldAndInstructions
import app.revanced.util.addStaticFieldToIntegration
import app.revanced.util.resultOrThrow

@Patch(
Expand All @@ -31,15 +31,12 @@ object FlyoutMenuHookPatch : BytecodePatch(
return-void
"""

context.findClass(
INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR
)!!.mutableClass.addFieldAndInstructions(
context,
context.addStaticFieldToIntegration(
INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR,
"showPlaybackSpeedFlyoutMenu",
"playbackRateBottomSheetClass",
definingClass,
smaliInstructions,
true
smaliInstructions
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import app.revanced.patches.shared.mapping.ResourceMappingPatch
import app.revanced.patches.shared.mapping.ResourceMappingPatch.getId
import app.revanced.patches.shared.mapping.ResourceType.BOOL
import app.revanced.patches.shared.mapping.ResourceType.COLOR
import app.revanced.patches.shared.mapping.ResourceType.DRAWABLE
import app.revanced.patches.shared.mapping.ResourceType.DIMEN
import app.revanced.patches.shared.mapping.ResourceType.DRAWABLE
import app.revanced.patches.shared.mapping.ResourceType.ID
import app.revanced.patches.shared.mapping.ResourceType.LAYOUT
import app.revanced.patches.shared.mapping.ResourceType.STRING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ object SponsorBlockBytecodePatch : BytecodePatch(
RectangleFieldInvalidatorFingerprint.alsoResolve(
context, SeekBarConstructorFingerprint
).let {
with (it.mutableMethod) {
val invalidateIndex = RectangleFieldInvalidatorFingerprint.indexOfInvalidateInstruction(this)
val rectangleIndex = indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
with(it.mutableMethod) {
val invalidateIndex =
RectangleFieldInvalidatorFingerprint.indexOfInvalidateInstruction(this)
val rectangleIndex =
indexOfFirstInstructionReversedOrThrow(invalidateIndex + 1) {
getReference<FieldReference>()?.type == "Landroid/graphics/Rect;"
}
val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference

Expand Down Expand Up @@ -116,7 +118,7 @@ object SponsorBlockBytecodePatch : BytecodePatch(
*/
rectangleFieldName =
MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let {
with (it.mutableMethod) {
with(it.mutableMethod) {
val rectangleIndex = it.scanResult.patternScanResult!!.startIndex
val rectangleReference =
getInstruction<ReferenceInstruction>(rectangleIndex).reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import app.revanced.patcher.fingerprint.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.toInstructions
Expand All @@ -24,7 +23,7 @@ import app.revanced.patches.music.video.information.fingerprints.VideoQualityLis
import app.revanced.patches.music.video.information.fingerprints.VideoQualityTextFingerprint
import app.revanced.patches.shared.fingerprints.MdxPlayerDirectorSetVideoStageFingerprint
import app.revanced.patches.shared.fingerprints.VideoLengthFingerprint
import app.revanced.util.addFieldAndInstructions
import app.revanced.util.addStaticFieldToIntegration
import app.revanced.util.alsoResolve
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
Expand Down Expand Up @@ -82,7 +81,6 @@ object VideoInformationPatch : BytecodePatch(
private var seekSourceEnumType = ""
private var seekSourceMethodName = ""

private lateinit var videoInformationMutableClass: MutableClass
private lateinit var context: BytecodeContext

private lateinit var playerConstructorMethod: MutableMethod
Expand Down Expand Up @@ -138,21 +136,18 @@ object VideoInformationPatch : BytecodePatch(
return v0
"""

videoInformationMutableClass.addFieldAndInstructions(
context,
context.addStaticFieldToIntegration(
INTEGRATIONS_CLASS_DESCRIPTOR,
methodName,
fieldName,
definingClass,
smaliInstructions,
true
smaliInstructions
)
}
}

override fun execute(context: BytecodeContext) {
this.context = context
videoInformationMutableClass =
context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)!!.mutableClass

VideoEndFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
Expand Down Expand Up @@ -211,9 +206,9 @@ object VideoInformationPatch : BytecodePatch(

PLAYER_RESPONSE_MODEL_CLASS_DESCRIPTOR =
getInstruction(playerResponseModelIndex)
.getReference<MethodReference>()
?.definingClass
?: throw PatchException("Could not find Player Response Model class")
.getReference<MethodReference>()
?.definingClass
?: throw PatchException("Could not find Player Response Model class")

videoIdMethodCall =
VideoIdFingerprint.getPlayerResponseInstruction("Ljava/lang/String;")
Expand Down Expand Up @@ -302,13 +297,12 @@ object VideoInformationPatch : BytecodePatch(
return-void
"""

videoInformationMutableClass.addFieldAndInstructions(
context,
VideoInformationPatch.context.addStaticFieldToIntegration(
INTEGRATIONS_CLASS_DESCRIPTOR,
"overrideVideoQuality",
"videoQualityClass",
videoQualityClass,
smaliInstructions,
true
smaliInstructions
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.music.video.playback.fingerprints.PlaybackSpeedBottomSheetFingerprint
import app.revanced.patches.music.video.playback.fingerprints.UserQualityChangeFingerprint
import app.revanced.util.findMethodOrThrow
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction

@Suppress("unused")
Expand Down Expand Up @@ -84,19 +85,14 @@ object VideoPlaybackPatch : BaseBytecodePatch(
it.mutableMethod.apply {
val endIndex = it.scanResult.patternScanResult!!.endIndex
val qualityChangedClass =
context.findClass(
(getInstruction<BuilderInstruction21c>(endIndex))
.reference.toString()
)!!
.mutableClass
getInstruction<ReferenceInstruction>(endIndex).reference.toString()

val onItemClickMethod =
qualityChangedClass.methods.find { method -> method.name == "onItemClick" }

onItemClickMethod?.addInstruction(
context.findMethodOrThrow(qualityChangedClass) {
name == "onItemClick"
}.addInstruction(
0,
"invoke-static {}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->userSelectedVideoQuality()V"
) ?: throw PatchException("Failed to find onItemClick method")
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ abstract class BaseAdsPatch(
MusicAdsFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = indexOfFirstInstructionOrThrow {
val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference)

val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL
&& reference?.returnType == "V"
&& reference.parameterTypes.size == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patches.shared.integrations.BaseIntegrationsPatch.IntegrationsFingerprint.IRegisterResolver
import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR
import app.revanced.util.findMethodOrThrow
import app.revanced.util.isDeprecated
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
Expand All @@ -18,11 +18,7 @@ abstract class BaseIntegrationsPatch(
) : BytecodePatch(hooks) {

override fun execute(context: BytecodeContext) {
if (context.findClass(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR) == null) {
throw PatchException(
"Integrations have not been merged yet. This patch can not succeed without merging the integrations.",
)
}
context.findMethodOrThrow(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR)

hooks.forEach { hook ->
hook.invoke(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR)
Expand Down
Loading

0 comments on commit 0752ff0

Please sign in to comment.