|
4 | 4 |
|
5 | 5 | #include <vector> |
6 | 6 |
|
| 7 | +std::vector<int16_t> MemHlp::patternToBytes(const char* pattern) |
| 8 | +{ |
| 9 | + auto bytes = std::vector<int16_t>(); |
| 10 | + |
| 11 | + char* start = const_cast<char*>(pattern); |
| 12 | + char* end = start + strlen(pattern); |
| 13 | + |
| 14 | + while (start < end) |
| 15 | + { |
| 16 | + if (*start == '?') |
| 17 | + { |
| 18 | + bytes.emplace_back(-1); |
| 19 | + } |
| 20 | + else if (*start != ' ') |
| 21 | + { |
| 22 | + bytes.emplace_back(std::strtoul(start, &start, 16)); |
| 23 | + } |
| 24 | + |
| 25 | + start++; |
| 26 | + } |
| 27 | + |
| 28 | + return bytes; |
| 29 | +} |
| 30 | + |
| 31 | +lm_address_t MemHlp::patternScan(const char* pattern, lm_module_t module) |
| 32 | +{ |
| 33 | + const auto bytes = patternToBytes(pattern); |
| 34 | + |
| 35 | + //For some reason these last bytes crash on read access, even if PROT_R is set. |
| 36 | + //If anyone knows why that could be please let me know <3 |
| 37 | + constexpr lm_address_t excludeTailSize = 0xd8000; |
| 38 | + const lm_address_t end = module.end - excludeTailSize - bytes.size() - 1; |
| 39 | + |
| 40 | + for (lm_address_t cur = module.base; cur < end; cur++) |
| 41 | + { |
| 42 | + bool found = true; |
| 43 | + for(unsigned int i = 0; i < bytes.size(); i++) |
| 44 | + { |
| 45 | + if (bytes.at(i) == -1) |
| 46 | + { |
| 47 | + continue; |
| 48 | + } |
| 49 | + |
| 50 | + lm_address_t byteAddr = cur + i; |
| 51 | + |
| 52 | + const lm_byte_t* pbyte = reinterpret_cast<lm_byte_t*>(byteAddr); |
| 53 | + if (*pbyte != bytes.at(i)) |
| 54 | + { |
| 55 | + found = false; |
| 56 | + break; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + if (found) |
| 61 | + { |
| 62 | + return cur; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + return LM_ADDRESS_BAD; |
| 67 | +} |
| 68 | + |
7 | 69 | lm_address_t MemHlp::searchSignature(const char* name, const char* signature, lm_module_t module, SigFollowMode mode, void* extraData, size_t extraDataSize) |
8 | 70 | { |
9 | | - lm_address_t address = LM_SigScan(signature, module.base, module.size); |
| 71 | + //lm_address_t address = LM_SigScan(signature, module.base, module.size); |
| 72 | + lm_address_t address = patternScan(signature, module); |
10 | 73 | if (address == LM_ADDRESS_BAD) |
11 | 74 | { |
12 | 75 | g_pLog->debug("Unable to find signature for %s!\n", name); |
|
0 commit comments