oSumAtrIX 3651981161
feat: migrate to dexlib
BREAKING CHANGE: Removed usage of ASM library
2022-06-05 08:02:51 +02:00

33 lines
1.2 KiB
Kotlin

package app.revanced.patcher.cache
import app.revanced.patcher.cache.proxy.ClassProxy
import app.revanced.patcher.signature.MethodSignatureScanResult
import org.jf.dexlib2.iface.ClassDef
class Cache(
internal val classes: Set<ClassDef>,
val resolvedMethods: MethodMap
) {
internal val classProxy = mutableListOf<ClassProxy>()
fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? {
// if a class has been found with the given predicate,
val foundClass = classes.singleOrNull(predicate) ?: return null
// create a class proxy with the index of the class in the classes list
// TODO: There might be a more elegant way to the comment above
val classProxy = ClassProxy(foundClass, classes.indexOf(foundClass))
// add it to the cache and
this.classProxy.add(classProxy)
// return the proxy class
return classProxy
}
}
class MethodMap : LinkedHashMap<String, MethodSignatureScanResult>() {
override fun get(key: String): MethodSignatureScanResult {
return super.get(key) ?: throw MethodNotFoundException("Method $key was not found in the method cache")
}
}
class MethodNotFoundException(s: String) : Exception(s)