feat(music/share-button-hook): no longer hooking the sleep timer dialog

This commit is contained in:
inotia00 2023-06-20 17:30:13 +09:00
parent 3e252d4cb3
commit b143131b41
6 changed files with 3 additions and 159 deletions

View File

@ -16,9 +16,8 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.utils.settings.resource.patch.MusicSettingsPatch
import app.revanced.patches.music.utils.videoid.patch.MusicVideoIdPatch
import app.revanced.patches.music.misc.sharebuttonhook.fingerprints.*
import app.revanced.patches.music.misc.sleeptimerhook.patch.SleepTimerHookPatch
import app.revanced.patches.music.utils.videoid.patch.MusicVideoIdPatch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_INTEGRATIONS_PATH
@ -30,8 +29,7 @@ import app.revanced.util.integrations.Constants.MUSIC_MISC_PATH
@DependsOn(
[
MusicSettingsPatch::class,
MusicVideoIdPatch::class,
SleepTimerHookPatch::class
MusicVideoIdPatch::class
]
)
@YouTubeMusicCompatibility
@ -69,7 +67,7 @@ class ShareButtonHookPatch : BytecodePatch(
0,"""
invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR->dismissContext(Landroid/content/Context;)Landroid/content/Context;
move-result-object p0
"""
"""
) ?: return ShowToastFingerprint.toErrorResult()
FullStackTraceActivityFingerprint.result?.mutableMethod?.addInstructions(

View File

@ -1,13 +0,0 @@
package app.revanced.patches.music.misc.sleeptimerhook.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object MusicPlaybackControlsClickFingerprint : MethodFingerprint(
returnType = "V",
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
customFingerprint = { it, _ -> it.definingClass.endsWith("/MusicPlaybackControls;") && it.name == "onClick" }
)

View File

@ -1,13 +0,0 @@
package app.revanced.patches.music.misc.sleeptimerhook.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object MusicPlaybackControlsTimeFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC,
parameters = listOf("J","J","J","J"),
opcodes = listOf(Opcode.RETURN_VOID),
)

View File

@ -1,9 +0,0 @@
package app.revanced.patches.music.misc.sleeptimerhook.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object SleepTimerFinalFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L"),
strings = listOf("SLEEP_TIMER_MENU_BOTTOM_SHEET_FRAGMENT")
)

View File

@ -1,9 +0,0 @@
package app.revanced.patches.music.misc.sleeptimerhook.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object SleepTimerStaticFingerprint : MethodFingerprint(
returnType = "L",
parameters = listOf("L"),
strings = listOf("SLEEP_TIMER_MENU_BOTTOM_SHEET_FRAGMENT")
)

View File

@ -1,110 +0,0 @@
package app.revanced.patches.music.misc.sleeptimerhook.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.toInstructions
import app.revanced.patches.music.misc.sleeptimerhook.fingerprints.*
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.util.integrations.Constants.MUSIC_MISC_PATH
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.dexbacked.reference.DexBackedFieldReference
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
@Name("sleep-timer-hook")
@YouTubeMusicCompatibility
@Version("0.0.1")
class SleepTimerHookPatch : BytecodePatch(
listOf(
MusicPlaybackControlsClickFingerprint,
SleepTimerFinalFingerprint,
SleepTimerStaticFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
val sleepTimerStaticMethod = SleepTimerStaticFingerprint.result?.mutableMethod
?: return SleepTimerStaticFingerprint.toErrorResult()
val sleepTimerStaticMethodToCall = sleepTimerStaticMethod.definingClass +
"->" +
sleepTimerStaticMethod.name +
"(${sleepTimerStaticMethod.parameters[0]})" +
sleepTimerStaticMethod.returnType
val sleepTimerFinalMethod = SleepTimerFinalFingerprint.result?.mutableMethod
?: return SleepTimerFinalFingerprint.toErrorResult()
val sleepTimerFinalMethodToCall = sleepTimerFinalMethod.definingClass +
"->" +
sleepTimerFinalMethod.name +
"(${sleepTimerFinalMethod.parameters[0]})" +
sleepTimerFinalMethod.returnType
MusicPlaybackControlsClickFingerprint.result?.let { parentResult ->
with (parentResult.mutableMethod.implementation!!.instructions) {
for (i in this.size - 1 downTo 0) {
if (this[i].opcode != Opcode.IGET_OBJECT) continue
val invokeInstruction = this[i] as? ReferenceInstruction ?: continue
val targetReference = (invokeInstruction.reference as DexBackedFieldReference).toString()
if (!targetReference.contains(parentResult.classDef.type)) continue
musicPlaybackControlsMethodToCall = targetReference
break
}
if (musicPlaybackControlsMethodToCall == null)
return MusicPlaybackControlsClickFingerprint.toErrorResult()
}
MusicPlaybackControlsTimeFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstruction(
1,
"invoke-virtual {p0}, ${parentResult.classDef.type}->openSleepTimer()V"
) ?: return MusicPlaybackControlsTimeFingerprint.toErrorResult()
parentResult.mutableClass.methods.add(
ImmutableMethod(
parentResult.classDef.type,
"openSleepTimer",
listOf(),
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL,
null,
null,
ImmutableMethodImplementation(
4, """
sget-boolean v0, $INTEGRATIONS_CLASS_DESCRIPTOR
if-eqz v0, :dismiss
iget-object v1, v3, $musicPlaybackControlsMethodToCall
invoke-static {v1}, $sleepTimerStaticMethodToCall
move-result-object v0
iget-object v1, v3, $musicPlaybackControlsMethodToCall
invoke-virtual {v0, v1}, $sleepTimerFinalMethodToCall
const/4 v0, 0x0
sput-boolean v0, $INTEGRATIONS_CLASS_DESCRIPTOR
:dismiss
return-void
""".toInstructions(), null, null
)
).toMutable()
)
} ?: return MusicPlaybackControlsClickFingerprint.toErrorResult()
return PatchResultSuccess()
}
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR = "$MUSIC_MISC_PATH/HookShareButtonPatch;->isShareButtonClicked:Z"
var musicPlaybackControlsMethodToCall: String? = null
}
}