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
- newtype ElfList c = ElfList [ElfXX c]
- type Elf = Sigma ElfClass (TyCon1 ElfList)
- data ElfSectionData c
- data ElfXX c
- = ElfHeader { }
- | ElfSectionTable
- | ElfSegmentTable
- | ElfSection {
- esName :: String
- esType :: ElfSectionType
- esFlags :: ElfSectionFlag
- esAddr :: WordXX c
- esAddrAlign :: WordXX c
- esEntSize :: WordXX c
- esN :: ElfSectionIndex
- esInfo :: Word32
- esLink :: Word32
- esData :: ElfSectionData c
- | ElfSegment {
- epType :: ElfSegmentType
- epFlags :: ElfSegmentFlag
- epVirtAddr :: WordXX c
- epPhysAddr :: WordXX c
- epAddMemSize :: WordXX c
- epAlign :: WordXX c
- epData :: [ElfXX c]
- | ElfRawData {
- edData :: ByteString
- | ElfRawAlign { }
- parseElf :: MonadCatch m => ByteString -> m Elf
- serializeElf :: MonadThrow 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) => [ElfXX a] -> b -> m (ElfXX a)
- elfFindSectionByName :: forall a m. (SingI a, MonadThrow m) => [ElfXX a] -> String -> m (ElfXX a)
- elfFindHeader :: forall a m. (SingI a, MonadThrow m) => [ElfXX a] -> m (ElfXX 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 a -> [ElfXX a] -> m [ElfSymbolXX a]
- serializeSymbolTable :: (MonadThrow m, SingI a) => ElfData -> [ElfSymbolXX a] -> m (ByteString, ByteString)
Elf
Elf
is a forrest of trees of type ElfXX
.
Trees are composed of ElfXX
nodes, ElfSegment
can contain subtrees
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 | |
ElfSegmentTable | |
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 :: MonadThrow 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) | |
=> [ElfXX a] | Structured ELF data |
-> b | Number of the section |
-> m (ElfXX a) | The section in question |
Find section with a given number
:: 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
:: 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 Source #
Parsed ELF symbol table entry. NB: This is work in progress
ElfSymbolXX | |
|
:: (MonadThrow m, SingI a) | |
=> ElfData | Endianness of the ELF file |
-> ElfXX a | Parsed section such that |
-> [ElfXX 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