melf-1.0.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

newtype ElfList c Source #

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

Constructors

ElfList [ElfXX c] 

type Elf = Sigma ElfClass (TyCon1 ElfList) Source #

Elf is a sigma type where ElfClass defines the type of ElfList

data ElfSectionData 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 ByteString

Regular section data

ElfSectionDataStringTable

Section data will be generated from section names

data ElfXX (c :: ElfClass) Source #

The type of node that defines Elf structure.

Constructors

ElfHeader 

Fields

ElfSectionTable 
ElfSegmentTable 
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

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

Parse ELF file

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

Serialze ELF file

Misc

getSectionData Source #

Arguments

:: IsElfClass a 
=> ByteString

ELF file

-> SectionXX a

Parsed section entry

-> ByteString

Section Data

Get section data

getString Source #

Arguments

:: 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

elfFindSection Source #

Arguments

:: forall a m b. (SingI a, MonadThrow m, Integral b, Show b) 
=> [ElfXX a]

Structured ELF data

-> b

Number of the section

-> m (ElfXX a)

The section in question

Find section with a given number

elfFindSectionByName Source #

Arguments

:: forall a m. (SingI a, MonadThrow m) 
=> [ElfXX a]

Structured ELF data

-> String

Section name

-> m (ElfXX a)

The section in question

Find section with a given name

elfFindHeader Source #

Arguments

:: forall a m. (SingI a, MonadThrow m) 
=> [ElfXX a]

Structured ELF data

-> m (ElfXX 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

:: (MonadThrow m, SingI a) 
=> ElfData

Endianness of the ELF file

-> ElfXX a

Parsed section such that sectionIsSymbolTable . sType is true.

-> [ElfXX a]

Structured ELF data

-> m [ElfSymbolXX a]

Symbol table

Parse symbol table

serializeSymbolTable Source #

Arguments

:: (MonadThrow m, SingI 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