-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "memory.hpp" | ||
|
||
struct PatternByte { | ||
bool isWildcard; | ||
uint8_t value; | ||
}; | ||
|
||
uintptr_t memory::PatternScan(uintptr_t base, uintptr_t scanSize, const std::string signature) { | ||
std::vector<PatternByte> patternData; | ||
|
||
for (size_t i = 0; i < signature.size(); ++i) { | ||
if (signature[i] == ' ') { | ||
continue; | ||
} | ||
|
||
if (signature[i] == '?') { | ||
patternData.push_back({ true, 0 }); | ||
} | ||
else { | ||
std::string byteStr = signature.substr(i, 2); | ||
patternData.push_back({ false, static_cast<uint8_t>(std::stoul(byteStr, nullptr, 16)) }); | ||
i++; | ||
} | ||
} | ||
|
||
for (uintptr_t i = base; /*i < base + scanSize*/; ++i) { | ||
bool found = true; | ||
|
||
for (size_t j = 0; j < patternData.size(); ++j) { | ||
if (patternData[j].isWildcard) { | ||
continue; | ||
} | ||
|
||
if (patternData[j].value != *reinterpret_cast<uint8_t*>(i + j)) { | ||
found = false; | ||
break; | ||
} | ||
} | ||
|
||
if (found) { | ||
return i; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include <fstream> | ||
#include <streambuf> | ||
#include <vector> | ||
#include <sstream> | ||
|
||
namespace memory { | ||
uintptr_t PatternScan(uintptr_t base, uintptr_t scanSize, const std::string signature); | ||
} |