mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
refactor: fix package and code structure
This commit is contained in:
@ -7,6 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprintResult
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField
|
||||
@ -172,6 +173,33 @@ fun MutableMethod.getTargetIndexReversed(startIndex: Int, opcode: Opcode): Int {
|
||||
return -1
|
||||
}
|
||||
|
||||
fun Method.getTargetIndexWithFieldReferenceName(filedName: String) = implementation?.let {
|
||||
it.instructions.indexOfFirst { instruction ->
|
||||
instruction.getReference<FieldReference>()?.name == filedName
|
||||
}
|
||||
} ?: -1
|
||||
|
||||
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(returnType: String)
|
||||
= getTargetIndexWithFieldReferenceTypeReversed(implementation!!.instructions.size - 1, returnType)
|
||||
|
||||
fun MutableMethod.getTargetIndexWithFieldReferenceName(startIndex: Int, filedName: String) =
|
||||
implementation!!.instructions.let {
|
||||
startIndex + it.subList(startIndex, it.size - 1).indexOfFirst { instruction ->
|
||||
instruction.getReference<FieldReference>()?.name == filedName
|
||||
}
|
||||
}
|
||||
|
||||
fun MutableMethod.getTargetIndexWithFieldReferenceNameReversed(startIndex: Int, filedName: String): Int {
|
||||
for (index in startIndex downTo 0) {
|
||||
val instruction = getInstruction(index)
|
||||
if (instruction.getReference<FieldReference>()?.name != filedName)
|
||||
continue
|
||||
|
||||
return index
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
fun Method.getTargetIndexWithFieldReferenceType(returnType: String) = implementation?.let {
|
||||
it.instructions.indexOfFirst { instruction ->
|
||||
instruction.getReference<FieldReference>()?.type == returnType
|
||||
@ -257,6 +285,9 @@ fun MutableMethod.getTargetIndexWithReferenceReversed(startIndex: Int, reference
|
||||
return -1
|
||||
}
|
||||
|
||||
fun MethodFingerprintResult.getWalkerMethod(context: BytecodeContext, index: Int) =
|
||||
mutableMethod.getWalkerMethod(context, index)
|
||||
|
||||
fun MutableMethod.getWalkerMethod(context: BytecodeContext, index: Int) =
|
||||
context.toMethodWalker(this)
|
||||
.nextMethod(index, true)
|
||||
|
@ -0,0 +1,34 @@
|
||||
package app.revanced.util.fingerprint
|
||||
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.util.containsReferenceInstructionIndex
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
/**
|
||||
* A fingerprint to resolve methods that contain a specific reference value.
|
||||
*
|
||||
* @param returnType The method's return type compared using String.startsWith.
|
||||
* @param accessFlags The method's exact access flags using values of AccessFlags.
|
||||
* @param parameters The parameters of the method. Partial matches allowed and follow the same rules as returnType.
|
||||
* @param opcodes An opcode pattern of the method's instructions. Wildcard or unknown opcodes can be specified by null.
|
||||
* @param strings A list of the method's strings compared each using String.contains.
|
||||
* @param reference A supplier for the reference value to check for.
|
||||
*/
|
||||
abstract class ReferenceFingerprint(
|
||||
returnType: String? = null,
|
||||
accessFlags: Int? = null,
|
||||
parameters: Iterable<String>? = null,
|
||||
opcodes: Iterable<Opcode>? = null,
|
||||
strings: Iterable<String>? = null,
|
||||
// Has to be a supplier because the fingerprint is created before patches can check reference.
|
||||
reference: () -> String
|
||||
) : MethodFingerprint(
|
||||
returnType = returnType,
|
||||
accessFlags = accessFlags,
|
||||
parameters = parameters,
|
||||
opcodes = opcodes,
|
||||
strings = strings,
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.containsReferenceInstructionIndex(reference())
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user