Skip to content

Commit

Permalink
feat: Allow unknown opcodes using null
Browse files Browse the repository at this point in the history
This is the same as `??` in IDA signatures.
  • Loading branch information
Sculas authored and oSumAtrIX committed Jun 5, 2022
1 parent 6ca0576 commit 0e5f4ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0e5f4ba

Please sign in to comment.