Skip to content

Commit 0b0dd4b

Browse files
committed
Added backend function to find occurence
1 parent d5722e4 commit 0b0dd4b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/core/hexeditor.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,21 @@ unsigned long HexEditor::countOccurrences(vector<uint8_t> &bytes) {
284284
}
285285
return matches;
286286
}
287+
288+
unsigned long HexEditor::findOccurrence(vector<uint8_t> &bytes, unsigned long start) {
289+
unsigned long offset = 0;
290+
for (unsigned long i = 0; i < this->loadedFileSize-bytes.size(); i++) {
291+
bool found = true;
292+
for (size_t j = start; j < bytes.size(); j++) {
293+
if (this->getCurrentData()[i+j] != bytes[j]) {
294+
found = false;
295+
break;
296+
}
297+
}
298+
if (found) {
299+
offset = i-bytes.size();
300+
break;
301+
}
302+
}
303+
return offset;
304+
}

src/core/hexeditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class HexEditor
4848
void initCompare();
4949
bool hasCompared();
5050
unsigned long countOccurrences(vector<uint8_t> &bytes);
51+
unsigned long findOccurrence(vector<uint8_t> &bytes, unsigned long start);
5152

5253
private:
5354
PatternMatching *patternMatching;

0 commit comments

Comments
 (0)