chore: lint code

This commit is contained in:
inotia00
2024-03-23 00:02:02 +09:00
parent 49727dfb3a
commit 3d8e3bb0be
11 changed files with 146 additions and 185 deletions

View File

@ -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 ->

View File

@ -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())
}
)