From d15240d0330a63c4b568fc5de3de861b8046cba4 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 6 Apr 2022 19:36:02 +0200 Subject: [PATCH] fix: Patcher not writing resolved methods --- src/main/kotlin/app/revanced/patcher/Patcher.kt | 12 ++++++++++-- src/main/kotlin/app/revanced/patcher/cache/Cache.kt | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index d53a059..042f6da 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -39,10 +39,13 @@ class Patcher( val newDexFile = object : DexFile { override fun getClasses(): Set { // this is a slow workaround for now + cache.methodMap.values.forEach { + if (!it.definingClassProxy.proxyUsed) return@forEach + cache.classes.replace(it.definingClassProxy.originalIndex, it.definingClassProxy.mutatedClass) + } cache.classProxy .filter { it.proxyUsed }.forEach { proxy -> - cache.classes.remove(cache.classes.elementAt(proxy.originalIndex)) - cache.classes.add(proxy.mutatedClass) + cache.classes.replace(proxy.originalIndex, proxy.mutatedClass) } return cache.classes @@ -87,3 +90,8 @@ class Patcher( } } } + +private fun MutableSet.replace(originalIndex: Int, mutatedClass: ClassDef) { + this.remove(this.elementAt(originalIndex)) + this.add(mutatedClass) +} diff --git a/src/main/kotlin/app/revanced/patcher/cache/Cache.kt b/src/main/kotlin/app/revanced/patcher/cache/Cache.kt index 4b66fac..c5a1be1 100644 --- a/src/main/kotlin/app/revanced/patcher/cache/Cache.kt +++ b/src/main/kotlin/app/revanced/patcher/cache/Cache.kt @@ -6,7 +6,7 @@ import org.jf.dexlib2.iface.ClassDef class Cache( internal val classes: MutableSet, - val resolvedMethods: MethodMap + val methodMap: MethodMap ) { // TODO: currently we create ClassProxies at multiple places, which is why we could have merge conflicts // this can be solved by creating a dedicated method for creating class proxies,