feat(YouTube): replace with a fingerprint that supports a wider range of versions

This commit is contained in:
inotia00
2024-10-06 18:41:52 +09:00
parent 12127d6f25
commit 41e00d6a4f
13 changed files with 173 additions and 43 deletions

View File

@ -16,10 +16,12 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
import app.revanced.patcher.util.proxy.mutableTypes.MutableField
import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.util.fingerprint.MultiMethodFingerprint
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.MethodParameter
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@ -30,6 +32,8 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.Reference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import com.android.tools.smali.dexlib2.immutable.ImmutableField
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation
import com.android.tools.smali.dexlib2.util.MethodUtil
const val REGISTER_TEMPLATE_REPLACEMENT: String = "REGISTER_INDEX"
@ -55,6 +59,18 @@ val MultiMethodFingerprint.exception
fun MethodFingerprint.alsoResolve(context: BytecodeContext, fingerprint: MethodFingerprint) =
also { resolve(context, fingerprint.resultOrThrow().classDef) }.resultOrThrow()
fun MethodFingerprint.getMethodCall() =
resultOrThrow().mutableMethod.getMethodCall()
fun MutableMethod.getMethodCall(): String {
var methodCall = "$definingClass->$name("
for (i in 0 until parameters.size) {
methodCall += parameterTypes[i]
}
methodCall += ")$returnType"
return methodCall
}
/**
* Find the [MutableMethod] from a given [Method] in a [MutableClass].
*
@ -371,7 +387,7 @@ fun Method.findOpcodeIndicesReversed(opcode: Opcode): List<Int> =
fun Method.findOpcodeIndicesReversed(filter: Instruction.() -> Boolean): List<Int> {
val indexes = implementation!!.instructions
.withIndex()
.filter { (_, instruction) -> filter.invoke(instruction) }
.filter { (_, instruction) -> filter(instruction) }
.map { (index, _) -> index }
.reversed()
@ -573,6 +589,38 @@ fun BytecodeContext.updatePatchStatus(
"const/4 v0, 0x1"
)
/**
* Taken from BiliRoamingX:
* https://github.com/BiliRoamingX/BiliRoamingX/blob/ae58109f3acdd53ec2d2b3fb439c2a2ef1886221/patches/src/main/kotlin/app/revanced/patches/bilibili/utils/Extenstions.kt#L51
*/
fun Method.cloneMutable(
registerCount: Int = implementation?.registerCount ?: 0,
clearImplementation: Boolean = false,
name: String = this.name,
accessFlags: Int = this.accessFlags,
parameters: List<MethodParameter> = this.parameters,
returnType: String = this.returnType
): MutableMethod {
val clonedImplementation = implementation?.let {
ImmutableMethodImplementation(
registerCount,
if (clearImplementation) emptyList() else it.instructions,
if (clearImplementation) emptyList() else it.tryBlocks,
if (clearImplementation) emptyList() else it.debugItems,
)
}
return ImmutableMethod(
definingClass,
name,
parameters,
returnType,
accessFlags,
annotations,
hiddenApiRestrictions,
clonedImplementation
).toMutable()
}
/**
* Return the resolved methods of [MethodFingerprint]s early.
*/

View File

@ -13,6 +13,9 @@ private typealias StringMatch = MethodFingerprintResult.MethodFingerprintScanRes
private typealias StringsScanResult = MethodFingerprintResult.MethodFingerprintScanResult.StringsScanResult
/**
* Taken from BiliRoamingX:
* https://github.com/BiliRoamingX/BiliRoamingX/blob/ae58109f3acdd53ec2d2b3fb439c2a2ef1886221/patches/src/main/kotlin/app/revanced/patches/bilibili/patcher/fingerprint/MultiMethodFingerprint.kt
*
* Represents the [MethodFingerprint] for a method.
* @param returnType The return type of the method.
* @param accessFlags The access flags of the method.

View File

@ -6,6 +6,10 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.util.fingerprint.MultiMethodFingerprint
import app.revanced.util.fingerprint.MultiMethodFingerprint.Companion.resolve
/**
* Taken from BiliRoamingX:
* https://github.com/BiliRoamingX/BiliRoamingX/blob/ae58109f3acdd53ec2d2b3fb439c2a2ef1886221/patches/src/main/kotlin/app/revanced/patches/bilibili/patcher/patch/MultiMethodBytecodePatch.kt
*/
abstract class MultiMethodBytecodePatch(
val fingerprints: Set<MethodFingerprint> = setOf(),
val multiFingerprints: Set<MultiMethodFingerprint> = setOf()