diff --git a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt index 47f2358..5e64bdd 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt @@ -5,8 +5,10 @@ import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.builder.BuilderInstruction import org.jf.dexlib2.builder.MutableMethodImplementation import org.jf.dexlib2.iface.Method +import org.jf.dexlib2.iface.reference.MethodReference import org.jf.dexlib2.immutable.ImmutableMethod import org.jf.dexlib2.immutable.ImmutableMethodImplementation +import org.jf.dexlib2.util.MethodUtil infix fun AccessFlags.or(other: AccessFlags) = this.value or other.value infix fun Int.or(other: AccessFlags) = this or other.value @@ -23,7 +25,7 @@ fun MutableMethodImplementation.addInstructions(index: Int, instructions: List, + parameters2: Iterable +): Boolean { + return parameters1.count() == parameters2.count() && parameters1.all { parameter -> + parameters2.any { + it.startsWith( + parameter + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt b/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt index 05b1179..2a23aba 100644 --- a/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt +++ b/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt @@ -2,6 +2,7 @@ package app.revanced.patcher.methodWalker import app.revanced.patcher.MethodNotFoundException import app.revanced.patcher.PatcherData +import app.revanced.patcher.extensions.softCompareTo import app.revanced.patcher.proxy.mutableTypes.MutableMethod import org.jf.dexlib2.Format import org.jf.dexlib2.iface.Method @@ -38,13 +39,17 @@ class MethodWalker internal constructor( Preconditions.checkFormat(instruction.opcode, Format.Format35c) - val newMethodRef = (instruction as Instruction35c).reference as MethodReference - val proxy = patcherData.findClass(newMethodRef.definingClass)!! + val newMethod = (instruction as Instruction35c).reference as MethodReference + val proxy = patcherData.findClass(newMethod.definingClass)!! val methods = if (walkMutable) proxy.resolve().methods else proxy.immutableClass.methods - currentMethod = methods.first { it.name == newMethodRef.name } + currentMethod = methods.first { it -> + return@first it.softCompareTo(newMethod) + } return this } throw MethodNotFoundException("This method can not be walked at offset $offset inside the method ${currentMethod.name}") } + + } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt b/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt index f19488f..f3e4c5b 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt @@ -1,5 +1,6 @@ package app.revanced.patcher.signature +import app.revanced.patcher.extensions.softCompareTo import app.revanced.patcher.proxy.ClassProxy import app.revanced.patcher.signature.resolver.SignatureResolver import org.jf.dexlib2.iface.Method @@ -7,33 +8,33 @@ import org.jf.dexlib2.iface.Method /** * Represents the result of a [SignatureResolver]. * @param definingClassProxy The [ClassProxy] that the matching method was found in. - * @param resolvedMethodName The name of the actual matching method. + * @param resolvedMethod The actual matching method. * @param scanData Opcodes pattern scan result. */ data class SignatureResolverResult( val definingClassProxy: ClassProxy, val scanData: PatternScanResult, - private val resolvedMethodName: String, + private val resolvedMethod: Method, ) { /** - * Returns the **mutable** method by the [resolvedMethodName] from the [definingClassProxy]. + * Returns the **mutable** method by the [resolvedMethod] from the [definingClassProxy]. * * Please note, this method allocates a [ClassProxy]. * Use [immutableMethod] where possible. */ val method get() = definingClassProxy.resolve().methods.first { - it.name == resolvedMethodName + it.softCompareTo(resolvedMethod) } /** - * Returns the **immutable** method by the [resolvedMethodName] from the [definingClassProxy]. + * Returns the **immutable** method by the [resolvedMethod] from the [definingClassProxy]. * * If you need to modify the method, use [method] instead. */ val immutableMethod: Method get() = definingClassProxy.immutableClass.methods.first { - it.name == resolvedMethodName + it.softCompareTo(resolvedMethod) } fun findParentMethod(signature: MethodSignature): SignatureResolverResult? { diff --git a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt b/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt index 9b95eea..69e5c77 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt @@ -1,6 +1,7 @@ package app.revanced.patcher.signature.resolver import app.revanced.patcher.PatcherData +import app.revanced.patcher.extensions.parametersEqual import app.revanced.patcher.proxy import app.revanced.patcher.proxy.ClassProxy import app.revanced.patcher.signature.MethodSignature @@ -29,7 +30,7 @@ internal class SignatureResolver( signature.result = SignatureResolverResult( classProxy, patternScanData, - method.name, + method, ) } } @@ -44,7 +45,7 @@ internal class SignatureResolver( return SignatureResolverResult( classProxy, result, - method.name, + method, ) } return null @@ -67,7 +68,7 @@ internal class SignatureResolver( } signature.methodParameters?.let { - if (compareParameterTypes(signature.methodParameters, method.parameterTypes)) { + if (!parametersEqual(signature.methodParameters, method.parameterTypes)) { return null } } @@ -137,13 +138,6 @@ internal class SignatureResolver( return null } - private fun compareParameterTypes( - signature: Iterable, - original: MutableList - ): Boolean { - return signature.count() != original.size || !(signature.all { a -> original.any { it.startsWith(a) } }) - } - private fun generateWarnings( signature: MethodSignature, instructions: Iterable,