Skip to content

Commit

Permalink
fix: use MethodUtil.methodSignaturesMatch instead of `Method.softCo…
Browse files Browse the repository at this point in the history
…mpareTo`
  • Loading branch information
oSumAtrIX committed Nov 25, 2022
1 parent fd742eb commit bd053b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
12 changes: 0 additions & 12 deletions src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.jf.dexlib2.builder.MutableMethodImplementation
import org.jf.dexlib2.builder.instruction.*
import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
import java.io.OutputStream
Expand Down Expand Up @@ -45,17 +44,6 @@ fun MutableMethodImplementation.removeInstructions(index: Int, count: Int) {
}
}

/**
* Compare a method to another, considering name and parameters.
* @param otherMethod The method to compare against.
* @return True if the methods match given the conditions.
*/
fun Method.softCompareTo(otherMethod: MethodReference): Boolean {
return this.name == otherMethod.name && parametersEqual(
this.parameterTypes, otherMethod.parameterTypes
)
}

/**
* Clones the method.
* @param registerCount This parameter allows you to change the register count of the method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyPatternScanMethod
import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyScanThreshold
import app.revanced.patcher.extensions.parametersEqual
import app.revanced.patcher.extensions.softCompareTo
import app.revanced.patcher.fingerprint.Fingerprint
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.util.proxy.ClassProxy
Expand All @@ -14,6 +13,7 @@ import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.StringReference
import org.jf.dexlib2.util.MethodUtil

/**
* Represents the [MethodFingerprint] for a method.
Expand Down Expand Up @@ -297,7 +297,7 @@ data class MethodFingerprintResult(
*/
val mutableMethod by lazy {
mutableClass.methods.first {
it.softCompareTo(this.method)
MethodUtil.methodSignaturesMatch(it, this.method)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app.revanced.patcher.util.method

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.softCompareTo
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import org.jf.dexlib2.iface.Method
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.MethodReference
import org.jf.dexlib2.util.MethodUtil

/**
* Find a method from another method via instruction offsets.
Expand Down Expand Up @@ -44,8 +44,8 @@ class MethodWalker internal constructor(
val proxy = bytecodeContext.findClass(newMethod.definingClass)!!

val methods = if (walkMutable) proxy.mutableClass.methods else proxy.immutableClass.methods
currentMethod = methods.first { it ->
return@first it.softCompareTo(newMethod)
currentMethod = methods.first {
return@first MethodUtil.methodSignaturesMatch(it, newMethod)
}
return this
}
Expand Down

0 comments on commit bd053b7

Please sign in to comment.