chore: replace with a fingerprint that supports a wider range of versions

This commit is contained in:
inotia00 2024-10-03 22:39:30 +09:00
parent e88c190460
commit 6360f97e54
10 changed files with 40 additions and 42 deletions

View File

@ -12,7 +12,7 @@ import app.revanced.patches.music.misc.backgroundplayback.fingerprints.PodCastCo
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
@ -52,8 +52,8 @@ object BackgroundPlaybackPatch : BaseBytecodePatch(
// don't play music video
MusicBrowserServiceFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val stringIndex = MusicBrowserServiceFingerprint.indexOfMBSInstruction(this)
val targetIndex = indexOfFirstInstructionReversedOrThrow(stringIndex) {
val stringIndex = it.scanResult.stringsScanResult!!.matches.first().index
val targetIndex = indexOfFirstInstructionOrThrow(stringIndex) {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "Z" &&

View File

@ -2,28 +2,14 @@ package app.revanced.patches.music.misc.backgroundplayback.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.music.misc.backgroundplayback.fingerprints.MusicBrowserServiceFingerprint.indexOfMBSInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.StringReference
internal object MusicBrowserServiceFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Ljava/lang/String;", "Landroid/os/Bundle;"),
customFingerprint = custom@{ methodDef, _ ->
if (!methodDef.definingClass.endsWith("/MusicBrowserService;"))
return@custom false
indexOfMBSInstruction(methodDef) >= 0
}
) {
fun indexOfMBSInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
opcode == Opcode.CONST_STRING &&
getReference<StringReference>()?.string?.startsWith("MBS: Return empty root for client: %s") == true
}
}
strings = listOf("android.service.media.extra.RECENT"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/MusicBrowserService;")
},
)

View File

@ -8,7 +8,6 @@ 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.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

View File

@ -9,6 +9,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
* It appears this hook may no longer be needed as one of the constructor parameters is the already hooked
* [EmbeddedPlayerControlsOverlayFingerprint]
*/
@Deprecated("Fingerprint is obsolete and will be deleted soon")
internal object APIPlayerServiceFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ -> methodDef.definingClass == "Lcom/google/android/apps/youtube/embeddedplayer/service/service/jar/ApiPlayerService;" },

View File

@ -10,6 +10,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
* Note: this fingerprint may no longer be needed, as it appears
* [RemoteEmbedFragmentFingerprint] may be set before this hook is called.
*/
@Deprecated("Fingerprint is obsolete and will be deleted soon")
internal object EmbeddedPlayerControlsOverlayFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.CONSTRUCTOR,
returnType = "V",

View File

@ -10,6 +10,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
* Note: this fingerprint may or may not be needed, as
* [RemoteEmbedFragmentFingerprint] might be set before this is called.
*/
@Deprecated("Fingerprint is obsolete and will be deleted soon")
internal object EmbeddedPlayerFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
returnType = "L",

View File

@ -7,6 +7,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
/**
* For embedded playback. Likely covers Google Play store and other Google products.
*/
@Deprecated("Fingerprint is obsolete and will be deleted soon")
internal object RemoteEmbedFragmentFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
returnType = "V",

View File

@ -7,6 +7,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
/**
* For embedded playback inside 3rd party android app (such as 3rd party Reddit apps).
*/
@Deprecated("Fingerprint is obsolete and will be deleted soon")
internal object RemoteEmbeddedPlayerFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.CONSTRUCTOR,
returnType = "V",

View File

@ -56,8 +56,7 @@ object NavigationBarHookPatch : BytecodePatch(
private lateinit var navigationTabCreatedCallback: MutableMethod
private lateinit var bottomBarContainerMethod: MutableMethod
private var bottomBarContainerIndex = 0
private var bottomBarContainerRegister = 0
private var bottomBarContainerOffset = 0
override fun execute(context: BytecodeContext) {
fun MutableMethod.addHook(hook: Hook, insertPredicate: Instruction.() -> Boolean) {
@ -131,13 +130,8 @@ object NavigationBarHookPatch : BytecodePatch(
"onBackPressed"
)
InitializeBottomBarContainerFingerprint.resultOrThrow().mutableMethod.apply {
bottomBarContainerMethod = this
bottomBarContainerIndex =
InitializeBottomBarContainerFingerprint.indexOfLayoutChangeListenerInstruction(this)
bottomBarContainerRegister =
getInstruction<FiveRegisterInstruction>(bottomBarContainerIndex).registerC
}
bottomBarContainerMethod =
InitializeBottomBarContainerFingerprint.resultOrThrow().mutableMethod
}
val hookNavigationButtonCreated: (String) -> Unit by lazy {
@ -152,11 +146,19 @@ object NavigationBarHookPatch : BytecodePatch(
}
}
fun addBottomBarContainerHook(descriptor: String) =
bottomBarContainerMethod.addInstruction(
bottomBarContainerIndex,
fun addBottomBarContainerHook(descriptor: String) {
bottomBarContainerMethod.apply {
val layoutChangeListenerIndex =
InitializeBottomBarContainerFingerprint.indexOfLayoutChangeListenerInstruction(this)
val bottomBarContainerRegister =
getInstruction<FiveRegisterInstruction>(layoutChangeListenerIndex).registerC
addInstruction(
layoutChangeListenerIndex + bottomBarContainerOffset--,
"invoke-static { v$bottomBarContainerRegister }, $descriptor"
)
}
}
private enum class Hook(val methodName: String, val parameters: String) {
SET_LAST_APP_NAVIGATION_ENUM("setLastAppNavigationEnum", "Ljava/lang/Enum;"),

View File

@ -2,20 +2,26 @@ package app.revanced.patches.youtube.utils.playertype.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
internal object VideoStateFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
parameters = listOf("Lcom/google/android/libraries/youtube/player/features/overlay/controls/ControlsState;"),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT, // obfuscated parameter field name
)
),
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstruction {
opcode == Opcode.IGET_OBJECT &&
getReference<FieldReference>()?.definingClass == methodDef.parameterTypes.firstOrNull()
} >= 0
}
)