mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
feat: string signature (#22)
* feat: string signature Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> * fix: signature in test Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> * fix: make string signature optional Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> * fix: use of `compareOpcodes` when comparing string signatures Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> * add: `PackageMetadata` for signatures Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
1f7bf3ac6c
commit
c245edb0c5
3 changed files with 25 additions and 2 deletions
|
@ -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<String>?,
|
||||
internal val opcodes: Iterable<Opcode?>?
|
||||
internal val opcodes: Iterable<Opcode?>?,
|
||||
internal val strings: Iterable<String>? = null
|
||||
) {
|
||||
/**
|
||||
* The result of the signature
|
||||
|
|
|
@ -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<ClassDef>,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
||||
) {
|
||||
|
|
Loading…
Reference in a new issue