{-# LANGUAGE DataKinds #-} module Shared ( withELF ) where import qualified Data.ByteString as B import qualified Data.ElfEdit as E withELF :: FilePath -> (E.Elf 64 -> IO ()) -> IO () withELF fp k = do bytes <- B.readFile fp case E.parseElf bytes of E.ElfHeaderError off msg -> error ("Error parsing ELF header at offset " ++ show off ++ ": " ++ msg) E.Elf32Res [] _e32 -> error "ELF32 is unsupported in the test suite" E.Elf64Res [] e64 -> k e64 E.Elf32Res errs _ -> error ("Errors while parsing ELF file: " ++ show errs) E.Elf64Res errs _ -> error ("Errors while parsing ELF file: " ++ show errs)