Copyright | (c) Aleksey Makarov 2021 |
---|---|
License | BSD 3-Clause License |
Maintainer | aleksey.makarov@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.Elf.Headers
Description
Parse headers and table entries of ELF files
Synopsis
- elfMagic :: Be Word32
- data ElfClass
- data SElfClass :: ElfClass -> Type where
- SELFCLASS32 :: SElfClass (ELFCLASS32 :: ElfClass)
- SELFCLASS64 :: SElfClass (ELFCLASS64 :: ElfClass)
- data ElfData
- class (SingI c, Typeable c, Typeable (WordXX c), Data (WordXX c), Show (WordXX c), Read (WordXX c), Eq (WordXX c), Ord (WordXX c), Bounded (WordXX c), Enum (WordXX c), Num (WordXX c), Integral (WordXX c), Real (WordXX c), Bits (WordXX c), FiniteBits (WordXX c), Binary (Be (WordXX c)), Binary (Le (WordXX c))) => IsElfClass c where
- type WordXX c = r | r -> c
- wordSize :: Num a => ElfClass -> a
- withElfClass :: Sing c -> (IsElfClass c => a) -> a
- data HeaderXX c = HeaderXX {}
- headerSize :: Num a => ElfClass -> a
- type Header = Sigma ElfClass (TyCon1 HeaderXX)
- data SectionXX (c :: ElfClass) = SectionXX {}
- sectionTableEntrySize :: Num a => ElfClass -> a
- data SegmentXX (c :: ElfClass) = SegmentXX {}
- segmentTableEntrySize :: Num a => ElfClass -> a
- data SymbolXX (c :: ElfClass) = SymbolXX {}
- symbolTableEntrySize :: Num a => ElfClass -> a
- data RelaXX (c :: ElfClass) = RelaXX {
- relaOffset :: WordXX c
- relaSym :: Word32
- relaType :: Word32
- relaAddend :: WordXX c
- relocationTableAEntrySize :: forall a. IsElfClass a => WordXX a
- newtype HeadersXX a = HeadersXX (HeaderXX a, [SectionXX a], [SegmentXX a])
- parseHeaders :: MonadThrow m => ByteString -> m (Sigma ElfClass (TyCon1 HeadersXX))
- parseBList :: (MonadThrow m, Binary (Le a), Binary (Be a)) => ElfData -> ByteString -> m [a]
- serializeBList :: (Binary (Le a), Binary (Be a)) => ElfData -> [a] -> ByteString
- sectionIsSymbolTable :: ElfSectionType -> Bool
Data definition
ELF class. Tells if ELF defines 32- or 64-bit objects
Constructors
ELFCLASS32 | |
ELFCLASS64 |
Instances
data SElfClass :: ElfClass -> Type where Source #
Constructors
SELFCLASS32 :: SElfClass (ELFCLASS32 :: ElfClass) | |
SELFCLASS64 :: SElfClass (ELFCLASS64 :: ElfClass) |
Instances
TestCoercion SElfClass Source # | |
Defined in Data.Elf.Headers | |
TestEquality SElfClass Source # | |
Defined in Data.Elf.Headers | |
Show (SElfClass z) Source # | |
ELF data. Specifies the endianness of the ELF data
Constructors
ELFDATA2LSB | Little-endian ELF format |
ELFDATA2MSB | Big-endian ELF format |
class (SingI c, Typeable c, Typeable (WordXX c), Data (WordXX c), Show (WordXX c), Read (WordXX c), Eq (WordXX c), Ord (WordXX c), Bounded (WordXX c), Enum (WordXX c), Num (WordXX c), Integral (WordXX c), Real (WordXX c), Bits (WordXX c), FiniteBits (WordXX c), Binary (Be (WordXX c)), Binary (Le (WordXX c))) => IsElfClass c Source #
IsElfClass a
is defined for each constructor of ElfClass
.
It defines WordXX a
, which is Word32
for ELFCLASS32
and Word64
for ELFCLASS64
.
Instances
IsElfClass 'ELFCLASS32 Source # | |
Defined in Data.Elf.Headers Associated Types type WordXX 'ELFCLASS32 = (r :: Type) Source # | |
IsElfClass 'ELFCLASS64 Source # | |
Defined in Data.Elf.Headers Associated Types type WordXX 'ELFCLASS64 = (r :: Type) Source # |
withElfClass :: Sing c -> (IsElfClass c => a) -> a Source #
Convenience function for creating a context with an implicit ElfClass available.
Types of ELF header
Parsed ELF header
Constructors
HeaderXX | |
Fields
|
headerSize :: Num a => ElfClass -> a Source #
Size of ELF header.
Types of ELF tables
Section table
data SectionXX (c :: ElfClass) Source #
Parsed ELF section table entry
Constructors
SectionXX | |
Fields
|
sectionTableEntrySize :: Num a => ElfClass -> a Source #
Size of section table entry.
Segment table
data SegmentXX (c :: ElfClass) Source #
Parsed ELF segment table entry
Constructors
SegmentXX | |
Fields
|
segmentTableEntrySize :: Num a => ElfClass -> a Source #
Size of segment table entry.
Sybmol table
data SymbolXX (c :: ElfClass) Source #
Parsed ELF symbol table entry
Constructors
SymbolXX | |
symbolTableEntrySize :: Num a => ElfClass -> a Source #
Size of symbol table entry.
Relocation table
data RelaXX (c :: ElfClass) Source #
Parsed relocation table entry (ElfXX_Rela
)
Constructors
RelaXX | |
Fields
|
relocationTableAEntrySize :: forall a. IsElfClass a => WordXX a Source #
Size of RelaXX a
in bytes.
Parse header and section and segment tables
The type that helps to make the sigma type of the result
of the parseHeaders
function
parseHeaders :: MonadThrow m => ByteString -> m (Sigma ElfClass (TyCon1 HeadersXX)) Source #
Parse ELF file and produce header and section and segment tables
Parse/serialize array of data
BList is an internal newtype for [a]
that is an instance of Binary
.
When serializing, the Binary
instance for BList does not write the length of the array to the stream.
Instead, parser just reads all the stream till the end.
Arguments
:: (MonadThrow m, Binary (Le a), Binary (Be a)) | |
=> ElfData | Tells if parser should expect big or little endian data |
-> ByteString | Data for parsing |
-> m [a] |
Parse an array
Arguments
:: (Binary (Le a), Binary (Be a)) | |
=> ElfData | Tells if serializer should tread the data as bit or little endian |
-> [a] | The array to serialize |
-> ByteString |
Serialize an array
Misc helpers
sectionIsSymbolTable :: ElfSectionType -> Bool Source #
Test if the section with such integer value of section type field (sType
)
contains symbol table