Skip to content

Commit

Permalink
fix: Patcher not writing resolved methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 5, 2022
1 parent 544bcf7 commit fac44a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ class Patcher(
val newDexFile = object : DexFile {
override fun getClasses(): Set<ClassDef> {
// 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
Expand Down Expand Up @@ -87,3 +90,8 @@ class Patcher(
}
}
}

private fun MutableSet<ClassDef>.replace(originalIndex: Int, mutatedClass: ClassDef) {
this.remove(this.elementAt(originalIndex))
this.add(mutatedClass)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/app/revanced/patcher/cache/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jf.dexlib2.iface.ClassDef

class Cache(
internal val classes: MutableSet<ClassDef>,
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,
Expand Down

0 comments on commit fac44a5

Please sign in to comment.