elf 0.2 → 0.22
raw patch · 2 files changed
+24/−19 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- elf.cabal +8/−3
- src/Data/Elf.hs +16/−16
elf.cabal view
@@ -1,5 +1,5 @@ Name: elf -Version: 0.2 +Version: 0.22 License: BSD3 License-file: LICENSE Category: Data @@ -7,14 +7,19 @@ Copyright: Erik Charlebois Maintainer: Erik Charlebois <erikcharlebois@gmail.com> Stability: unstable -Cabal-Version: >= 1.2 +Cabal-Version: >= 1.6 +Homepage: http://code.fac9.com/elf/ Build-Depends: base Build-Type: Custom Synopsis: Parser for ELF object format. Description: Parser for ELF object format. Data-Files: tests/empty.elf tests/Test.hs +source-repository head + type: git + location: http://github.com/erikcharlebois/elf + library - build-depends: base, bytestring, binary + build-depends: base >= 2 && < 5, bytestring, binary hs-source-dirs: src exposed-modules: Data.Elf
src/Data/Elf.hs view
@@ -74,7 +74,7 @@ | SHT_DYNSYM -- ^ Contains a dynamic loader symbol table | SHT_EXT Word32 -- ^ Processor- or environment-specific type deriving (Eq, Show) -getElfSectionType er = getWord32 er >>= return . getElfSectionType_ +getElfSectionType er = liftM getElfSectionType_ $ getWord32 er where getElfSectionType_ 0 = SHT_NULL getElfSectionType_ 1 = SHT_PROGBITS getElfSectionType_ 2 = SHT_SYMTAB @@ -96,13 +96,13 @@ | SHF_EXT Int -- ^ Processor- or environment-specific flag deriving (Eq, Show) getElfSectionFlags 0 word = [] -getElfSectionFlags 1 word | testBit word 1 = SHF_WRITE : getElfSectionFlags 0 word -getElfSectionFlags 2 word | testBit word 2 = SHF_ALLOC : getElfSectionFlags 1 word -getElfSectionFlags 3 word | testBit word 4 = SHF_EXECINSTR : getElfSectionFlags 2 word -getElfSectionFlags n word | testBit word n = SHF_EXT n : getElfSectionFlags (n-1) word +getElfSectionFlags 1 word | testBit word 0 = SHF_WRITE : getElfSectionFlags 0 word +getElfSectionFlags 2 word | testBit word 1 = SHF_ALLOC : getElfSectionFlags 1 word +getElfSectionFlags 3 word | testBit word 2 = SHF_EXECINSTR : getElfSectionFlags 2 word +getElfSectionFlags n word | testBit word (n-1) = SHF_EXT (n-1) : getElfSectionFlags (n-1) word getElfSectionFlags n word = getElfSectionFlags (n-1) word -getElfSectionFlags32 er = getWord32 er >>= return . getElfSectionFlags 31 -getElfSectionFlags64 er = getWord64 er >>= return . getElfSectionFlags 63 +getElfSectionFlags32 = liftM (getElfSectionFlags 32) . getWord32 +getElfSectionFlags64 = liftM (getElfSectionFlags 64) . getWord64 data ElfClass = ELFCLASS32 -- ^ 32-bit ELF format @@ -141,7 +141,7 @@ | ELFOSABI_STANDALONE -- ^ Standalone (embedded) application | ELFOSABI_EXT Word8 -- ^ Other deriving (Eq, Show) -getElfOsabi = getWord8 >>= return . getElfOsabi_ +getElfOsabi = liftM getElfOsabi_ getWord8 where getElfOsabi_ 0 = ELFOSABI_SYSV getElfOsabi_ 1 = ELFOSABI_HPUX getElfOsabi_ 2 = ELFOSABI_NETBSD @@ -168,7 +168,7 @@ | ET_CORE -- ^ Core dump object file | ET_EXT Word16 -- ^ Other deriving (Eq, Show) -getElfType er = getWord16 er >>= return . getElfType_ +getElfType = liftM getElfType_ . getWord16 where getElfType_ 0 = ET_NONE getElfType_ 1 = ET_REL getElfType_ 2 = ET_EXEC @@ -272,7 +272,7 @@ | EM_UNICORE -- ^ Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University | EM_EXT Word16 -- ^ Other deriving (Eq, Show) -getElfMachine er = getWord16 er >>= return . getElfMachine_ +getElfMachine = liftM getElfMachine_ . getWord16 where getElfMachine_ 0 = EM_NONE getElfMachine_ 1 = EM_M32 getElfMachine_ 2 = EM_SPARC @@ -396,7 +396,7 @@ sh_info <- getWord32 er sh_addralign <- getWord32 er sh_entsize <- getWord32 er - return $ ElfSection + return ElfSection { elfSectionName = map B.w2c $ B.unpack $ B.takeWhile (/= 0) $ B.drop (fromIntegral sh_name) string_section , elfSectionType = sh_type , elfSectionFlags = sh_flags @@ -419,7 +419,7 @@ sh_info <- getWord32 er sh_addralign <- getWord64 er sh_entsize <- getWord64 er - return $ ElfSection + return ElfSection { elfSectionName = map B.w2c $ B.unpack $ B.takeWhile (/= 0) $ B.drop (fromIntegral sh_name) string_section , elfSectionType = sh_type , elfSectionFlags = sh_flags @@ -447,9 +447,9 @@ e_type <- getElfType er e_machine <- getElfMachine er e_version <- getWord32 er - e_entry <- getWord32 er >>= return . fromIntegral + e_entry <- liftM fromIntegral $ getWord32 er e_phoff <- getWord32 er - e_shoff <- getWord32 er >>= return . fromIntegral + e_shoff <- liftM fromIntegral $ getWord32 er e_flags <- getWord32 er e_ehsize <- getWord16 er e_phentsize <- getWord16 er @@ -502,7 +502,7 @@ divide :: B.ByteString -> Int -> Int -> [B.ByteString] divide bs s 0 = [] -divide bs s n = let (x,y) = B.splitAt s bs in x:(divide y s (n-1)) +divide bs s n = let (x,y) = B.splitAt s bs in x : divide y s (n-1) -- | Parses a ByteString into an Elf record. Parse failures call error. 32-bit ELF objects have their -- fields promoted to 64-bit so that the 32- and 64-bit ELF records can be the same. @@ -512,6 +512,6 @@ sh = B.take (fromIntegral (e_shentsize * e_shnum)) $ B.drop (fromIntegral e_shoff) b (shstroff, shstrsize) = runGet (getElf_Shdr_OffsetSize (elfClass e) (elfReader $ elfData e)) $ L.fromChunks [B.drop (fromIntegral (e_shentsize * e_shstrndx)) sh] sh_str = B.take (fromIntegral shstrsize) $ B.drop (fromIntegral shstroff) b - sections = filter (\sec -> elfSectionType sec /= SHT_NULL) $ map (runGet (getElf_Shdr (elfClass e) (elfReader $ elfData e) b sh_str)) (map (\x -> L.fromChunks [x]) (divide sh (fromIntegral e_shentsize) (fromIntegral e_shnum))) + sections = filter (\sec -> elfSectionType sec /= SHT_NULL) $ map (runGet (getElf_Shdr (elfClass e) (elfReader $ elfData e) b sh_str) . (\x -> L.fromChunks [x])) (divide sh (fromIntegral e_shentsize) (fromIntegral e_shnum)) in e { elfSections = sections }