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

Data.Elf

Description

Parse/serialize ELF files into structured data

Synopsis

Elf

data ElfListXX (c :: ElfClass) where Source #

List of ELF nodes.

Constructors

ElfListCons :: forall (t :: ElfNodeType) (c :: ElfClass). ElfXX t c -> ElfListXX c -> ElfListXX c 
ElfListNull :: forall (c :: ElfClass). ElfListXX c 

(~:) :: forall (t :: ElfNodeType) (a :: ElfClass). ElfXX t a -> ElfListXX a -> ElfListXX a infixr 9 Source #

Helper for ElfListCons

data ElfNodeType Source #

Elf is a forrest of trees of type ElfXX. Trees are composed of ElfXX nodes, ElfSegment can contain subtrees

data ElfSectionData (c :: ElfClass) Source #

Section data may contain a string table. If a section contains a string table with section names, the data for such a section is generated and esData should contain ElfSectionDataStringTable

Constructors

ElfSectionData

Regular section data

Fields

ElfSectionDataStringTable

Section data will be generated from section names

ElfSectionDataNoBits

SHT_NOBITS uninitialized section data: section has size but no content

Fields

data ElfXX (t :: ElfNodeType) (c :: ElfClass) where Source #

The type of node that defines Elf structure.

Constructors

ElfHeader 

Fields

ElfSectionTable :: forall (c :: ElfClass). ElfXX 'SectionTable c 
ElfSegmentTable :: forall (c :: ElfClass). ElfXX 'SegmentTable c 
ElfSection 

Fields

ElfSegment 

Fields

ElfRawData

Some ELF files (some executables) don't bother to define sections for linking and have just raw data in segments.

Fields

ElfRawAlign

Align the next data in the ELF file. The offset of the next data in the ELF file will be the minimal x such that x mod eaAlign == eaOffset mod eaAlign

Fields

data Elf Source #

Elf is a sigma type where the first entry defines the type of the second one

Constructors

Elf (SingElfClass a) (ElfListXX a) 

parseElf :: MonadCatch m => ByteString -> m Elf Source #

Parse ELF file

serializeElf :: MonadCatch m => Elf -> m ByteString Source #

Serialze ELF file

Misc

elfFindSection Source #

Arguments

:: forall (a :: ElfClass) m b. (SingElfClassI a, MonadThrow m, Integral b, Show b) 
=> ElfListXX a

Structured ELF data

-> b

Number of the section

-> m (ElfXX 'Section a)

The section in question

Find section with a given number

elfFindSectionByName Source #

Arguments

:: forall (a :: ElfClass) m. (SingElfClassI a, MonadThrow m) 
=> ElfListXX a

Structured ELF data

-> String

Section name

-> m (ElfXX 'Section a)

The section in question

Find section with a given name

elfFindHeader Source #

Arguments

:: forall (a :: ElfClass) m. (SingElfClassI a, MonadThrow m) 
=> ElfListXX a

Structured ELF data

-> m (ElfXX 'Header a)

ELF header

Find ELF header

Symbol table

data ElfSymbolXX (c :: ElfClass) Source #

Parsed ELF symbol table entry. NB: This is work in progress

Constructors

ElfSymbolXX 

Fields

parseSymbolTable Source #

Arguments

:: forall m (a :: ElfClass). (MonadThrow m, SingElfClassI a) 
=> ElfData

Endianness of the ELF file

-> ElfXX 'Section a

Parsed section such that sectionIsSymbolTable . sType is true.

-> ElfListXX a

Structured ELF data

-> m [ElfSymbolXX a]

Symbol table

Parse symbol table

serializeSymbolTable Source #

Arguments

:: forall m (a :: ElfClass). (MonadThrow m, SingElfClassI a) 
=> ElfData

Endianness of the ELF file

-> [ElfSymbolXX a]

Symbol table

-> m (ByteString, ByteString)

Pair of symbol table section data and string table section data

Serialize symbol table