Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slightly better fuzzy scanning #115

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,33 @@ abstract class MethodFingerprint(
for (index in 0 until instructionLength) {
var patternIndex = 0
var threshold = fingerprintFuzzyPatternScanThreshold
var offset = 0;

while (index + patternIndex < instructionLength) {
scan@ while (index + patternIndex < instructionLength) {
val originalOpcode = instructions.elementAt(index + patternIndex).opcode
val patternOpcode = pattern.elementAt(patternIndex)
val patternOpcode = pattern.elementAt(patternIndex + offset)

if (patternOpcode != null && patternOpcode.ordinal != originalOpcode.ordinal) {
// reaching maximum threshold (0) means,
// the pattern does not match to the current instructions
if (threshold-- == 0) break

// look ahead
for (depth in 1 until threshold + 2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is threshold + 2 arbitrary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of, I wanted to make it so that at a minimum at least the next instruction is considered. If threshold is 0 at that point, you'll only enter that loop once since you start at 1 and would go 'until' 2 (exclusive).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val lookAheadIndex = patternIndex + offset + depth
if (lookAheadIndex < patternLength && index + lookAheadIndex < instructionLength)
{
val nextPatternOpcode = pattern.elementAt(lookAheadIndex)
if (nextPatternOpcode != null && nextPatternOpcode.ordinal == originalOpcode.ordinal)
{
offset+=depth;
continue@scan;
}
}
}
}

if (patternIndex < patternLength - 1) {
if (patternIndex + offset < patternLength - 1) {
// if the entire pattern has not been scanned yet
// continue the scan
patternIndex++
Expand Down