haskus-system- Haskus system programming framework

Safe HaskellNone




ELF binary format



data Elf Source #

Structure representing a ELF file

An ELF file starts with a PreHeader that contains the magic number and that describes how the remaining of the file has to be decoded (e.g. endianness, word size).

Then comes the Header which mentions the target architecture, the type of ELF file, some flags, etc. It also gives information on where to find section and segment tables in the file.





Show Elf Source # 


showsPrec :: Int -> Elf -> ShowS #

show :: Elf -> String #

showList :: [Elf] -> ShowS #

parseElf :: Buffer -> Elf Source #

Parse a Buffer to retrieve ELF headers and tables.

readElf :: FilePath -> IO Elf Source #

Lazily read an ELF file


getSectionByIndex :: Integral a => Elf -> a -> Maybe Section Source #

Get a section by index

getSectionContentBuffer :: Elf -> Section -> Buffer Source #

Returns the content of a section as a buffer

getEntriesWithAlignment :: Word -> Get a -> Get [a] Source #

Get a sequence of aligned entries with their offset

getEntriesAndOffsetWithAlignment :: Word -> Get a -> Get [(Word64, a)] Source #

Get a sequence of entries. Each entry is aligned to the given number of bytes. The first entry must be correctly aligned.

getEntryTableFromSection :: Elf -> Section -> Get a -> [a] Source #

Return a sequence of entries from a section. The entry size is given by the sectionEntrySize field

getEntryListFromSection :: Integral b => Elf -> Section -> Get a -> (a -> b) -> [a] Source #

Get a linked list of entries from a section next returns the next address

findSectionByName :: Elf -> Text -> Maybe Section Source #

Find section with name

data FullSectionType Source #

Fields are reused depending on the section types. This type gives a meaningful section type




BasicSectionType SectionType 

getFullSectionType :: Elf -> Section -> FullSectionType Source #

Convert a raw section into a more complete section data type

Strings sections

getStringsFromSection :: Elf -> Section -> [(Word64, Text)] Source #

Extract strings from a strings section

Section names

getSectionNameByIndex :: Elf -> SectionIndex -> Maybe Text Source #

Return the name of a section from its index

getSectionNamesSection :: Elf -> Maybe Section Source #

Return the section containing section names (if any)

getSectionName :: Elf -> Section -> Maybe Text Source #

Return the name of a section

getSectionNames :: Elf -> Vector (Section, Maybe Text) Source #

Return all the section names

Symbols sections

isSymbolSection :: Section -> Bool Source #

Indicate if the section contains symbols

getSymbolsFromSection :: Elf -> Section -> [SymbolEntry] Source #

Get symbols from a section

getSymbolNames :: Elf -> Section -> [SymbolEntry] -> [Maybe Text] Source #

Get symbol names from the associated symbol name table

getSymbols :: Elf -> Section -> [(Maybe Text, SymbolEntry)] Source #

Get symbols with their names

getAllSymbols :: Elf -> [(Maybe Text, SymbolEntry)] Source #

Get all the symbols in the ELF file

getSymbolByName :: Elf -> Text -> Maybe SymbolEntry Source #

Find a symbol by its name

getSymbolBuffer :: SymbolEntry -> Word64 -> IO Buffer Source #

Get symbol buffer (duplicate)

Relocation sections

getRelocationEntriesFromSection :: Elf -> Section -> [RelocationEntry] Source #

Get relocation entries from a section

Dynamic sections

data DynamicEntry Source #

Entry in the .dynamic section


DynEntryRaw RawDynamicEntry

Raw entry


Empty entry

DynEntryFlags DynamicEntryFlags


DynEntryStateFlags DynamicStateFlags

State flags

DynEntryPositionalFlags DynamicPositionalFlags

Positional flags

DynEntryFeatureSelection DynamicFeatures

Feature selection

DynEntryNeededLibrary Text

Needed library name

DynEntryStringTableAddress Word64

String table address

DynEntryStringTableSize Word64

String table size

DynEntrySymbolTableAddress Word64

Symbol table address

DynEntrySymbolEntrySize Word64

Symbol entry size

DynEntryInitFunctionAddress Word64

Init function address

DynEntryFiniFunctionAddress Word64

Fini function address

DynEntryInitFunctionArrayAddress Word64

Init function array address

DynEntryFiniFunctionArrayAddress Word64

Fini function array address

DynEntryInitFunctionArraySize Word64

Init function array size

DynEntryFiniFunctionArraySize Word64

Fini function array size

DynEntrySymbolHashTableAddress Word64

Symbol hash table address

DynEntryGNUSymbolHashTableAddress Word64

GNU symbol hash table address

DynEntryPLTRelocAddress Word64

Address of the PLT relocations

DynEntryPLTGOTAddress Word64

Address of the global offset table (GOT) for the PLT relocations

DynEntryPLTRelocSize Word64

Size in bytes of PLT relocations

DynEntryRelocaAddress Word64

Address of relocations with addend

DynEntryRelocaSize Word64

Size in bytes of relocations with addend

DynEntryRelocaEntrySize Word64

Size in bytes of a relocation with addend entry

getDynamicEntry :: Elf -> Section -> Get DynamicEntry Source #

Getter for a single dynamic entry

Version sections

getVersionNeededEntriesFromSection :: Elf -> Section -> [VersionNeeded] Source #

Get version needed entries from a section

Notes sections

data Note Source #





getNoteEntriesFromSection :: Elf -> Section -> [Note] Source #

Get note entries

Debug sections

Intel specific sections

getZCATableFromSection :: Elf -> Section -> ZCATable Source #

Return ZCA table (e.g. optimization report)