mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-04 00:24:34 +02:00
feat(YouTube Music/Litho filter): add support for identifier and byte buffer
This commit is contained in:
parent
065f0c124f
commit
cfcc0e5801
@ -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.litho.fingerprints.LithoFilterFingerprint
|
||||
import app.revanced.patches.shared.patch.litho.ComponentParserPatch
|
||||
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.pathBuilderHook
|
||||
import app.revanced.util.exception
|
||||
import java.io.Closeable
|
||||
|
||||
@ -25,7 +24,7 @@ object LithoFilterPatch : BytecodePatch(
|
||||
private var filterCount = 0
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
pathBuilderHook("$INTEGRATIONS_CLASS_DESCRIPTOR->filter")
|
||||
ComponentParserPatch.injectCall(INTEGRATIONS_CLASS_DESCRIPTOR)
|
||||
|
||||
LithoFilterFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
|
@ -2,12 +2,13 @@ package app.revanced.patches.music.utils.litho.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
object LithoFilterFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR,
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass == "Lapp/revanced/integrations/music/patches/components/LithoFilterPatch;"
|
||||
methodDef.definingClass == "$COMPONENTS_PATH/LithoFilterPatch;"
|
||||
}
|
||||
)
|
@ -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.fingerprint.MethodFingerprint
|
||||
@ -10,7 +10,7 @@ object GeneralByteBufferFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("I", "Ljava/nio/ByteBuffer;"),
|
||||
opcodes = listOf(
|
||||
Opcode.IPUT_OBJECT,
|
||||
null,
|
||||
Opcode.IF_EQZ,
|
||||
Opcode.IPUT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
@ -1,12 +1,14 @@
|
||||
package app.revanced.patches.shared.patch.litho
|
||||
|
||||
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.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
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.getEmptyStringInstructionIndex
|
||||
import app.revanced.util.getReference
|
||||
@ -20,10 +22,14 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object ComponentParserPatch : BytecodePatch(
|
||||
setOf(EmptyComponentBuilderFingerprint)
|
||||
setOf(
|
||||
EmptyComponentBuilderFingerprint,
|
||||
GeneralByteBufferFingerprint
|
||||
)
|
||||
) {
|
||||
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 insertIndex by Delegates.notNull<Int>()
|
||||
@ -32,24 +38,20 @@ object ComponentParserPatch : BytecodePatch(
|
||||
private var objectRegister by Delegates.notNull<Int>()
|
||||
private var stringBuilderRegister by Delegates.notNull<Int>()
|
||||
|
||||
internal fun generalHook(descriptor: String) {
|
||||
insertMethod.apply {
|
||||
addInstructionsWithLabels(
|
||||
insertIndex, """
|
||||
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
|
||||
move-result v$stringBuilderRegister
|
||||
if-eqz v$stringBuilderRegister, :filter
|
||||
""" + emptyComponentLabel,
|
||||
ExternalLabel("filter", getInstruction(insertIndex))
|
||||
internal fun injectCall(descriptor: String) {
|
||||
byteBufferMethod.apply {
|
||||
val insertIndex = getTargetIndex(0, Opcode.IF_EQZ) + 1
|
||||
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static { p2 }, $descriptor->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun pathBuilderHook(descriptor: String) {
|
||||
insertMethod.apply {
|
||||
pathBuilderMethod.apply {
|
||||
addInstructionsWithLabels(
|
||||
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
|
||||
if-eqz v$stringBuilderRegister, :filter
|
||||
""" + emptyComponentLabel,
|
||||
@ -60,12 +62,12 @@ object ComponentParserPatch : BytecodePatch(
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
/**
|
||||
* Shared fingerprint
|
||||
*/
|
||||
byteBufferMethod = GeneralByteBufferFingerprint.result?.mutableMethod
|
||||
?: throw GeneralByteBufferFingerprint.exception
|
||||
|
||||
EmptyComponentBuilderFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
insertMethod = this
|
||||
pathBuilderMethod = this
|
||||
emptyComponentIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||
|
||||
val builderMethodDescriptor =
|
||||
|
@ -63,7 +63,7 @@ object BrowseIdHookPatch : BytecodePatch(
|
||||
/**
|
||||
* Set BrowseId to integrations.
|
||||
*/
|
||||
ComponentParserPatch.insertMethod.apply {
|
||||
ComponentParserPatch.pathBuilderMethod.apply {
|
||||
addInstruction(
|
||||
0,
|
||||
"invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V"
|
||||
|
@ -1,15 +1,12 @@
|
||||
package app.revanced.patches.youtube.utils.litho
|
||||
|
||||
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.removeInstructions
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
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.litho.fingerprints.GeneralByteBufferFingerprint
|
||||
import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint
|
||||
import app.revanced.util.exception
|
||||
import java.io.Closeable
|
||||
@ -17,10 +14,7 @@ import java.io.Closeable
|
||||
@Patch(dependencies = [ComponentParserPatch::class])
|
||||
@Suppress("unused")
|
||||
object LithoFilterPatch : BytecodePatch(
|
||||
setOf(
|
||||
GeneralByteBufferFingerprint,
|
||||
LithoFilterFingerprint
|
||||
)
|
||||
setOf(LithoFilterFingerprint)
|
||||
), Closeable {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$COMPONENTS_PATH/LithoFilterPatch;"
|
||||
@ -30,18 +24,7 @@ object LithoFilterPatch : BytecodePatch(
|
||||
|
||||
private var filterCount = 0
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
// 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")
|
||||
ComponentParserPatch.injectCall(INTEGRATIONS_CLASS_DESCRIPTOR)
|
||||
|
||||
LithoFilterFingerprint.result?.mutableMethod?.apply {
|
||||
removeInstructions(0, 6)
|
||||
|
@ -2,12 +2,13 @@ package app.revanced.patches.youtube.utils.litho.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
object LithoFilterFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.CONSTRUCTOR,
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass == "Lapp/revanced/integrations/youtube/patches/components/LithoFilterPatch;"
|
||||
methodDef.definingClass == "$COMPONENTS_PATH/LithoFilterPatch;"
|
||||
}
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user