Advertisement
R3v3rs3r

Untitled

Jul 24th, 2023
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ (WinAPI) 1.62 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. // Function for pattern scanning with a mask
  6. uintptr_t FindPattern(const char* data, size_t dataSize, const char* pattern, const char* mask) {
  7.     size_t patternLength = strlen(mask);
  8.  
  9.     for (size_t i = 0; i < dataSize - patternLength; ++i) {
  10.         bool found = true;
  11.         for (size_t j = 0; j < patternLength; ++j) {
  12.             if (mask[j] != '?' && data[i + j] != pattern[j]) {
  13.                 found = false;
  14.                 break;
  15.             }
  16.         }
  17.  
  18.         if (found) {
  19.             return reinterpret_cast<uintptr_t>(&data[i]);
  20.         }
  21.     }
  22.  
  23.     return 0; // Pattern not found
  24. }
  25.  
  26. int main() {
  27.     const char* exeFilePath = "your_executable.exe";
  28.     const char* pattern = "\x12\x34\x56\x78"; // Replace with your desired pattern in hex format
  29.     const char* mask = "xxxx"; // 'x' denotes a byte to match, '?' denotes a byte to ignore
  30.  
  31.     std::ifstream file(exeFilePath, std::ios::binary | std::ios::ate);
  32.     if (!file.is_open()) {
  33.         std::cerr << "Failed to open the executable file." << std::endl;
  34.         return 1;
  35.     }
  36.  
  37.     std::streampos fileSize = file.tellg();
  38.     std::vector<char> buffer(fileSize);
  39.     file.seekg(0, std::ios::beg);
  40.     file.read(buffer.data(), fileSize);
  41.     file.close();
  42.  
  43.     uintptr_t foundAddress = FindPattern(buffer.data(), buffer.size(), pattern, mask);
  44.  
  45.     if (foundAddress != 0) {
  46.         std::cout << "Pattern found at address: " << std::hex << foundAddress << std::endl;
  47.     } else {
  48.         std::cout << "Pattern not found in the executable." << std::endl;
  49.     }
  50.  
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement