2017-11-09 21:43:41 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
module Shared (
|
2018-05-22 00:32:29 +03:00
|
|
|
withELF
|
2017-11-09 21:43:41 +03:00
|
|
|
) 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)
|