Skip to content

Commit

Permalink
fix proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Apr 30, 2024
1 parent 58c61f7 commit 55bba4b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/4_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A handful of APIs are available to make patch development easier and more effici

## 📙 Overview

1. 👹 Mutate classes with `classDex.proxy()`
1. 👹 Mutate classes with `context.proxy(ClassDef)`
2. 🔍 Find and proxy existing classes with `classBy(Predicate)`
3. 🏃‍ Easily access referenced methods recursively by index with `MethodNavigator`
4. 🔨 Make use of extension functions from `BytecodeUtils` and `ResourceUtils` with certain applications (Available in ReVanced Patches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ class MethodFingerprintResult(
* Use [classDef] where possible.
*/
val mutableClass by lazy {
with(context) {
classDef.proxy().mutableClass
}
context.proxy(classDef).mutableClass
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ class BytecodePatchContext internal constructor(private val config: PatcherConfi
* @return A proxy for the first class that matches the predicate.
*/
fun classBy(predicate: (ClassDef) -> Boolean) =
classes.proxyPool.find { predicate(it.immutableClass) } ?: classes.find(predicate)?.proxy()
classes.proxyPool.find { predicate(it.immutableClass) } ?: classes.find(predicate)?.let { proxy(it) }

/**
* Proxy the class to allow mutation.
*
* @param classDef The class to proxy.
*
* @return A proxy for the class.
*/
fun ClassDef.proxy() = this@BytecodePatchContext.classes.proxyPool.find { it.immutableClass.type == type }
?: ClassProxy(this).also { this@BytecodePatchContext.classes.proxyPool.add(it) }
fun proxy(classDef: ClassDef) = this@BytecodePatchContext.classes.proxyPool.find {
it.immutableClass.type == classDef.type
} ?: ClassProxy(classDef).also { this@BytecodePatchContext.classes.proxyPool.add(it) }

/**
* Navigate a method.
Expand Down

0 comments on commit 55bba4b

Please sign in to comment.