/** * @file rex/codegen/sig_scanner.h * @brief Signature scanner for pattern-based function discovery * * @copyright Copyright (c) 2026 Tom Clay * All rights reserved. * * @license BSD 3-Clause License * See LICENSE file in the project root for full license text. */ #pragma once #include #include #include #include #include #include namespace rex::codegen { //============================================================================= // Signature - Pattern definition for matching //============================================================================= // Dword-based patterns follow PPC's per-instruction size. // Each pattern word is matched against memory using the corresponding mask. // A mask of 0xFFFFFFFF means exact match; partial masks allow wildcards. struct Signature { std::string name; // e.g., "__savegprlr_14" std::vector pattern; // Instruction words to match std::vector mask; // Bits that must match (0xFFFFFFFF = exact) size_t entryOffset = 0; // Offset from pattern start to entry point std::optional size; // Known size, or nullopt to compute from pattern }; //============================================================================= // SigScanner - Pattern-based signature matcher //============================================================================= class SigScanner { public: explicit SigScanner(const runtime::Module& module); // Scan for a single signature, return all match entry points std::vector scan(const Signature& sig); // Scan for multiple signatures at once (more efficient - single pass) std::unordered_map> scanAll( const std::vector& sigs); // Built-in signature sets static std::vector helperSignatures(); // __save/__restore helpers static std::vector hleSignatures(); // memset, memmove, etc. (future) private: const runtime::Module& module_; // Scan a single range for a pattern std::vector scanRange(uint32_t start, uint32_t end, const std::vector& pattern, const std::vector& mask, size_t entryOffset); }; } // namespace rex::codegen