| 46 | } |
| 47 | |
| 48 | void* FindFunctionPattern( |
| 49 | const std::vector<BytePattern>& allPatterns, |
| 50 | void* _begin, |
| 51 | void* _end) { |
| 52 | auto begin = reinterpret_cast<uint64_t*>(_begin); |
| 53 | auto end = reinterpret_cast<uint64_t*>(_end); |
| 54 | dprint( |
| 55 | "Code search range: {:#018x}-{:#018x}", (uint64_t)begin, (uint64_t)end); |
| 56 | |
| 57 | const uint64_t firstPattern = allPatterns.front().value, |
| 58 | firstMask = allPatterns.front().mask; |
| 59 | auto patterns = allPatterns; |
| 60 | patterns.erase(patterns.begin()); |
| 61 | // Stack entries (including functions) are always aligned on 16-byte |
| 62 | // boundaries |
| 63 | for (auto func = begin; func < end; func += (16 / sizeof(*func))) { |
| 64 | auto it = func; |
| 65 | if ((*it & firstMask) != firstPattern) { |
| 66 | continue; |
| 67 | } |
| 68 | for (auto& pattern: patterns) { |
| 69 | it++; |
| 70 | if (it >= end) { |
| 71 | return nullptr; |
| 72 | } |
| 73 | |
| 74 | if ((*it & pattern.mask) != pattern.value) { |
| 75 | goto FindFunctionPattern_NextBlock; |
| 76 | } |
| 77 | } |
| 78 | return reinterpret_cast<void*>(func); |
| 79 | |
| 80 | FindFunctionPattern_NextBlock: |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | return nullptr; |
| 85 | } |
| 86 | |
| 87 | void* FindFunctionPatternInModule( |
| 88 | const char* moduleName, |
no test coverage detected