Copyright | (c) Aleksey Makarov 2021 |
---|---|
License | BSD 3-Clause License |
Maintainer | aleksey.makarov@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Parse headers and table entries of ELF files
Synopsis
- elfMagic :: Be Word32
- data ElfClass
- data ElfData
- data SingElfClass :: ElfClass -> Type 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 = r | r -> c
- singElfClass :: SingElfClass c
- withSingElfClass :: SingElfClassI c => (SingElfClass c -> r) -> r
- withSingElfClassI :: SingElfClass c -> (SingElfClassI c => r) -> r
- fromSingElfClass :: SingElfClass c -> ElfClass
- withElfClass :: ElfClass -> (forall c. SingElfClassI c => SingElfClass c -> r) -> r
- data HeaderXX c = HeaderXX {}
- headerSize :: Num a => ElfClass -> a
- data Header = forall a. Header (SingElfClass a) (HeaderXX a)
- data SectionXX c = SectionXX {}
- sectionTableEntrySize :: Num a => ElfClass -> a
- data SegmentXX c = SegmentXX {}
- segmentTableEntrySize :: Num a => ElfClass -> a
- data SymbolXX c = SymbolXX {}
- symbolTableEntrySize :: Num a => ElfClass -> a
- data RelaXX c = RelaXX {
- relaOffset :: WordXX c
- relaSym :: Word32
- relaType :: Word32
- relaAddend :: WordXX c
- relocationTableAEntrySize :: forall a. SingElfClassI a => WordXX a
- data Headers = forall a. 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 :: 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 :: ElfClass -> Type 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 type WordXX 'ELFCLASS32 = (r :: Type) Source # | |
SingElfClassI 'ELFCLASS64 Source # | |
Defined in Data.Elf.Headers type WordXX 'ELFCLASS64 = (r :: Type) Source # |
withSingElfClass :: 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 :: SingElfClass c -> (SingElfClassI c => r) -> r Source #
Convenience function for creating a context with an implicit singleton available.
See also withSing
fromSingElfClass :: SingElfClass c -> ElfClass Source #
Convert a singleton to its unrefined version.
See also fromSing
withElfClass :: ElfClass -> (forall c. SingElfClassI c => SingElfClass c -> r) -> r Source #
Use this instead of toSing
Types of ELF header
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
forall a. Header (SingElfClass a) (HeaderXX a) |
Types of ELF tables
Section table
Parsed ELF section table entry
SectionXX | |
|
sectionTableEntrySize :: Num a => ElfClass -> a Source #
Size of section table entry.
Segment table
Parsed ELF segment table entry
SegmentXX | |
|
segmentTableEntrySize :: Num a => ElfClass -> a Source #
Size of segment table entry.
Sybmol table
Parsed ELF symbol table entry
symbolTableEntrySize :: Num a => ElfClass -> a Source #
Size of symbol table entry.
Relocation table
Parsed relocation table entry (ElfXX_Rela
)
RelaXX | |
|
relocationTableAEntrySize :: forall a. 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
.
forall a. 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
:: 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