Copyright | (c) Aleksey Makarov 2021 |
---|---|
License | BSD 3-Clause License |
Maintainer | aleksey.makarov@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Parse/serialize ELF files into structured data
Synopsis
- data ElfNodeType
- data ElfListXX c where
- ElfListCons :: ElfXX t c -> ElfListXX c -> ElfListXX c
- ElfListNull :: ElfListXX c
- type Elf = Sigma ElfClass (TyCon1 ElfListXX)
- data ElfSectionData c
- data ElfXX t c where
- ElfHeader :: {..} -> ElfXX 'Header c
- ElfSectionTable :: ElfXX 'SectionTable c
- ElfSegmentTable :: ElfXX 'SegmentTable c
- ElfSection :: {..} -> ElfXX 'Section c
- ElfSegment :: {..} -> ElfXX 'Segment c
- ElfRawData :: {..} -> ElfXX 'RawData c
- ElfRawAlign :: {..} -> ElfXX 'RawAlign c
- (~:) :: ElfXX t a -> ElfListXX a -> ElfListXX a
- parseElf :: MonadCatch m => ByteString -> m Elf
- serializeElf :: MonadCatch m => Elf -> m ByteString
- getSectionData :: IsElfClass a => ByteString -> SectionXX a -> ByteString
- getString :: ByteString -> Int64 -> String
- elfFindSection :: forall a m b. (SingI a, MonadThrow m, Integral b, Show b) => ElfListXX a -> b -> m (ElfXX 'Section a)
- elfFindSectionByName :: forall a m. (SingI a, MonadThrow m) => ElfListXX a -> String -> m (ElfXX 'Section a)
- elfFindHeader :: forall a m. (SingI a, MonadThrow m) => ElfListXX a -> m (ElfXX 'Header a)
- data ElfSymbolXX c = ElfSymbolXX {
- steName :: String
- steBind :: ElfSymbolBinding
- steType :: ElfSymbolType
- steShNdx :: ElfSectionIndex
- steValue :: WordXX c
- steSize :: WordXX c
- parseSymbolTable :: (MonadThrow m, SingI a) => ElfData -> ElfXX 'Section a -> ElfListXX a -> m [ElfSymbolXX a]
- serializeSymbolTable :: (MonadThrow m, SingI a) => ElfData -> [ElfSymbolXX a] -> m (ByteString, ByteString)
Elf
data ElfNodeType Source #
Elf
is a forrest of trees of type ElfXX
.
Trees are composed of ElfXX
nodes, ElfSegment
can contain subtrees
data ElfListXX c where Source #
ElfListCons :: ElfXX t c -> ElfListXX c -> ElfListXX c | |
ElfListNull :: ElfListXX c |
type Elf = Sigma ElfClass (TyCon1 ElfListXX) Source #
Elf is a sigma type where ElfClass
defines the type of ElfList
data ElfSectionData c 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 |
The type of node that defines Elf structure.
ElfHeader | |
| |
ElfSectionTable :: ElfXX 'SectionTable c | |
ElfSegmentTable :: 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 |
parseElf :: MonadCatch m => ByteString -> m Elf Source #
Parse ELF file
serializeElf :: MonadCatch m => Elf -> m ByteString Source #
Serialze ELF file
Misc
:: IsElfClass a | |
=> ByteString | ELF file |
-> SectionXX a | Parsed section entry |
-> ByteString | Section Data |
Get section data
:: 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
:: forall a m b. (SingI 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 m. (SingI 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 m. (SingI a, MonadThrow m) | |
=> ElfListXX a | Structured ELF data |
-> m (ElfXX 'Header a) | ELF header |
Find ELF header
Symbol table
data ElfSymbolXX c Source #
Parsed ELF symbol table entry. NB: This is work in progress
ElfSymbolXX | |
|
:: (MonadThrow m, SingI 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
:: (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