| 48 | // ---- byte-pattern scanner ---- |
| 49 | |
| 50 | static bool ParseSig(const std::string& str, |
| 51 | std::vector<uint8_t>& bytes, |
| 52 | std::vector<uint8_t>& mask) |
| 53 | { |
| 54 | bytes.clear(); |
| 55 | mask.clear(); |
| 56 | for (const char* p = str.c_str(); *p; ) { |
| 57 | if (*p == ' ' || *p == '\t' || *p == ',') { ++p; continue; } |
| 58 | if (p[0] == '?' && p[1] == '?') { |
| 59 | bytes.push_back(0); mask.push_back(0); p += 2; continue; |
| 60 | } |
| 61 | char hi = p[0], lo = p[1]; |
| 62 | if (!hi || !lo) return false; |
| 63 | auto nib = [](char c) -> int { |
| 64 | if (c >= '0' && c <= '9') return c - '0'; |
| 65 | if (c >= 'a' && c <= 'f') return c - 'a' + 10; |
| 66 | if (c >= 'A' && c <= 'F') return c - 'A' + 10; |
| 67 | return -1; |
| 68 | }; |
| 69 | int h = nib(hi), l = nib(lo); |
| 70 | if (h < 0 || l < 0) return false; |
| 71 | bytes.push_back(static_cast<uint8_t>((h << 4) | l)); |
| 72 | mask.push_back(1); |
| 73 | p += 2; |
| 74 | } |
| 75 | return !bytes.empty(); |
| 76 | } |
| 77 | |
| 78 | static void* ScanModule(OSTPlatform::DynamicLibrary::ModuleHandle module, |
| 79 | const std::vector<uint8_t>& bytes, |