mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-02 07:34:31 +02:00
feat(music/litho-filter): no longer uses identifier
parameter
This commit is contained in:
parent
4c0d11cf76
commit
a798aab519
@ -9,7 +9,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
|
|||||||
import app.revanced.patches.music.utils.annotations.MusicCompatibility
|
import app.revanced.patches.music.utils.annotations.MusicCompatibility
|
||||||
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.Companion.identifierHook
|
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.pathBuilderHook
|
||||||
import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH
|
import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class LithoFilterPatch : BytecodePatch(
|
|||||||
listOf(LithoFilterFingerprint)
|
listOf(LithoFilterFingerprint)
|
||||||
), Closeable {
|
), Closeable {
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
identifierHook("$MUSIC_ADS_PATH/LithoFilterPatch;->filter")
|
pathBuilderHook("$MUSIC_ADS_PATH/LithoFilterPatch;->filter")
|
||||||
|
|
||||||
LithoFilterFingerprint.result?.let {
|
LithoFilterFingerprint.result?.let {
|
||||||
it.mutableMethod.apply {
|
it.mutableMethod.apply {
|
||||||
|
@ -3,9 +3,16 @@ package app.revanced.patches.shared.fingerprints.litho
|
|||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
object EmptyComponentBuilderFingerprint : MethodFingerprint(
|
object EmptyComponentBuilderFingerprint : MethodFingerprint(
|
||||||
returnType = "L",
|
returnType = "L",
|
||||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.INVOKE_INTERFACE,
|
||||||
|
Opcode.INVOKE_STATIC_RANGE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.IGET_OBJECT
|
||||||
|
),
|
||||||
strings = listOf("Error while converting %s")
|
strings = listOf("Error while converting %s")
|
||||||
)
|
)
|
@ -5,13 +5,11 @@ import app.revanced.patcher.data.BytecodeContext
|
|||||||
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.patch.PatchException
|
|
||||||
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.IdentifierFingerprint
|
import app.revanced.patches.shared.fingerprints.litho.IdentifierFingerprint
|
||||||
import app.revanced.util.bytecode.getStringIndex
|
import app.revanced.util.bytecode.getStringIndex
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
|
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
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.ReferenceInstruction
|
||||||
@ -27,17 +25,18 @@ class ComponentParserPatch : BytecodePatch(
|
|||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared fingerprint
|
||||||
|
*/
|
||||||
EmptyComponentBuilderFingerprint.result?.let {
|
EmptyComponentBuilderFingerprint.result?.let {
|
||||||
it.mutableMethod.apply {
|
it.mutableMethod.apply {
|
||||||
val targetStringIndex = getStringIndex("Error while converting %s")
|
insertMethod = this
|
||||||
|
emptyComponentIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||||
for (index in targetStringIndex until implementation!!.instructions.size - 1) {
|
|
||||||
if (getInstruction(index).opcode != Opcode.INVOKE_STATIC_RANGE) continue
|
|
||||||
|
|
||||||
val builderMethodDescriptor =
|
val builderMethodDescriptor =
|
||||||
getInstruction<ReferenceInstruction>(index).reference
|
getInstruction<ReferenceInstruction>(emptyComponentIndex).reference
|
||||||
val emptyComponentFieldDescriptor =
|
val emptyComponentFieldDescriptor =
|
||||||
getInstruction<ReferenceInstruction>(index + 2).reference
|
getInstruction<ReferenceInstruction>(emptyComponentIndex + 2).reference
|
||||||
|
|
||||||
emptyComponentLabel = """
|
emptyComponentLabel = """
|
||||||
move-object/from16 v0, p1
|
move-object/from16 v0, p1
|
||||||
@ -46,17 +45,6 @@ class ComponentParserPatch : BytecodePatch(
|
|||||||
iget-object v0, v0, $emptyComponentFieldDescriptor
|
iget-object v0, v0, $emptyComponentFieldDescriptor
|
||||||
return-object v0
|
return-object v0
|
||||||
"""
|
"""
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (emptyComponentLabel.isEmpty())
|
|
||||||
throw PatchException("could not find Empty Component Label in method")
|
|
||||||
}
|
|
||||||
} ?: throw EmptyComponentBuilderFingerprint.exception
|
|
||||||
|
|
||||||
IdentifierFingerprint.result?.let {
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
insertMethod = this
|
|
||||||
|
|
||||||
val stringBuilderIndex =
|
val stringBuilderIndex =
|
||||||
implementation!!.instructions.indexOfFirst { instruction ->
|
implementation!!.instructions.indexOfFirst { instruction ->
|
||||||
@ -65,29 +53,26 @@ class ComponentParserPatch : BytecodePatch(
|
|||||||
fieldReference?.let { reference -> reference.type == "Ljava/lang/StringBuilder;" } == true
|
fieldReference?.let { reference -> reference.type == "Ljava/lang/StringBuilder;" } == true
|
||||||
}
|
}
|
||||||
|
|
||||||
val identifierIndex = it.scanResult.patternScanResult!!.endIndex
|
|
||||||
val objectIndex = getStringIndex("") + 1
|
|
||||||
val freeIndex = implementation!!.instructions.indexOfFirst { instruction ->
|
|
||||||
instruction.opcode == Opcode.CONST
|
|
||||||
}
|
|
||||||
|
|
||||||
stringBuilderRegister =
|
stringBuilderRegister =
|
||||||
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
|
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
|
||||||
identifierRegister =
|
|
||||||
getInstruction<OneRegisterInstruction>(identifierIndex).registerA
|
|
||||||
objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC
|
|
||||||
|
|
||||||
val register = getInstruction<OneRegisterInstruction>(freeIndex).registerA
|
|
||||||
|
|
||||||
freeRegister =
|
|
||||||
if (register == stringBuilderRegister || register == identifierRegister || register == objectRegister)
|
|
||||||
15
|
|
||||||
else
|
|
||||||
register
|
|
||||||
|
|
||||||
insertIndex = stringBuilderIndex + 1
|
insertIndex = stringBuilderIndex + 1
|
||||||
}
|
}
|
||||||
} ?: throw IdentifierFingerprint.exception
|
} ?: throw EmptyComponentBuilderFingerprint.exception
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only used in YouTube
|
||||||
|
*/
|
||||||
|
IdentifierFingerprint.result?.let {
|
||||||
|
it.mutableMethod.apply {
|
||||||
|
val identifierIndex = it.scanResult.patternScanResult!!.endIndex
|
||||||
|
val objectIndex = getStringIndex("") + 1
|
||||||
|
|
||||||
|
identifierRegister =
|
||||||
|
getInstruction<OneRegisterInstruction>(identifierIndex).registerA
|
||||||
|
objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,42 +80,35 @@ class ComponentParserPatch : BytecodePatch(
|
|||||||
lateinit var emptyComponentLabel: String
|
lateinit var emptyComponentLabel: String
|
||||||
lateinit var insertMethod: MutableMethod
|
lateinit var insertMethod: MutableMethod
|
||||||
|
|
||||||
|
var emptyComponentIndex by Delegates.notNull<Int>()
|
||||||
var insertIndex by Delegates.notNull<Int>()
|
var insertIndex by Delegates.notNull<Int>()
|
||||||
|
|
||||||
var freeRegister = 15
|
|
||||||
|
|
||||||
var identifierRegister by Delegates.notNull<Int>()
|
var identifierRegister by Delegates.notNull<Int>()
|
||||||
var objectRegister by Delegates.notNull<Int>()
|
var objectRegister by Delegates.notNull<Int>()
|
||||||
var stringBuilderRegister by Delegates.notNull<Int>()
|
var stringBuilderRegister by Delegates.notNull<Int>()
|
||||||
|
|
||||||
fun generalHook(
|
fun generalHook(descriptor: String) {
|
||||||
descriptor: String
|
|
||||||
) {
|
|
||||||
insertMethod.apply {
|
insertMethod.apply {
|
||||||
addInstructionsWithLabels(
|
addInstructionsWithLabels(
|
||||||
insertIndex,
|
insertIndex,
|
||||||
"""
|
"""
|
||||||
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
|
invoke-static {v$stringBuilderRegister, v$identifierRegister, v$objectRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)Z
|
||||||
move-result v$freeRegister
|
move-result v$stringBuilderRegister
|
||||||
if-eqz v$freeRegister, :unfiltered
|
if-nez v$stringBuilderRegister, :filter
|
||||||
""" + emptyComponentLabel,
|
""", ExternalLabel("filter", getInstruction(emptyComponentIndex))
|
||||||
ExternalLabel("unfiltered", getInstruction(insertIndex))
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun identifierHook(
|
fun pathBuilderHook(descriptor: String) {
|
||||||
descriptor: String
|
|
||||||
) {
|
|
||||||
insertMethod.apply {
|
insertMethod.apply {
|
||||||
addInstructionsWithLabels(
|
addInstructionsWithLabels(
|
||||||
insertIndex,
|
insertIndex,
|
||||||
"""
|
"""
|
||||||
invoke-static {v$stringBuilderRegister, v$identifierRegister}, $descriptor(Ljava/lang/StringBuilder;Ljava/lang/String;)Z
|
invoke-static {v$stringBuilderRegister}, $descriptor(Ljava/lang/StringBuilder;)Z
|
||||||
move-result v$freeRegister
|
move-result v$stringBuilderRegister
|
||||||
if-eqz v$freeRegister, :unfiltered
|
if-nez v$stringBuilderRegister, :filter
|
||||||
""" + emptyComponentLabel,
|
""", ExternalLabel("filter", getInstruction(emptyComponentIndex))
|
||||||
ExternalLabel("unfiltered", getInstruction(insertIndex))
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user