mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
chore: lint code
This commit is contained in:
@ -143,6 +143,15 @@ fun BytecodeContext.traverseClassHierarchy(
|
||||
inline fun <reified T : Reference> Instruction.getReference() =
|
||||
(this as? ReferenceInstruction)?.reference as? T
|
||||
|
||||
/**
|
||||
* Get the index of the first [Instruction] that matches the predicate.
|
||||
*
|
||||
* @param predicate The predicate to match.
|
||||
* @return The index of the first [Instruction] that matches the predicate.
|
||||
*/
|
||||
fun Method.indexOfFirstInstruction(predicate: Instruction.() -> Boolean) =
|
||||
this.implementation!!.instructions.indexOfFirst(predicate)
|
||||
|
||||
fun MutableMethod.getTargetIndex(opcode: Opcode) = getTargetIndex(0, opcode)
|
||||
|
||||
fun MutableMethod.getTargetIndexReversed(opcode: Opcode) =
|
||||
@ -220,6 +229,12 @@ fun MutableMethod.getTargetIndexWithMethodReferenceNameReversed(startIndex: Int,
|
||||
return -1
|
||||
}
|
||||
|
||||
fun MutableMethod.getTargetIndexWithReference(reference: String)
|
||||
= getTargetIndexWithReference(0, reference)
|
||||
|
||||
fun MutableMethod.getTargetIndexWithReferenceReversed(reference: String)
|
||||
= getTargetIndexWithReferenceReversed(implementation!!.instructions.size - 1, reference)
|
||||
|
||||
fun MutableMethod.getTargetIndexWithReference(startIndex: Int, reference: String) =
|
||||
implementation!!.instructions.let {
|
||||
startIndex + it.subList(startIndex, it.size - 1).indexOfFirst { instruction ->
|
||||
|
@ -0,0 +1,34 @@
|
||||
package app.revanced.util.fingerprint
|
||||
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.util.containsMethodReferenceNameInstructionIndex
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
/**
|
||||
* A fingerprint to resolve methods that contain a specific method reference name 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 method reference name value to check for.
|
||||
*/
|
||||
abstract class MethodReferenceNameFingerprint(
|
||||
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.containsMethodReferenceNameInstructionIndex(reference())
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user