Copyright | (c) Aleksey Makarov 2021 |
---|---|
License | BSD 3-Clause License |
Maintainer | aleksey.makarov@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Parse headers and table entries of ELF files
Synopsis
- elfMagic :: Be Word32
- data ElfClass
- data ElfData
- data SingElfClass (a :: ElfClass) where
- class (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))) => SingElfClassI (c :: ElfClass) where
- type WordXX (c :: ElfClass) = (r :: Type) | r -> c
- singElfClass :: SingElfClass c
- withSingElfClass :: forall (c :: ElfClass) r. SingElfClassI c => (SingElfClass c -> r) -> r
- withSingElfClassI :: forall (c :: ElfClass) r. SingElfClass c -> (SingElfClassI c => r) -> r
- fromSingElfClass :: forall (c :: ElfClass). SingElfClass c -> ElfClass
- withElfClass :: ElfClass -> (forall (c :: ElfClass). SingElfClassI c => SingElfClass c -> r) -> r
- data HeaderXX (c :: ElfClass) = HeaderXX {}
- headerSize :: Num a => ElfClass -> a
- data Header = Header (SingElfClass a) (HeaderXX a)
- 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 :: ElfClass). SingElfClassI a => WordXX a
- data Headers = Headers (SingElfClass a) (HeaderXX a) [SectionXX a] [SegmentXX a]
- parseHeaders :: MonadThrow m => ByteString -> m Headers
- 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
- getSectionData :: forall (a :: ElfClass). SingElfClassI a => ByteString -> SectionXX a -> ByteString
- getString :: ByteString -> Int64 -> String
- wordSize :: Num a => ElfClass -> a
Data definition
ELF class. Tells if ELF defines 32- or 64-bit objects
ELFCLASS32 | 32-bit ELF format |
ELFCLASS64 | 64-bit ELF format |
ELF data. Specifies the endianness of the ELF data
ELFDATA2LSB | Little-endian ELF format |
ELFDATA2MSB | Big-endian ELF format |
Singletons
data SingElfClass (a :: ElfClass) where Source #
Singletons for ElfClass
SELFCLASS32 | |
| |
SELFCLASS64 | |
|
class (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))) => SingElfClassI (c :: ElfClass) where Source #
SingElfClassI a
is defined for each constructor of ElfClass
.
It defines WordXX a
, which is Word32
for ELFCLASS32
and Word64
for ELFCLASS64
.
Also it defines singletons for each of the ElfClass
type.
singElfClass :: SingElfClass c Source #
Instances
SingElfClassI 'ELFCLASS32 Source # | |||||
Defined in Data.Elf.Headers
| |||||
SingElfClassI 'ELFCLASS64 Source # | |||||
Defined in Data.Elf.Headers
|
withSingElfClass :: forall (c :: ElfClass) r. SingElfClassI c => (SingElfClass c -> r) -> r Source #
A convenience function useful when we need to name a singleton value multiple times.
Without this function, each use of sing could potentially refer to a different singleton,
and one has to use type signatures (often with ScopedTypeVariables) to ensure that they are the same.
See also withSingI
withSingElfClassI :: forall (c :: ElfClass) r. SingElfClass c -> (SingElfClassI c => r) -> r Source #
Convenience function for creating a context with an implicit singleton available.
See also withSing
fromSingElfClass :: forall (c :: ElfClass). SingElfClass c -> ElfClass Source #
Convert a singleton to its unrefined version.
See also fromSing
withElfClass :: ElfClass -> (forall (c :: ElfClass). SingElfClassI c => SingElfClass c -> r) -> r Source #
Use this instead of toSing
Types of ELF header
data HeaderXX (c :: ElfClass) Source #
Parsed ELF header
HeaderXX | |
|
headerSize :: Num a => ElfClass -> a Source #
Size of ELF header.
Header is a sigma type where the first entry defines the type of the second one
Header (SingElfClass a) (HeaderXX a) |
Types of ELF tables
Section table
data SectionXX (c :: ElfClass) Source #
Parsed ELF section table entry
SectionXX | |
|
sectionTableEntrySize :: Num a => ElfClass -> a Source #
Size of section table entry.
Segment table
data SegmentXX (c :: ElfClass) Source #
Parsed ELF segment table entry
SegmentXX | |
|
segmentTableEntrySize :: Num a => ElfClass -> a Source #
Size of segment table entry.
Sybmol table
data SymbolXX (c :: ElfClass) Source #
Parsed ELF symbol table entry
symbolTableEntrySize :: Num a => ElfClass -> a Source #
Size of symbol table entry.
Relocation table
data RelaXX (c :: ElfClass) Source #
Parsed relocation table entry (ElfXX_Rela
)
RelaXX | |
|
relocationTableAEntrySize :: forall (a :: ElfClass). SingElfClassI a => WordXX a Source #
Size of RelaXX a
in bytes.
Parse header and section and segment tables
Sigma type to hold the ELF header and section and segment tables for a given ElfClass
.
Headers (SingElfClass a) (HeaderXX a) [SectionXX a] [SegmentXX a] |
parseHeaders :: MonadThrow m => ByteString -> m Headers 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.
:: (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
:: (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
:: forall (a :: ElfClass). SingElfClassI a | |
=> ByteString | ELF file |
-> SectionXX a | Parsed section entry |
-> ByteString | Section Data |
Get section data
:: ByteString | Section data of a string table section |
-> Int64 | Offset to the start of the string in that data |
-> String |
Get string from string table