diff --git a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt b/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt index 8db9a24..7c88f9d 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt @@ -11,6 +11,7 @@ import org.jf.dexlib2.Opcode * @param accessFlags The access flags of the method. * @param methodParameters The parameters of the method. * @param opcodes The list of opcodes of the method. + * @param strings A list of strings which a method contains. * A `null` opcode is equals to an unknown opcode. */ class MethodSignature( @@ -18,7 +19,8 @@ class MethodSignature( internal val returnType: String?, internal val accessFlags: Int?, internal val methodParameters: Iterable?, - internal val opcodes: Iterable? + internal val opcodes: Iterable?, + internal val strings: Iterable? = null ) { /** * The result of the signature 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 80ad401..5f17999 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt @@ -7,9 +7,12 @@ import app.revanced.patcher.signature.MethodSignature import app.revanced.patcher.signature.PatternScanMethod import app.revanced.patcher.signature.PatternScanResult import app.revanced.patcher.signature.SignatureResolverResult +import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.ClassDef import org.jf.dexlib2.iface.Method import org.jf.dexlib2.iface.instruction.Instruction +import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.reference.StringReference internal class SignatureResolver( private val classes: List, @@ -69,6 +72,23 @@ internal class SignatureResolver( } } + method.implementation?.instructions?.let { instructions -> + signature.strings?.let { + val stringsList = it as MutableSet + + for (instruction in instructions) { + if (instruction.opcode != Opcode.CONST_STRING) continue + + val string = ((instruction as Instruction21c).reference as StringReference).string + if (stringsList.contains(string)) { + stringsList.remove(string) + } + } + + if (stringsList.isNotEmpty()) return null + } + } + return if (signature.opcodes == null) { PatternScanResult(0, 0) } else { diff --git a/src/test/kotlin/app/revanced/patcher/usage/ExamplePatch.kt b/src/test/kotlin/app/revanced/patcher/usage/ExamplePatch.kt index e0c506c..4451c97 100644 --- a/src/test/kotlin/app/revanced/patcher/usage/ExamplePatch.kt +++ b/src/test/kotlin/app/revanced/patcher/usage/ExamplePatch.kt @@ -64,7 +64,8 @@ class ExamplePatch : Patch( null, // Testing unknown opcodes. Opcode.INVOKE_STATIC, // This is intentionally wrong to test the Fuzzy resolver. Opcode.RETURN_VOID - ) + ), + null ) ) ) {