32 static std::map<const uint8_t*, ByteHistogram>
cache;
60 std::vector<ScanRange>
ranges;
69 std::vector<ScanRange>
ranges;
93 Log::Warn(
"SigScanner: Pattern ambiguous in '{}' (2+ matches); refusing it.",
fullName);
97 at =
static_cast<size_t>(
hit -
range.Base) + 1;
151 const auto target =
reinterpret_cast<unsigned long>(
address);
152 std::ifstream
maps(
"/proc/self/maps");
156 unsigned long start = 0;
157 unsigned long end = 0;
166 .Readable =
perms[0] ==
'r',
167 .Executable =
perms[2] ==
'x'};
Parsing and searching byte patterns, with no notion of a loaded module.
void Error(std::format_string< Args... > fmt, Args &&... args)
void Warn(std::format_string< Args... > fmt, Args &&... args)
bool FindImage(std::string_view moduleName, Image &module)
std::vector< PatternByte > ParsePattern(const std::string &pattern)
static const ByteHistogram & FrequenciesOf(const Image &module, const std::vector< ScanRange > &ranges)
bool FindModuleAndRanges(std::string_view fileName, Image &module, std::vector< ScanRange > &ranges)
ScanResult FindPatternEx(std::string_view moduleName, const std::string &pattern)
const uint8_t * FindFirst(const uint8_t *base, size_t size, const std::vector< PatternByte > &pattern, size_t anchor)
static std::string ReadFile(const std::filesystem::path &path)
bool IsExecutableAddress(const void *address)
bool IsReadableAddress(const void *address, size_t bytes)
uintptr_t ResolveRelativeAddress(const Image &module, uintptr_t matchAddress, int ripOffset, int ripSize)
size_t AnchorOf(const std::vector< PatternByte > &pattern, const ByteHistogram &frequencies)
constexpr bool Rel32ReadInBounds(uintptr_t moduleBase, size_t moduleSize, uintptr_t matchAddress, int ripOffset) noexcept
std::array< size_t, 256 > ByteHistogram
static std::optional< MemoryRegion > QueryRegion(const void *address)
constexpr uintptr_t Rel32Target(uintptr_t site, int32_t displacement, int ripSize=Rel32Size) noexcept
void CountBytes(const uint8_t *base, size_t size, ByteHistogram &counts)
std::string PlatformModuleName(std::string_view moduleName)
constexpr uintptr_t Rel32Site(uintptr_t matchAddress, int ripOffset) noexcept