Copyright | Galois Inc 2016-18 |
---|---|
Maintainer | jhendrix@galois.com |
Safe Haskell | None |
Language | Haskell2010 |
Data.Macaw.Memory.ElfLoader
Contents
Description
Operations for creating a view of memory from an elf file.
Synopsis
- memoryForElf :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError])
- memoryForElf' :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> (SymtabEntry ByteString (ElfWordType w) -> Bool) -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError])
- memoryForElfAllSymbols :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError])
- memoryForElfSections :: forall (w :: Nat). ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning])
- memoryForElfSegments :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning])
- memoryForElfSegments' :: forall (w :: Nat). RegionIndex -> Integer -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning])
- type SectionIndexMap (w :: Nat) = Map Word16 (MemSegmentOff w)
- data MemLoadWarning
- = SectionNotAlloc !SectionName
- | MultipleSectionsWithName !SectionName
- | MultipleDynamicSegments
- | OverlappingLoadableSegments
- | UnsupportedSection !SectionName
- | UnknownDefinedSymbolBinding !SymbolName ElfSymbolBinding
- | UnknownDefinedSymbolType !SymbolName ElfSymbolType
- | UnknownUndefinedSymbolBinding !SymbolName ElfSymbolBinding
- | UnknownUndefinedSymbolType !SymbolName ElfSymbolType
- | ExpectedSectionSymbolNameEmpty !SymbolName
- | ExpectedSectionSymbolLocal
- | InvalidSectionSymbolIndex !ElfSectionIndex
- | UnsupportedProcessorSpecificSymbolIndex !SymbolName !ElfSectionIndex
- | MultipleRelocationTables
- | RelocationParseFailure !String
- | DynamicTagsOutOfRange !ElfDynamicTag !ElfDynamicTag !Word64 !Word64
- | DynamicTagPairMismatch !ElfDynamicTag !ElfDynamicTag
- | DynamicMultipleTags !ElfDynamicTag
- | AndroidRelWithNonzeroAddend
- | AndroidRelDecodingError !ElfDynamicTag !AndroidDecodeError
- | MultipleRelocationsAtAddr !Word64
- | IgnoreRelocation !RelocationError
- | ShdrPhdrOverlap
- data RelocationError
- type SectionName = ByteString
- resolveElfContents :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String ([String], Memory w, Maybe (MemSegmentOff w), [MemSymbol w])
- elfAddrWidth :: forall (w :: Nat). ElfClass w -> AddrWidthRepr w
- adjustedLoadRegionIndex :: ElfType -> LoadOptions -> RegionIndex
- data MemSymbol (w :: Nat) = MemSymbol {
- memSymbolName :: !ByteString
- memSymbolStart :: !(MemSegmentOff w)
- memSymbolSize :: !(MemWord w)
- data SymbolResolutionError
- = EmptySymbolName !Int !ElfSymbolType
- | UndefSymbol !ByteString
- | CouldNotResolveAddr !ByteString
- | MultipleSymbolTables
- data SymbolTable (w :: Nat)
- = NoSymbolTable
- | StaticSymbolTable !(Vector (SymtabEntry ByteString (ElfWordType w)))
- | DynamicSymbolTable !(DynamicSection w) !(VirtAddrMap w) !VersionDefMap !VersionReqMap
- module Data.Macaw.Memory.LoadCommon
- module Data.Macaw.Memory
- module Data.Macaw.Memory.Symbols
Documentation
memoryForElf :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) Source #
Load allocated Elf sections into memory, using the section table information map.
Normally, Elf uses segments for loading, but the section information tends to be more precise.
The return value includes a list of all function symbols (STT_FUNC Symbol table entry types).
Arguments
:: forall (w :: Nat). LoadOptions | |
-> ElfHeaderInfo w | |
-> (SymtabEntry ByteString (ElfWordType w) -> Bool) | Filter on symbol table entries |
-> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) |
Deprecated: Use memoryForElf
memoryForElfAllSymbols :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) Source #
Load allocated Elf sections into memory, using the section table information map.
Normally, Elf uses segments for loading, but the section information tends to be more precise.
The return value includes a list of *all* symbols, whether they are functions or not.
memoryForElfSections :: forall (w :: Nat). ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #
Load allocated Elf sections into memory.
This is only used for object files.
memoryForElfSegments :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #
Load an elf file into memory by parsing segments.
memoryForElfSegments' :: forall (w :: Nat). RegionIndex -> Integer -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #
Load an elf file into memory by parsing segments.
type SectionIndexMap (w :: Nat) = Map Word16 (MemSegmentOff w) Source #
Maps section indices that are loaded in memory to their associated base address and section contents.
The base address is expressed in terms of the underlying memory segment.
data MemLoadWarning Source #
Constructors
SectionNotAlloc !SectionName | |
MultipleSectionsWithName !SectionName | |
MultipleDynamicSegments | |
OverlappingLoadableSegments | |
UnsupportedSection !SectionName | |
UnknownDefinedSymbolBinding !SymbolName ElfSymbolBinding | |
UnknownDefinedSymbolType !SymbolName ElfSymbolType | |
UnknownUndefinedSymbolBinding !SymbolName ElfSymbolBinding | |
UnknownUndefinedSymbolType !SymbolName ElfSymbolType | |
ExpectedSectionSymbolNameEmpty !SymbolName | |
ExpectedSectionSymbolLocal | |
InvalidSectionSymbolIndex !ElfSectionIndex | |
UnsupportedProcessorSpecificSymbolIndex !SymbolName !ElfSectionIndex | |
MultipleRelocationTables | Issued if the file contains multiple relocation tables. |
RelocationParseFailure !String | |
DynamicTagsOutOfRange !ElfDynamicTag !ElfDynamicTag !Word64 !Word64 | The range referenced by the dynamic tags was range. |
DynamicTagPairMismatch !ElfDynamicTag !ElfDynamicTag | We expected either both tags or neither. |
DynamicMultipleTags !ElfDynamicTag | We expected at most a single value of the given tag, but failed multiple. |
AndroidRelWithNonzeroAddend | The |
AndroidRelDecodingError !ElfDynamicTag !AndroidDecodeError | We could not decode the table identified by the given dynamic tag. |
MultipleRelocationsAtAddr !Word64 | Multiple relocations at the given offset |
IgnoreRelocation !RelocationError |
|
ShdrPhdrOverlap | A section header overlaps with a program header. |
Instances
Show MemLoadWarning Source # | |
Defined in Data.Macaw.Memory.ElfLoader Methods showsPrec :: Int -> MemLoadWarning -> ShowS # show :: MemLoadWarning -> String # showList :: [MemLoadWarning] -> ShowS # |
data RelocationError Source #
Instances
Show RelocationError Source # | |
Defined in Data.Macaw.Memory.ElfLoader Methods showsPrec :: Int -> RelocationError -> ShowS # show :: RelocationError -> String # showList :: [RelocationError] -> ShowS # |
type SectionName = ByteString Source #
Arguments
:: forall (w :: Nat). LoadOptions | Options for loading contents |
-> ElfHeaderInfo w | |
-> Either String ([String], Memory w, Maybe (MemSegmentOff w), [MemSymbol w]) |
This interprets the Elf file to construct the initial memory, entry points, and functions symbols.
If it encounters a fatal error it returns the error message in the left value, and otherwise it returns the interpreted information as a 4-tuple of: warnings, the initial memory image, possible entry points (e.g. for an executable or shared library), and function symbols.
elfAddrWidth :: forall (w :: Nat). ElfClass w -> AddrWidthRepr w Source #
Return the addr width repr associated with an elf class
adjustedLoadRegionIndex :: ElfType -> LoadOptions -> RegionIndex Source #
Return default region index to use when loading.
Symbols
data MemSymbol (w :: Nat) Source #
Type for representing a symbol that has a defined location in this memory.
Constructors
MemSymbol | |
Fields
|
Instances
MemWidth w => Show (MemSymbol w) Source # | |
Eq (MemSymbol w) Source # | |
Ord (MemSymbol w) Source # | |
Defined in Data.Macaw.Memory.ElfLoader |
data SymbolResolutionError Source #
Error when resolving symbols.
Constructors
EmptySymbolName !Int !ElfSymbolType | Symbol names must be non-empty |
UndefSymbol !ByteString | Symbol was in the undefined section. |
CouldNotResolveAddr !ByteString | Symbol address could not be resolved. |
MultipleSymbolTables | The elf file contained multiple symbol tables |
Instances
Show SymbolResolutionError Source # | |
Defined in Data.Macaw.Memory.ElfLoader Methods showsPrec :: Int -> SymbolResolutionError -> ShowS # show :: SymbolResolutionError -> String # showList :: [SymbolResolutionError] -> ShowS # |
data SymbolTable (w :: Nat) Source #
This wraps a callback function that lets users lookup symbol information by index from the Elf file.
It is implemented using a callback function as the Elf dynamic section doesn't provide an explicit number of symbol table elements, and we decided not to depend on meta data such as section names that could be stripped from executables/shared objects.
Constructors
NoSymbolTable | |
StaticSymbolTable !(Vector (SymtabEntry ByteString (ElfWordType w))) | |
DynamicSymbolTable !(DynamicSection w) !(VirtAddrMap w) !VersionDefMap !VersionReqMap |
Re-exports
module Data.Macaw.Memory.LoadCommon
module Data.Macaw.Memory
module Data.Macaw.Memory.Symbols