// E2E: structural blob validation — confirms the Windows (MZ) and macOS // (Mach-O 64-bit) sections inside a fat .vls have correct magic bytes. // This runs on Linux and validates cross-platform blobs without executing them. #include #include #include #include #include #include #include "format/vlc_format.hpp" #ifndef VOIDLIBC_TEST_VLC_PATH #error "VOIDLIBC_TEST_VLC_PATH must be set by CMake" #endif using namespace voidlibc::format; #define REQUIRE(cond) do { \ if (!(cond)) { \ std::fprintf(stderr, "FAIL: %s (line %d)\n", #cond, \ __LINE__); \ std::exit(1); \ } \ } while (0) static std::vector read_section_bytes( std::ifstream& f, const SectionEntry& sec) { f.seekg(static_cast(sec.code_off)); std::vector buf(static_cast(sec.code_size)); f.read(reinterpret_cast(buf.data()), static_cast(buf.size())); return buf; } int main() { std::ifstream f(VOIDLIBC_TEST_VLC_PATH, std::ios::binary); REQUIRE(f.is_open()); FileHeader hdr{}; f.read(reinterpret_cast(&hdr), sizeof(hdr)); REQUIRE(f.good()); REQUIRE(hdr.magic == kMagic); REQUIRE(hdr.section_count >= 3); // must have linux + windows + macos f.seekg(static_cast(hdr.section_dir_off)); std::vector sects(hdr.section_count); f.read(reinterpret_cast(sects.data()), static_cast(hdr.section_count * sizeof(SectionEntry))); REQUIRE(f.good()); bool saw_linux = false, saw_windows = false, saw_macos = false; for (const auto& sec : sects) { REQUIRE(sec.kind == SectionKind::NativeBlob); REQUIRE(sec.code_size >= 4); auto bytes = read_section_bytes(f, sec); REQUIRE(bytes.size() >= 4); if (sec.target_os == TargetOS::Linux) { // ELF magic: \x7F E L F REQUIRE(bytes[0] == 0x7F && bytes[1] == 'E' && bytes[2] == 'L' && bytes[3] == 'F'); saw_linux = true; } else if (sec.target_os == TargetOS::Windows) { // PE: MZ header REQUIRE(bytes[0] == 'M' && bytes[1] == 'Z'); saw_windows = true; } else if (sec.target_os == TargetOS::MacOS) { // Mach-O 64-bit LE: 0xCFFAEDFE REQUIRE(bytes[0] == 0xCF && bytes[1] == 0xFA && bytes[2] == 0xED && bytes[3] == 0xFE); saw_macos = true; } } REQUIRE(saw_linux); REQUIRE(saw_windows); REQUIRE(saw_macos); std::printf("PASS: e2e_blob_validate — ELF/PE/Mach-O magic bytes all correct\n"); return 0; }