Copyright | (c) Aleksey Makarov 2021 |
---|---|
License | BSD 3-Clause License |
Maintainer | aleksey.makarov@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Parse/serialize ELF files into structured data
Synopsis
- data ElfListXX (c :: ElfClass) where
- 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
- data ElfNodeType
- data ElfSectionData (c :: ElfClass)
- data ElfXX (t :: ElfNodeType) (c :: ElfClass) where
- ElfHeader :: forall (c :: ElfClass). {..} -> ElfXX 'Header c
- ElfSectionTable :: forall (c :: ElfClass). ElfXX 'SectionTable c
- ElfSegmentTable :: forall (c :: ElfClass). ElfXX 'SegmentTable c
- ElfSection :: forall (c :: ElfClass). {..} -> ElfXX 'Section c
- ElfSegment :: forall (c :: ElfClass). {..} -> ElfXX 'Segment c
- ElfRawData :: forall (c :: ElfClass). {..} -> ElfXX 'RawData c
- ElfRawAlign :: forall (c :: ElfClass). {..} -> ElfXX 'RawAlign c
- data Elf = Elf (SingElfClass a) (ElfListXX a)
- parseElf :: MonadCatch m => ByteString -> m Elf
- serializeElf :: MonadCatch m => Elf -> m ByteString
- elfFindSection :: forall (a :: ElfClass) m b. (SingElfClassI a, MonadThrow m, Integral b, Show b) => ElfListXX a -> b -> m (ElfXX 'Section a)
- elfFindSectionByName :: forall (a :: ElfClass) m. (SingElfClassI a, MonadThrow m) => ElfListXX a -> String -> m (ElfXX 'Section a)
- elfFindHeader :: forall (a :: ElfClass) m. (SingElfClassI a, MonadThrow m) => ElfListXX a -> m (ElfXX 'Header a)
- data ElfSymbolXX (c :: ElfClass) = ElfSymbolXX {
- steName :: String
- steBind :: ElfSymbolBinding
- steType :: ElfSymbolType
- steShNdx :: ElfSectionIndex
- steValue :: WordXX c
- steSize :: WordXX c
- parseSymbolTable :: forall m (a :: ElfClass). (MonadThrow m, SingElfClassI a) => ElfData -> ElfXX 'Section a -> ElfListXX a -> m [ElfSymbolXX a]
- serializeSymbolTable :: forall m (a :: ElfClass). (MonadThrow m, SingElfClassI a) => ElfData -> [ElfSymbolXX a] -> m (ByteString, ByteString)
Elf
data ElfListXX (c :: ElfClass) where Source #
List of ELF nodes.
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
ElfSectionData | Regular section data |
| |
ElfSectionDataStringTable | Section data will be generated from section names |
ElfSectionDataNoBits | SHT_NOBITS uninitialized section data: section has size but no content |
data ElfXX (t :: ElfNodeType) (c :: ElfClass) where Source #
The type of node that defines Elf structure.
ElfHeader | |
| |
ElfSectionTable :: forall (c :: ElfClass). ElfXX 'SectionTable c | |
ElfSegmentTable :: forall (c :: ElfClass). ElfXX 'SegmentTable c | |
ElfSection | |
| |
ElfSegment | |
| |
ElfRawData | Some ELF files (some executables) don't bother to define sections for linking and have just raw data in segments. |
| |
ElfRawAlign | Align the next data in the ELF file.
The offset of the next data in the ELF file
will be the minimal |
Elf is a sigma type where the first entry defines the type of the second one
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
:: 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
:: 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
:: 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
ElfSymbolXX | |
|
:: forall m (a :: ElfClass). (MonadThrow m, SingElfClassI a) | |
=> ElfData | Endianness of the ELF file |
-> ElfXX 'Section a | Parsed section such that |
-> ElfListXX a | Structured ELF data |
-> m [ElfSymbolXX a] | Symbol table |
Parse symbol table
:: 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