@@ -83,24 +83,26 @@ internal class SignatureResolver(
83
83
val count = instructions.count()
84
84
val pattern = signature.opcodes!!
85
85
val size = pattern.count()
86
- var threshold = 0
87
- if (signature.methodSignatureMetadata.patternScanMethod is PatternScanMethod .Fuzzy ) {
88
- threshold = signature.methodSignatureMetadata.patternScanMethod.threshold
89
- }
86
+ val method = signature.metadata.patternScanMethod
87
+ val threshold = if (method is PatternScanMethod .Fuzzy )
88
+ method.threshold else 0
90
89
91
90
for (instructionIndex in 0 until count) {
92
91
var patternIndex = 0
93
92
var currentThreshold = threshold
94
93
while (instructionIndex + patternIndex < count) {
95
- if (
96
- instructions.elementAt(
97
- instructionIndex + patternIndex
98
- ).opcode != pattern.elementAt(patternIndex)
99
- && currentThreshold-- == 0
100
- ) break
94
+ val originalOpcode = instructions.elementAt(instructionIndex + patternIndex).opcode
95
+ val patternOpcode = pattern.elementAt(patternIndex)
96
+ if (originalOpcode != patternOpcode && currentThreshold-- == 0 ) break
101
97
if (++ patternIndex < size) continue
102
98
103
- return PatternScanResult (instructionIndex, instructionIndex + patternIndex)
99
+ val result = PatternScanResult (instructionIndex, instructionIndex + patternIndex)
100
+ if (method is PatternScanMethod .Fuzzy ) {
101
+ method.warnings = generateWarnings(
102
+ signature, instructions, result
103
+ )
104
+ }
105
+ return result
104
106
}
105
107
}
106
108
@@ -113,6 +115,24 @@ internal class SignatureResolver(
113
115
): Boolean {
114
116
return signature.count() != original.size || ! (signature.all { a -> original.any { it.startsWith(a) } })
115
117
}
118
+
119
+ private fun generateWarnings (
120
+ signature : MethodSignature ,
121
+ instructions : Iterable <Instruction >,
122
+ scanResult : PatternScanResult ,
123
+ ) = buildList {
124
+ val pattern = signature.opcodes!!
125
+ for ((patternIndex, originalIndex) in (scanResult.startIndex until scanResult.endIndex).withIndex()) {
126
+ val originalOpcode = instructions.elementAt(originalIndex).opcode
127
+ val patternOpcode = pattern.elementAt(patternIndex)
128
+ if (originalOpcode != patternOpcode) {
129
+ this .add(PatternScanMethod .Fuzzy .Warning (
130
+ originalOpcode, patternOpcode,
131
+ originalIndex, patternIndex
132
+ ))
133
+ }
134
+ }
135
+ }
116
136
}
117
137
}
118
138
0 commit comments