mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-13 02:14:27 +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.
|
* ReVanced Patcher.
|
||||||
* @param input The input file (an apk or any other multi dex container).
|
* @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(
|
class Patcher(
|
||||||
input: File,
|
input: File,
|
||||||
signatures: Array<MethodSignature>,
|
signatures: Iterable<MethodSignature>,
|
||||||
) {
|
) {
|
||||||
private val cache: Cache
|
private val cache: Cache
|
||||||
private val patches = mutableSetOf<Patch>()
|
private val patches = mutableSetOf<Patch>()
|
||||||
|
@ -92,7 +92,7 @@ class Patcher(
|
||||||
* Add a patch to the patcher.
|
* Add a patch to the patcher.
|
||||||
* @param patches The patches to add.
|
* @param patches The patches to add.
|
||||||
*/
|
*/
|
||||||
fun addPatches(vararg patches: Patch) {
|
fun addPatches(patches: Iterable<Patch>) {
|
||||||
this.patches.addAll(patches)
|
this.patches.addAll(patches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,6 @@ data class MethodSignature(
|
||||||
val name: String,
|
val name: String,
|
||||||
val returnType: String?,
|
val returnType: String?,
|
||||||
val accessFlags: Int?,
|
val accessFlags: Int?,
|
||||||
val methodParameters: Array<String>?,
|
val methodParameters: Iterable<String>?,
|
||||||
val opcodes: Array<Opcode>?
|
val opcodes: Iterable<Opcode>?
|
||||||
)
|
)
|
|
@ -13,7 +13,7 @@ import org.jf.dexlib2.iface.instruction.Instruction
|
||||||
// TODO: add logger back
|
// TODO: add logger back
|
||||||
internal class SignatureResolver(
|
internal class SignatureResolver(
|
||||||
private val classes: Set<ClassDef>,
|
private val classes: Set<ClassDef>,
|
||||||
private val methodSignatures: Array<MethodSignature>
|
private val methodSignatures: Iterable<MethodSignature>
|
||||||
) {
|
) {
|
||||||
fun resolve(): MethodMap {
|
fun resolve(): MethodMap {
|
||||||
val methodMap = MethodMap()
|
val methodMap = MethodMap()
|
||||||
|
@ -84,8 +84,8 @@ internal class SignatureResolver(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compareParameterTypes(signature: Array<String>, original: MutableList<out CharSequence>): Boolean {
|
private fun compareParameterTypes(signature: Iterable<String>, original: MutableList<out CharSequence>): Boolean {
|
||||||
return signature.size != original.size || !(signature.all { a -> original.any { it.startsWith(a) } })
|
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.component1() = this
|
||||||
private operator fun ClassDef.component2() = this.methods
|
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 count = this.count()
|
||||||
|
val size = pattern.count()
|
||||||
for (instructionIndex in 0 until count) {
|
for (instructionIndex in 0 until count) {
|
||||||
var patternIndex = 0
|
var patternIndex = 0
|
||||||
while (instructionIndex + patternIndex < count) {
|
while (instructionIndex + patternIndex < count) {
|
||||||
if (this.elementAt(instructionIndex + patternIndex).opcode != pattern[patternIndex]) break
|
if (this.elementAt(instructionIndex + patternIndex).opcode != pattern.elementAt(patternIndex)) break
|
||||||
if (++patternIndex < pattern.size) continue
|
if (++patternIndex < size) continue
|
||||||
|
|
||||||
return PatternScanResult(instructionIndex, instructionIndex + patternIndex)
|
return PatternScanResult(instructionIndex, instructionIndex + patternIndex)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,13 @@ import kotlin.test.assertTrue
|
||||||
|
|
||||||
internal class PatcherTest {
|
internal class PatcherTest {
|
||||||
companion object {
|
companion object {
|
||||||
val testSignatures: Array<MethodSignature> = arrayOf(
|
val testSignatures = listOf(
|
||||||
MethodSignature(
|
MethodSignature(
|
||||||
"main-method",
|
"main-method",
|
||||||
"V",
|
"V",
|
||||||
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||||
arrayOf("[L"),
|
listOf("[L"),
|
||||||
arrayOf(
|
listOf(
|
||||||
Opcode.CONST_STRING,
|
Opcode.CONST_STRING,
|
||||||
Opcode.INVOKE_VIRTUAL,
|
Opcode.INVOKE_VIRTUAL,
|
||||||
Opcode.RETURN_VOID
|
Opcode.RETURN_VOID
|
||||||
|
@ -45,7 +45,7 @@ internal class PatcherTest {
|
||||||
testSignatures
|
testSignatures
|
||||||
)
|
)
|
||||||
|
|
||||||
patcher.addPatches(
|
patcher.addPatches(listOf(
|
||||||
object : Patch("TestPatch") {
|
object : Patch("TestPatch") {
|
||||||
override fun execute(cache: Cache): PatchResult {
|
override fun execute(cache: Cache): PatchResult {
|
||||||
// Get the result from the resolver cache
|
// Get the result from the resolver cache
|
||||||
|
@ -146,7 +146,7 @@ internal class PatcherTest {
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
))
|
||||||
|
|
||||||
// Apply all patches loaded in the patcher
|
// Apply all patches loaded in the patcher
|
||||||
val patchResult = patcher.applyPatches()
|
val patchResult = patcher.applyPatches()
|
||||||
|
|
Loading…
Reference in a new issue