feat(YouTube Music/Litho filter): add support for identifier and byte buffer

This commit is contained in:
inotia00 2024-03-20 01:13:33 +09:00
parent 065f0c124f
commit cfcc0e5801
7 changed files with 31 additions and 45 deletions

View File

@ -8,7 +8,6 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.music.utils.litho.fingerprints.LithoFilterFingerprint import app.revanced.patches.music.utils.litho.fingerprints.LithoFilterFingerprint
import app.revanced.patches.shared.patch.litho.ComponentParserPatch import app.revanced.patches.shared.patch.litho.ComponentParserPatch
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.pathBuilderHook
import app.revanced.util.exception import app.revanced.util.exception
import java.io.Closeable import java.io.Closeable
@ -25,7 +24,7 @@ object LithoFilterPatch : BytecodePatch(
private var filterCount = 0 private var filterCount = 0
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
pathBuilderHook("$INTEGRATIONS_CLASS_DESCRIPTOR->filter") ComponentParserPatch.injectCall(INTEGRATIONS_CLASS_DESCRIPTOR)
LithoFilterFingerprint.result?.let { LithoFilterFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {

View File

@ -2,12 +2,13 @@ package app.revanced.patches.music.utils.litho.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.music.utils.integrations.Constants.COMPONENTS_PATH
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
object LithoFilterFingerprint : MethodFingerprint( object LithoFilterFingerprint : MethodFingerprint(
returnType = "V", returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR, accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ -> customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lapp/revanced/integrations/music/patches/components/LithoFilterPatch;" methodDef.definingClass == "$COMPONENTS_PATH/LithoFilterPatch;"
} }
) )

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.utils.litho.fingerprints package app.revanced.patches.shared.fingerprints.litho
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
@ -10,7 +10,7 @@ object GeneralByteBufferFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("I", "Ljava/nio/ByteBuffer;"), parameters = listOf("I", "Ljava/nio/ByteBuffer;"),
opcodes = listOf( opcodes = listOf(
Opcode.IPUT_OBJECT, null,
Opcode.IF_EQZ, Opcode.IF_EQZ,
Opcode.IPUT, Opcode.IPUT,
Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL,

View File

@ -1,12 +1,14 @@
package app.revanced.patches.shared.patch.litho package app.revanced.patches.shared.patch.litho
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint import app.revanced.patches.shared.fingerprints.litho.EmptyComponentBuilderFingerprint
import app.revanced.patches.shared.fingerprints.litho.GeneralByteBufferFingerprint
import app.revanced.util.exception import app.revanced.util.exception
import app.revanced.util.getEmptyStringInstructionIndex import app.revanced.util.getEmptyStringInstructionIndex
import app.revanced.util.getReference import app.revanced.util.getReference
@ -20,10 +22,14 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import kotlin.properties.Delegates import kotlin.properties.Delegates
object ComponentParserPatch : BytecodePatch( object ComponentParserPatch : BytecodePatch(
setOf(EmptyComponentBuilderFingerprint) setOf(
EmptyComponentBuilderFingerprint,
GeneralByteBufferFingerprint
)
) { ) {
private lateinit var emptyComponentLabel: String private lateinit var emptyComponentLabel: String
internal lateinit var insertMethod: MutableMethod private lateinit var byteBufferMethod: MutableMethod
internal lateinit var pathBuilderMethod: MutableMethod
private var emptyComponentIndex by Delegates.notNull<Int>() private var emptyComponentIndex by Delegates.notNull<Int>()
private var insertIndex by Delegates.notNull<Int>() private var insertIndex by Delegates.notNull<Int>()
@ -32,24 +38,20 @@ object ComponentParserPatch : BytecodePatch(
private var objectRegister by Delegates.notNull<Int>() private var objectRegister by Delegates.notNull<Int>()
private var stringBuilderRegister by Delegates.notNull<Int>() private var stringBuilderRegister by Delegates.notNull<Int>()
internal fun generalHook(descriptor: String) { internal fun injectCall(descriptor: String) {
insertMethod.apply { byteBufferMethod.apply {
addInstructionsWithLabels( val insertIndex = getTargetIndex(0, Opcode.IF_EQZ) + 1
insertIndex, """
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z addInstruction(
move-result v$stringBuilderRegister insertIndex,
if-eqz v$stringBuilderRegister, :filter "invoke-static { p2 }, $descriptor->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
""" + emptyComponentLabel,
ExternalLabel("filter", getInstruction(insertIndex))
) )
} }
}
internal fun pathBuilderHook(descriptor: String) { pathBuilderMethod.apply {
insertMethod.apply {
addInstructionsWithLabels( addInstructionsWithLabels(
insertIndex, """ insertIndex, """
invoke-static {v$stringBuilderRegister}, $descriptor(Ljava/lang/StringBuilder;)Z invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor->filter(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
move-result v$stringBuilderRegister move-result v$stringBuilderRegister
if-eqz v$stringBuilderRegister, :filter if-eqz v$stringBuilderRegister, :filter
""" + emptyComponentLabel, """ + emptyComponentLabel,
@ -60,12 +62,12 @@ object ComponentParserPatch : BytecodePatch(
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
/** byteBufferMethod = GeneralByteBufferFingerprint.result?.mutableMethod
* Shared fingerprint ?: throw GeneralByteBufferFingerprint.exception
*/
EmptyComponentBuilderFingerprint.result?.let { EmptyComponentBuilderFingerprint.result?.let {
it.mutableMethod.apply { it.mutableMethod.apply {
insertMethod = this pathBuilderMethod = this
emptyComponentIndex = it.scanResult.patternScanResult!!.startIndex + 1 emptyComponentIndex = it.scanResult.patternScanResult!!.startIndex + 1
val builderMethodDescriptor = val builderMethodDescriptor =

View File

@ -63,7 +63,7 @@ object BrowseIdHookPatch : BytecodePatch(
/** /**
* Set BrowseId to integrations. * Set BrowseId to integrations.
*/ */
ComponentParserPatch.insertMethod.apply { ComponentParserPatch.pathBuilderMethod.apply {
addInstruction( addInstruction(
0, 0,
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V" "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V"

View File

@ -1,15 +1,12 @@
package app.revanced.patches.youtube.utils.litho package app.revanced.patches.youtube.utils.litho
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.patch.litho.ComponentParserPatch import app.revanced.patches.shared.patch.litho.ComponentParserPatch
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.generalHook
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.youtube.utils.litho.fingerprints.GeneralByteBufferFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint
import app.revanced.util.exception import app.revanced.util.exception
import java.io.Closeable import java.io.Closeable
@ -17,10 +14,7 @@ import java.io.Closeable
@Patch(dependencies = [ComponentParserPatch::class]) @Patch(dependencies = [ComponentParserPatch::class])
@Suppress("unused") @Suppress("unused")
object LithoFilterPatch : BytecodePatch( object LithoFilterPatch : BytecodePatch(
setOf( setOf(LithoFilterFingerprint)
GeneralByteBufferFingerprint,
LithoFilterFingerprint
)
), Closeable { ), Closeable {
private const val INTEGRATIONS_CLASS_DESCRIPTOR = private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/LithoFilterPatch;" "$COMPONENTS_PATH/LithoFilterPatch;"
@ -30,18 +24,7 @@ object LithoFilterPatch : BytecodePatch(
private var filterCount = 0 private var filterCount = 0
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
ComponentParserPatch.injectCall(INTEGRATIONS_CLASS_DESCRIPTOR)
// ByteBuffer is set after checking for non-null
GeneralByteBufferFingerprint.result?.let {
it.mutableMethod.apply {
addInstruction(
2,
"invoke-static { p2 }, $INTEGRATIONS_CLASS_DESCRIPTOR->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
)
}
} ?: throw GeneralByteBufferFingerprint.exception
generalHook("$INTEGRATIONS_CLASS_DESCRIPTOR->filter")
LithoFilterFingerprint.result?.mutableMethod?.apply { LithoFilterFingerprint.result?.mutableMethod?.apply {
removeInstructions(0, 6) removeInstructions(0, 6)

View File

@ -2,12 +2,13 @@ package app.revanced.patches.youtube.utils.litho.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.utils.integrations.Constants.COMPONENTS_PATH
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
object LithoFilterFingerprint : MethodFingerprint( object LithoFilterFingerprint : MethodFingerprint(
returnType = "V", returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR, accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ -> customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lapp/revanced/integrations/youtube/patches/components/LithoFilterPatch;" methodDef.definingClass == "$COMPONENTS_PATH/LithoFilterPatch;"
} }
) )