u/DanDan197

Conex – single-header C++20 library for condition-based binary pattern matching
▲ 14 r/cpp

Conex – single-header C++20 library for condition-based binary pattern matching

I built a small single-header library called Conex for binary pattern matching with lambda conditions.

The idea: instead of hard-coded byte signatures, you express each match condition as a lambda that inspects the raw bytes. The pattern syntax is regex-style — (c0:4)(c1:8)* means "4 bytes satisfying lambda 0, followed by zero or more 8-byte groups satisfying lambda 1".

// Find a struct by its signature + page-aligned address fields
auto result = conex::search_first(blob, "(c0:4)(c1:8)*",
    [](std::span<const uint8_t> s) {
        uint32_t sig; std::memcpy(&sig, s.data(), 4);
        return sig == 0xDEADBEEF;
    },
    [](std::span<const uint8_t> s) {
        uint64_t addr; std::memcpy(&addr, s.data(), 8);
        return (addr & 0xFFF) == 0; // page-aligned
    } 
);

Useful for reverse engineering, game modding, firmware analysis, or anywhere you're scanning binary blobs for structures you can identify semantically but not by fixed offsets.

Single header, no dependencies, C++20.

https://github.com/DanielCohen197/Conex

Happy to hear feedback!

u/DanDan197 — 1 day ago