mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
refactor: Change all references from Array to Iterable
BREAKING CHANGE: arrayOf has to be changed to listOf.
This commit is contained in:
parent
9659a61c5c
commit
72f3cad3f9
4 changed files with 17 additions and 16 deletions
|
@ -20,11 +20,11 @@ val NAMER = BasicDexFileNamer()
|
|||
/**
|
||||
* ReVanced Patcher.
|
||||
* @param input The input file (an apk or any other multi dex container).
|
||||
* @param signatures An array of method signatures for the patches
|
||||
* @param signatures A list of method signatures for the patches.
|
||||
*/
|
||||
class Patcher(
|
||||
input: File,
|
||||
signatures: Array<MethodSignature>,
|
||||
signatures: Iterable<MethodSignature>,
|
||||
) {
|
||||
private val cache: Cache
|
||||
private val patches = mutableSetOf<Patch>()
|
||||
|
@ -92,7 +92,7 @@ class Patcher(
|
|||
* Add a patch to the patcher.
|
||||
* @param patches The patches to add.
|
||||
*/
|
||||
fun addPatches(vararg patches: Patch) {
|
||||
fun addPatches(patches: Iterable<Patch>) {
|
||||
this.patches.addAll(patches)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,6 @@ data class MethodSignature(
|
|||
val name: String,
|
||||
val returnType: String?,
|
||||
val accessFlags: Int?,
|
||||
val methodParameters: Array<String>?,
|
||||
val opcodes: Array<Opcode>?
|
||||
val methodParameters: Iterable<String>?,
|
||||
val opcodes: Iterable<Opcode>?
|
||||
)
|
|
@ -13,7 +13,7 @@ import org.jf.dexlib2.iface.instruction.Instruction
|
|||
// TODO: add logger back
|
||||
internal class SignatureResolver(
|
||||
private val classes: Set<ClassDef>,
|
||||
private val methodSignatures: Array<MethodSignature>
|
||||
private val methodSignatures: Iterable<MethodSignature>
|
||||
) {
|
||||
fun resolve(): MethodMap {
|
||||
val methodMap = MethodMap()
|
||||
|
@ -84,8 +84,8 @@ internal class SignatureResolver(
|
|||
}
|
||||
}
|
||||
|
||||
private fun compareParameterTypes(signature: Array<String>, original: MutableList<out CharSequence>): Boolean {
|
||||
return signature.size != original.size || !(signature.all { a -> original.any { it.startsWith(a) } })
|
||||
private fun compareParameterTypes(signature: Iterable<String>, original: MutableList<out CharSequence>): Boolean {
|
||||
return signature.count() != original.size || !(signature.all { a -> original.any { it.startsWith(a) } })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,13 +93,14 @@ internal class SignatureResolver(
|
|||
private operator fun ClassDef.component1() = this
|
||||
private operator fun ClassDef.component2() = this.methods
|
||||
|
||||
private fun MutableIterable<Instruction>.scanFor(pattern: Array<Opcode>): PatternScanResult? {
|
||||
private fun MutableIterable<Instruction>.scanFor(pattern: Iterable<Opcode>): PatternScanResult? {
|
||||
val count = this.count()
|
||||
val size = pattern.count()
|
||||
for (instructionIndex in 0 until count) {
|
||||
var patternIndex = 0
|
||||
while (instructionIndex + patternIndex < count) {
|
||||
if (this.elementAt(instructionIndex + patternIndex).opcode != pattern[patternIndex]) break
|
||||
if (++patternIndex < pattern.size) continue
|
||||
if (this.elementAt(instructionIndex + patternIndex).opcode != pattern.elementAt(patternIndex)) break
|
||||
if (++patternIndex < size) continue
|
||||
|
||||
return PatternScanResult(instructionIndex, instructionIndex + patternIndex)
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ import kotlin.test.assertTrue
|
|||
|
||||
internal class PatcherTest {
|
||||
companion object {
|
||||
val testSignatures: Array<MethodSignature> = arrayOf(
|
||||
val testSignatures = listOf(
|
||||
MethodSignature(
|
||||
"main-method",
|
||||
"V",
|
||||
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
arrayOf("[L"),
|
||||
arrayOf(
|
||||
listOf("[L"),
|
||||
listOf(
|
||||
Opcode.CONST_STRING,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.RETURN_VOID
|
||||
|
@ -45,7 +45,7 @@ internal class PatcherTest {
|
|||
testSignatures
|
||||
)
|
||||
|
||||
patcher.addPatches(
|
||||
patcher.addPatches(listOf(
|
||||
object : Patch("TestPatch") {
|
||||
override fun execute(cache: Cache): PatchResult {
|
||||
// Get the result from the resolver cache
|
||||
|
@ -146,7 +146,7 @@ internal class PatcherTest {
|
|||
return PatchResultSuccess()
|
||||
}
|
||||
}
|
||||
)
|
||||
))
|
||||
|
||||
// Apply all patches loaded in the patcher
|
||||
val patchResult = patcher.applyPatches()
|
||||
|
|
Loading…
Reference in a new issue