mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
feat(YouTube): replace with a fingerprint that supports a wider range of versions
This commit is contained in:
@ -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.
|
||||
*/
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user