feat: Allow unknown opcodes using null

This is the same as `??` in IDA signatures.
This commit is contained in:
Lucaskyy 2022-04-14 18:29:37 +02:00 committed by oSumAtrIX
parent 6ca05769ef
commit 0e5f4ba2d5
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
2 changed files with 11 additions and 3 deletions

View file

@ -10,13 +10,14 @@ 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.
* 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?>?
) {
/**
* The result of the signature

View file

@ -93,7 +93,11 @@ internal class SignatureResolver(
while (instructionIndex + patternIndex < count) {
val originalOpcode = instructions.elementAt(instructionIndex + patternIndex).opcode
val patternOpcode = pattern.elementAt(patternIndex)
if (originalOpcode != patternOpcode && currentThreshold-- == 0) break
if (
patternOpcode != null && // unknown opcode
originalOpcode != patternOpcode &&
currentThreshold-- == 0
) break
if (++patternIndex < size) continue
val result = PatternScanResult(instructionIndex, instructionIndex + patternIndex)
@ -125,7 +129,10 @@ internal class SignatureResolver(
for ((patternIndex, originalIndex) in (scanResult.startIndex until scanResult.endIndex).withIndex()) {
val originalOpcode = instructions.elementAt(originalIndex).opcode
val patternOpcode = pattern.elementAt(patternIndex)
if (originalOpcode != patternOpcode) {
if (
patternOpcode != null && // unknown opcode
originalOpcode != patternOpcode
) {
this.add(
PatternScanMethod.Fuzzy.Warning(
originalOpcode, patternOpcode,