Skip to content

Commit

Permalink
[BUGFIX] In pattern_tree: added Node destructor. Small refact
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Feb 7, 2024
1 parent 7d8e686 commit 3e66912
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
29 changes: 13 additions & 16 deletions utils/artefacts_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,20 @@ size_t search_all_matches(Node* rootN, const BYTE* loadedData, size_t loadedSize

size_t pesieve::util::is_32bit_code(BYTE *loadedData, size_t loadedSize)
{
static Node *rootN32 = nullptr;
if (!rootN32) {
rootN32 = new Node();
init_32_patterns(rootN32);
static Node rootN;
if(rootN.isEnd()) {
init_32_patterns(&rootN);
}
return search_till_pattern(rootN32, loadedData, loadedSize);
return search_till_pattern(&rootN, loadedData, loadedSize);
}

size_t pesieve::util::is_64bit_code(BYTE* loadedData, size_t loadedSize)
{
static Node* rootN64 = nullptr;
if (!rootN64) {
rootN64 = new Node();
init_64_patterns(rootN64);
static Node rootN;
if (rootN.isEnd()) {
init_64_patterns(&rootN);
}
return search_till_pattern(rootN64, loadedData, loadedSize);
return search_till_pattern(&rootN, loadedData, loadedSize);
}

bool pesieve::util::is_code(BYTE* loadedData, size_t loadedSize)
Expand All @@ -149,14 +147,13 @@ bool pesieve::util::is_code(BYTE* loadedData, size_t loadedSize)
return false;
}

static Node* rootN = nullptr;
if (!rootN) {
rootN = new Node();
init_32_patterns(rootN);
init_64_patterns(rootN);
static Node rootN;
if (rootN.isEnd()) {
init_32_patterns(&rootN);
init_64_patterns(&rootN);
}

if ((search_till_pattern(rootN, loadedData, loadedSize)) != CODE_PATTERN_NOT_FOUND) {
if ((search_till_pattern(&rootN, loadedData, loadedSize)) != CODE_PATTERN_NOT_FOUND) {
return true;
}
return false;
Expand Down
12 changes: 12 additions & 0 deletions utils/pattern_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ namespace pattern_tree {
{
}

~Node()
{
for (auto itr = immediates.begin(); itr != immediates.end(); ++itr) {
Node* next = itr->second;
delete next;
}
immediates.clear();
if (sign) {
delete sign;
}
}

Node* getNode(BYTE _val)
{
auto found = immediates.find(_val);
Expand Down

0 comments on commit 3e66912

Please sign in to comment.