parseElfSegmentEntry :: ElfClass -> ElfReader -> B.ByteString -> Get ElfSegment
parseElfSegmentEntry elf_class er elf_file =
  do p_type   <- parseElfSegmentType  `fmap` getWord32 er
     p_flags  <- parseElfSegmentFlags `fmap` getWord32 er
     p_offset <- getWord
     p_vaddr  <- getWord
     p_paddr  <- getWord
     p_filesz <- getWord
     p_memsz  <- getWord
     p_align  <- getWord
     return ElfSegment
       { elfSegmentType     = p_type
       , elfSegmentFlags    = p_flags
       , elfSegmentVirtAddr = p_vaddr
       , elfSegmentPhysAddr = p_paddr
       , elfSegmentAlign    = p_align
       , elfSegmentData     = B.take (fromIntegral p_filesz) $ B.drop (fromIntegral p_offset) elf_file
       , elfSegmentMemSize  = p_memsz
       }

  where getWord = case elf_class of
                    ELFCLASS64 -> getWord64 er
                    ELFCLASS32 -> fromIntegral `fmap` getWord32 er
parseElfSegmentEntry :: ElfClass -> ElfReader -> B.ByteString -> Get ElfSegment
parseElfSegmentEntry elf_class er elf_file =
  do p_type   <- parseElfSegmentType  `fmap` getWord32 er
     p_flags  <- parseElfSegmentFlags `fmap` getWord32 er
     p_offset <- getWord
     p_vaddr  <- getWord
     p_paddr  <- getWord
     p_filesz <- getWord
     p_memsz  <- getWord
     p_align  <- getWord
     return ElfSegment
       { elfSegmentType     = p_type
       , elfSegmentFlags    = p_flags
       , elfSegmentVirtAddr = p_vaddr
       , elfSegmentPhysAddr = p_paddr
       , elfSegmentAlign    = p_align
       , elfSegmentData     = B.take (fromIntegral p_filesz) $ B.drop (fromIntegral p_offset) elf_file
       , elfSegmentMemSize  = p_memsz
       }

  where getWord = case elf_class of
                    ELFCLASS64 -> getWord64 er
                    ELFCLASS32 -> fromIntegral `fmap` getWord32 er
parseElfSegmentEntry elf_class er elf_file =
  do p_type   <- parseElfSegmentType  `fmap` getWord32 er
     p_flags  <- parseElfSegmentFlags `fmap` getWord32 er
     p_offset <- getWord
     p_vaddr  <- getWord
     p_paddr  <- getWord
     p_filesz <- getWord
     p_memsz  <- getWord
     p_align  <- getWord
     return ElfSegment
       { elfSegmentType     = p_type
       , elfSegmentFlags    = p_flags
       , elfSegmentVirtAddr = p_vaddr
       , elfSegmentPhysAddr = p_paddr
       , elfSegmentAlign    = p_align
       , elfSegmentData     = B.take (fromIntegral p_filesz) $ B.drop (fromIntegral p_offset) elf_file
       , elfSegmentMemSize  = p_memsz
       }

  where getWord = case elf_class of
                    ELFCLASS64 -> getWord64 er
                    ELFCLASS32 -> fromIntegral `fmap` getWord32 er