Skip to content

Commit

Permalink
feat: string signature (ReVanced#22)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
oSumAtrIX committed Jun 5, 2022
1 parent b1eebc9 commit 612515a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ 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(
val metadata: MethodSignatureMetadata,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/test/kotlin/app/revanced/patcher/usage/ExamplePatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
) {
Expand Down

0 comments on commit 612515a

Please sign in to comment.