Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- // Function for pattern scanning with a mask
- uintptr_t FindPattern(const char* data, size_t dataSize, const char* pattern, const char* mask) {
- size_t patternLength = strlen(mask);
- for (size_t i = 0; i < dataSize - patternLength; ++i) {
- bool found = true;
- for (size_t j = 0; j < patternLength; ++j) {
- if (mask[j] != '?' && data[i + j] != pattern[j]) {
- found = false;
- break;
- }
- }
- if (found) {
- return reinterpret_cast<uintptr_t>(&data[i]);
- }
- }
- return 0; // Pattern not found
- }
- int main() {
- const char* exeFilePath = "your_executable.exe";
- const char* pattern = "\x12\x34\x56\x78"; // Replace with your desired pattern in hex format
- const char* mask = "xxxx"; // 'x' denotes a byte to match, '?' denotes a byte to ignore
- std::ifstream file(exeFilePath, std::ios::binary | std::ios::ate);
- if (!file.is_open()) {
- std::cerr << "Failed to open the executable file." << std::endl;
- return 1;
- }
- std::streampos fileSize = file.tellg();
- std::vector<char> buffer(fileSize);
- file.seekg(0, std::ios::beg);
- file.read(buffer.data(), fileSize);
- file.close();
- uintptr_t foundAddress = FindPattern(buffer.data(), buffer.size(), pattern, mask);
- if (foundAddress != 0) {
- std::cout << "Pattern found at address: " << std::hex << foundAddress << std::endl;
- } else {
- std::cout << "Pattern not found in the executable." << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement