feat: Use an extension property to create new exception when failing to resolve a fingerprint
This commit adds the extension property to the public API
This commit is contained in:
@ -15,11 +15,12 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
import org.w3c.dom.Node
|
||||
|
||||
/**
|
||||
* Return [PatchException] from a [MethodFingerprint].
|
||||
* The [PatchException] of failing to resolve a [MethodFingerprint].
|
||||
*
|
||||
* @return The [PatchException] for the [MethodFingerprint].
|
||||
* @return The [PatchException].
|
||||
*/
|
||||
internal fun MethodFingerprint.toErrorResult() = PatchException("Failed to resolve $name")
|
||||
val MethodFingerprint.exception
|
||||
get() = PatchException("Failed to resolve $name")
|
||||
|
||||
/**
|
||||
* Find the [MutableMethod] from a given [Method] in a [MutableClass].
|
||||
@ -27,27 +28,27 @@ internal fun MethodFingerprint.toErrorResult() = PatchException("Failed to resol
|
||||
* @param method The [Method] to find.
|
||||
* @return The [MutableMethod].
|
||||
*/
|
||||
internal fun MutableClass.findMutableMethodOf(method: Method) = this.methods.first {
|
||||
fun MutableClass.findMutableMethodOf(method: Method) = this.methods.first {
|
||||
MethodUtil.methodSignaturesMatch(it, method)
|
||||
}
|
||||
|
||||
/**
|
||||
* apply a transform to all methods of the class
|
||||
* apply a transform to all methods of the class.
|
||||
*
|
||||
* @param transform the transformation function. original method goes in, transformed method goes out
|
||||
* @param transform the transformation function. original method goes in, transformed method goes out.
|
||||
*/
|
||||
internal fun MutableClass.transformMethods(transform: MutableMethod.() -> MutableMethod) {
|
||||
fun MutableClass.transformMethods(transform: MutableMethod.() -> MutableMethod) {
|
||||
val transformedMethods = methods.map { it.transform() }
|
||||
methods.clear()
|
||||
methods.addAll(transformedMethods)
|
||||
}
|
||||
|
||||
internal fun Node.doRecursively(action: (Node) -> Unit) {
|
||||
fun Node.doRecursively(action: (Node) -> Unit) {
|
||||
action(this)
|
||||
for (i in 0 until this.childNodes.length) this.childNodes.item(i).doRecursively(action)
|
||||
}
|
||||
|
||||
internal fun MutableMethod.injectHideViewCall(
|
||||
fun MutableMethod.injectHideViewCall(
|
||||
insertIndex: Int,
|
||||
viewRegister: Int,
|
||||
classDescriptor: String,
|
||||
@ -57,7 +58,13 @@ internal fun MutableMethod.injectHideViewCall(
|
||||
"invoke-static { v$viewRegister }, $classDescriptor->$targetMethod(Landroid/view/View;)V"
|
||||
)
|
||||
|
||||
internal fun Method.findIndexForIdResource(resourceName: String): Int {
|
||||
/**
|
||||
* Find the index of the first constant instruction with the id of the given resource name.
|
||||
*
|
||||
* @param resourceName the name of the resource to find the id for.
|
||||
* @return the index of the first constant instruction with the id of the given resource name, or -1 if not found.
|
||||
*/
|
||||
fun Method.findIndexForIdResource(resourceName: String): Int {
|
||||
fun getIdResourceId(resourceName: String) = ResourceMappingPatch.resourceMappings.single {
|
||||
it.type == "id" && it.name == resourceName
|
||||
}.id
|
||||
@ -66,6 +73,8 @@ internal fun Method.findIndexForIdResource(resourceName: String): Int {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the index of the first constant instruction with the given value.
|
||||
*
|
||||
* @return the first constant instruction with the value, or -1 if not found.
|
||||
*/
|
||||
fun Method.indexOfFirstConstantInstructionValue(constantValue: Long): Int {
|
||||
@ -77,6 +86,8 @@ fun Method.indexOfFirstConstantInstructionValue(constantValue: Long): Int {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the method contains a constant with the given value.
|
||||
*
|
||||
* @return if the method contains a constant with the given value.
|
||||
*/
|
||||
fun Method.containsConstantInstructionValue(constantValue: Long): Boolean {
|
||||
@ -84,10 +95,10 @@ fun Method.containsConstantInstructionValue(constantValue: Long): Boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* traverse the class hierarchy starting from the given root class
|
||||
* Traverse the class hierarchy starting from the given root class.
|
||||
*
|
||||
* @param targetClass the class to start traversing the class hierarchy from
|
||||
* @param callback function that is called for every class in the hierarchy
|
||||
* @param targetClass the class to start traversing the class hierarchy from.
|
||||
* @param callback function that is called for every class in the hierarchy.
|
||||
*/
|
||||
fun BytecodeContext.traverseClassHierarchy(targetClass: MutableClass, callback: MutableClass.() -> Unit) {
|
||||
callback(targetClass)
|
||||
|
Reference in New Issue
Block a user