diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index 1e7433d..3bf2359 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -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, + signatures: Iterable, ) { private val cache: Cache private val patches = mutableSetOf() @@ -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) { this.patches.addAll(patches) } diff --git a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt b/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt index 8fa7302..4c560d6 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt @@ -15,6 +15,6 @@ data class MethodSignature( val name: String, val returnType: String?, val accessFlags: Int?, - val methodParameters: Array?, - val opcodes: Array? + val methodParameters: Iterable?, + val opcodes: Iterable? ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt b/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt index dd5e10f..7630a13 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt @@ -13,7 +13,7 @@ import org.jf.dexlib2.iface.instruction.Instruction // TODO: add logger back internal class SignatureResolver( private val classes: Set, - private val methodSignatures: Array + private val methodSignatures: Iterable ) { fun resolve(): MethodMap { val methodMap = MethodMap() @@ -84,8 +84,8 @@ internal class SignatureResolver( } } - private fun compareParameterTypes(signature: Array, original: MutableList): Boolean { - return signature.size != original.size || !(signature.all { a -> original.any { it.startsWith(a) } }) + private fun compareParameterTypes(signature: Iterable, original: MutableList): 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.scanFor(pattern: Array): PatternScanResult? { +private fun MutableIterable.scanFor(pattern: Iterable): 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) } diff --git a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt index c2b3cb9..fbf83b0 100644 --- a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt +++ b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt @@ -23,13 +23,13 @@ import kotlin.test.assertTrue internal class PatcherTest { companion object { - val testSignatures: Array = 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()