melf-1.1.0: An Elf parser
Copyright(c) Aleksey Makarov 2021
LicenseBSD 3-Clause License
Maintaineraleksey.makarov@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Elf.Headers

Description

Parse headers and table entries of ELF files

Synopsis

Data definition

elfMagic :: Be Word32 Source #

The first 4 bytes of the ELF file

data ElfClass Source #

ELF class. Tells if ELF defines 32- or 64-bit objects

Constructors

ELFCLASS32 
ELFCLASS64 

Instances

Instances details
Show ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Binary ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: ElfClass -> Put #

get :: Get ElfClass #

putList :: [ElfClass] -> Put #

Binary Header Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Header -> Put #

get :: Get Header #

putList :: [Header] -> Put #

Eq ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

SingKind ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Associated Types

type Demote ElfClass = (r :: Type) #

SDecide ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

(%~) :: forall (a :: ElfClass) (b :: ElfClass). Sing a -> Sing b -> Decision (a :~: b) #

PEq ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Associated Types

type arg == arg1 :: Bool #

type arg /= arg1 :: Bool #

SEq ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

(%==) :: forall (t1 :: ElfClass) (t2 :: ElfClass). Sing t1 -> Sing t2 -> Sing (Apply (Apply (==@#@$) t1) t2) #

(%/=) :: forall (t1 :: ElfClass) (t2 :: ElfClass). Sing t1 -> Sing t2 -> Sing (Apply (Apply (/=@#@$) t1) t2) #

PShow ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Associated Types

type ShowsPrec arg arg1 arg2 :: Symbol #

type Show_ arg :: Symbol #

type ShowList arg arg1 :: Symbol #

SShow ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

sShowsPrec :: forall (t1 :: Natural) (t2 :: ElfClass) (t3 :: Symbol). Sing t1 -> Sing t2 -> Sing t3 -> Sing (Apply (Apply (Apply ShowsPrecSym0 t1) t2) t3) #

sShow_ :: forall (t :: ElfClass). Sing t -> Sing (Apply Show_Sym0 t) #

sShowList :: forall (t1 :: [ElfClass]) (t2 :: Symbol). Sing t1 -> Sing t2 -> Sing (Apply (Apply ShowListSym0 t1) t2) #

TestCoercion SElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

testCoercion :: forall (a :: k) (b :: k). SElfClass a -> SElfClass b -> Maybe (Coercion a b) #

TestEquality SElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

testEquality :: forall (a :: k) (b :: k). SElfClass a -> SElfClass b -> Maybe (a :~: b) #

SingI 'ELFCLASS32 Source # 
Instance details

Defined in Data.Elf.Headers

Methods

sing :: Sing 'ELFCLASS32 #

SingI 'ELFCLASS64 Source # 
Instance details

Defined in Data.Elf.Headers

Methods

sing :: Sing 'ELFCLASS64 #

type Demote ElfClass Source # 
Instance details

Defined in Data.Elf.Headers

type Sing Source # 
Instance details

Defined in Data.Elf.Headers

type Show_ (arg :: ElfClass) Source # 
Instance details

Defined in Data.Elf.Headers

type Show_ (arg :: ElfClass) = Apply (Show__6989586621679997126Sym0 :: TyFun ElfClass Symbol -> Type) arg
type (arg :: ElfClass) /= (arg1 :: ElfClass) Source # 
Instance details

Defined in Data.Elf.Headers

type (arg :: ElfClass) /= (arg1 :: ElfClass) = Apply (Apply (TFHelper_6989586621679146855Sym0 :: TyFun ElfClass (ElfClass ~> Bool) -> Type) arg) arg1
type (a1 :: ElfClass) == (a2 :: ElfClass) Source # 
Instance details

Defined in Data.Elf.Headers

type (a1 :: ElfClass) == (a2 :: ElfClass)
type ShowList (arg :: [ElfClass]) arg1 Source # 
Instance details

Defined in Data.Elf.Headers

type ShowList (arg :: [ElfClass]) arg1 = Apply (Apply (ShowList_6989586621679997142Sym0 :: TyFun [ElfClass] (Symbol ~> Symbol) -> Type) arg) arg1
type ShowsPrec a1 (a2 :: ElfClass) a3 Source # 
Instance details

Defined in Data.Elf.Headers

type ShowsPrec a1 (a2 :: ElfClass) a3

data SElfClass :: ElfClass -> Type where Source #

Instances

Instances details
TestCoercion SElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

testCoercion :: forall (a :: k) (b :: k). SElfClass a -> SElfClass b -> Maybe (Coercion a b) #

TestEquality SElfClass Source # 
Instance details

Defined in Data.Elf.Headers

Methods

testEquality :: forall (a :: k) (b :: k). SElfClass a -> SElfClass b -> Maybe (a :~: b) #

Show (SElfClass z) Source # 
Instance details

Defined in Data.Elf.Headers

data ElfData Source #

ELF data. Specifies the endianness of the ELF data

Constructors

ELFDATA2LSB

Little-endian ELF format

ELFDATA2MSB

Big-endian ELF format

Instances

Instances details
Show ElfData Source # 
Instance details

Defined in Data.Elf.Headers

Binary ElfData Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: ElfData -> Put #

get :: Get ElfData #

putList :: [ElfData] -> Put #

Eq ElfData Source # 
Instance details

Defined in Data.Elf.Headers

Methods

(==) :: ElfData -> ElfData -> Bool #

(/=) :: ElfData -> ElfData -> Bool #

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 :: ElfClass) Source #

IsElfClass a is defined for each constructor of ElfClass. It defines WordXX a, which is Word32 for ELFCLASS32 and Word64 for ELFCLASS64.

Associated Types

type WordXX c = r | r -> c Source #

Instances

Instances details
IsElfClass 'ELFCLASS32 Source # 
Instance details

Defined in Data.Elf.Headers

Associated Types

type WordXX 'ELFCLASS32 = (r :: Type) Source #

IsElfClass 'ELFCLASS64 Source # 
Instance details

Defined in Data.Elf.Headers

Associated Types

type WordXX 'ELFCLASS64 = (r :: Type) Source #

wordSize :: Num a => ElfClass -> a Source #

Size of WordXX a in bytes.

withElfClass :: Sing c -> (IsElfClass c => a) -> a Source #

Convenience function for creating a context with an implicit ElfClass available.

Types of ELF header

data HeaderXX c Source #

Parsed ELF header

Constructors

HeaderXX 

Fields

Instances

Instances details
Binary Header Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Header -> Put #

get :: Get Header #

putList :: [Header] -> Put #

headerSize :: Num a => ElfClass -> a Source #

Size of ELF header.

type Header = Sigma ElfClass (TyCon1 HeaderXX) Source #

Sigma type where ElfClass defines the type of HeaderXX

Types of ELF tables

Section table

data SectionXX c Source #

Parsed ELF section table entry

Constructors

SectionXX 

Fields

Instances

Instances details
SingI a => Binary (Be (SectionXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Be (SectionXX a) -> Put #

get :: Get (Be (SectionXX a)) #

putList :: [Be (SectionXX a)] -> Put #

SingI a => Binary (Le (SectionXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Le (SectionXX a) -> Put #

get :: Get (Le (SectionXX a)) #

putList :: [Le (SectionXX a)] -> Put #

sectionTableEntrySize :: Num a => ElfClass -> a Source #

Size of section table entry.

Segment table

data SegmentXX c Source #

Parsed ELF segment table entry

Constructors

SegmentXX 

Fields

Instances

Instances details
SingI a => Binary (Be (SegmentXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Be (SegmentXX a) -> Put #

get :: Get (Be (SegmentXX a)) #

putList :: [Be (SegmentXX a)] -> Put #

SingI a => Binary (Le (SegmentXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Le (SegmentXX a) -> Put #

get :: Get (Le (SegmentXX a)) #

putList :: [Le (SegmentXX a)] -> Put #

segmentTableEntrySize :: Num a => ElfClass -> a Source #

Size of segment table entry.

Sybmol table

data SymbolXX c Source #

Parsed ELF symbol table entry

Constructors

SymbolXX 

Fields

Instances

Instances details
SingI a => Binary (Be (SymbolXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Be (SymbolXX a) -> Put #

get :: Get (Be (SymbolXX a)) #

putList :: [Be (SymbolXX a)] -> Put #

SingI a => Binary (Le (SymbolXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Le (SymbolXX a) -> Put #

get :: Get (Le (SymbolXX a)) #

putList :: [Le (SymbolXX a)] -> Put #

symbolTableEntrySize :: Num a => ElfClass -> a Source #

Size of symbol table entry.

Relocation table

data RelaXX c Source #

Parsed relocation table entry (ElfXX_Rela)

Constructors

RelaXX 

Fields

Instances

Instances details
SingI a => Binary (Be (RelaXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Be (RelaXX a) -> Put #

get :: Get (Be (RelaXX a)) #

putList :: [Be (RelaXX a)] -> Put #

SingI a => Binary (Le (RelaXX a)) Source # 
Instance details

Defined in Data.Elf.Headers

Methods

put :: Le (RelaXX a) -> Put #

get :: Get (Le (RelaXX a)) #

putList :: [Le (RelaXX a)] -> Put #

relocationTableAEntrySize :: forall a. IsElfClass a => WordXX a Source #

Size of RelaXX a in bytes.

Parse header and section and segment tables

newtype HeadersXX a Source #

The type that helps to make the sigma type of the result of the parseHeaders function

Constructors

HeadersXX (HeaderXX a, [SectionXX a], [SegmentXX a]) 

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.

parseBList Source #

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

serializeBList Source #

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