55 lines
No EOL
1.8 KiB
Kotlin
55 lines
No EOL
1.8 KiB
Kotlin
package app.revanced.extensions
|
|
|
|
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
|
import app.revanced.patcher.extensions.addInstruction
|
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
import app.revanced.patcher.patch.PatchResultError
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|
import org.jf.dexlib2.iface.Method
|
|
import org.jf.dexlib2.util.MethodUtil
|
|
import org.w3c.dom.Node
|
|
|
|
// TODO: populate this to all patches
|
|
/**
|
|
* Convert a [MethodFingerprint] to a [PatchResultError].
|
|
*
|
|
* @return A [PatchResultError] for the [MethodFingerprint].
|
|
*/
|
|
fun MethodFingerprint.toErrorResult() = PatchResultError("Failed to resolve $name")
|
|
|
|
/**
|
|
* Find the [MutableMethod] from a given [Method] in a [MutableClass].
|
|
*
|
|
* @param method The [Method] to find.
|
|
* @return The [MutableMethod].
|
|
*/
|
|
fun MutableClass.findMutableMethodOf(method: Method) = this.methods.first {
|
|
MethodUtil.methodSignaturesMatch(it, method)
|
|
}
|
|
|
|
/**
|
|
* apply a transform to all methods of the class
|
|
*
|
|
* @param transform the transformation function. original method goes in, transformed method goes out
|
|
*/
|
|
fun MutableClass.transformMethods(transform: MutableMethod.() -> MutableMethod) {
|
|
val transformedMethods = methods.map { it.transform() }
|
|
methods.clear()
|
|
methods.addAll(transformedMethods)
|
|
}
|
|
|
|
internal fun Node.doRecursively(action: (Node) -> Unit) {
|
|
action(this)
|
|
for (i in 0 until this.childNodes.length) this.childNodes.item(i).doRecursively(action)
|
|
}
|
|
|
|
fun MutableMethod.injectHideViewCall(
|
|
insertIndex: Int,
|
|
viewRegister: Int,
|
|
classDescriptor: String,
|
|
targetMethod: String
|
|
) = addInstruction(
|
|
insertIndex,
|
|
"invoke-static { v$viewRegister }, $classDescriptor->$targetMethod(Landroid/view/View;)V"
|
|
) |