mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-11-24 08:53:12 +03:00
Additional exports from ElfLoader/Discovery.
This commit is contained in:
parent
5272f2152e
commit
bd34bcfc2d
@ -30,6 +30,7 @@ module Data.Macaw.Discovery
|
|||||||
, State.exploredFunctions
|
, State.exploredFunctions
|
||||||
, State.symbolNames
|
, State.symbolNames
|
||||||
, State.ppDiscoveryStateBlocks
|
, State.ppDiscoveryStateBlocks
|
||||||
|
, State.unexploredFunctions
|
||||||
, Data.Macaw.Discovery.cfgFromAddrs
|
, Data.Macaw.Discovery.cfgFromAddrs
|
||||||
, Data.Macaw.Discovery.markAddrsAsFunction
|
, Data.Macaw.Discovery.markAddrsAsFunction
|
||||||
, State.CodeAddrReason(..)
|
, State.CodeAddrReason(..)
|
||||||
@ -46,6 +47,7 @@ module Data.Macaw.Discovery
|
|||||||
, State.emptySymbolAddrMap
|
, State.emptySymbolAddrMap
|
||||||
, State.symbolAddrMap
|
, State.symbolAddrMap
|
||||||
, State.symbolAddrs
|
, State.symbolAddrs
|
||||||
|
, State.symbolAtAddr
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@ -161,8 +163,13 @@ rewriteTermStmt tstmt = do
|
|||||||
case tstmt of
|
case tstmt of
|
||||||
FetchAndExecute regs ->
|
FetchAndExecute regs ->
|
||||||
FetchAndExecute <$> traverseF rewriteValue regs
|
FetchAndExecute <$> traverseF rewriteValue regs
|
||||||
Branch c t f ->
|
Branch c t f -> do
|
||||||
Branch <$> rewriteValue c <*> pure t <*> pure f
|
tgtCond <- rewriteValue c
|
||||||
|
case () of
|
||||||
|
_ | Just (NotApp c) <- valueAsApp tgtCond -> do
|
||||||
|
Branch c <$> pure f <*> pure t
|
||||||
|
| otherwise ->
|
||||||
|
Branch tgtCond <$> pure t <*> pure f
|
||||||
Syscall regs ->
|
Syscall regs ->
|
||||||
Syscall <$> traverseF rewriteValue regs
|
Syscall <$> traverseF rewriteValue regs
|
||||||
TranslateError regs msg ->
|
TranslateError regs msg ->
|
||||||
@ -913,7 +920,6 @@ analyzeFunction addr rsn s = do
|
|||||||
-- analyzed all function entry points.
|
-- analyzed all function entry points.
|
||||||
analyzeDiscoveredFunctions :: DiscoveryState arch -> DiscoveryState arch
|
analyzeDiscoveredFunctions :: DiscoveryState arch -> DiscoveryState arch
|
||||||
analyzeDiscoveredFunctions info =
|
analyzeDiscoveredFunctions info =
|
||||||
-- If local block frontier is empty, then try function frontier.
|
|
||||||
case Map.lookupMin (info^.unexploredFunctions) of
|
case Map.lookupMin (info^.unexploredFunctions) of
|
||||||
Nothing -> info
|
Nothing -> info
|
||||||
Just (addr, rsn) ->
|
Just (addr, rsn) ->
|
||||||
|
@ -24,6 +24,7 @@ module Data.Macaw.Memory.ElfLoader
|
|||||||
-- * Symbol resolution utilities
|
-- * Symbol resolution utilities
|
||||||
, resolvedSegmentedElfFuncSymbols
|
, resolvedSegmentedElfFuncSymbols
|
||||||
, ppElfUnresolvedSymbols
|
, ppElfUnresolvedSymbols
|
||||||
|
, elfAddrWidth
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@ -53,6 +54,11 @@ import qualified Data.Macaw.Memory.Permissions as Perm
|
|||||||
sliceL :: Integral w => Range w -> L.ByteString -> L.ByteString
|
sliceL :: Integral w => Range w -> L.ByteString -> L.ByteString
|
||||||
sliceL (i,c) = L.take (fromIntegral c) . L.drop (fromIntegral i)
|
sliceL (i,c) = L.take (fromIntegral c) . L.drop (fromIntegral i)
|
||||||
|
|
||||||
|
-- | Return the addr width repr associated with an elf class
|
||||||
|
elfAddrWidth :: ElfClass w -> AddrWidthRepr w
|
||||||
|
elfAddrWidth ELFCLASS32 = Addr32
|
||||||
|
elfAddrWidth ELFCLASS64 = Addr64
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
-- SectionIndexMap
|
-- SectionIndexMap
|
||||||
|
|
||||||
@ -307,6 +313,10 @@ relocMapOfDynamic d cl mach virtMap dynContents =
|
|||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
-- Elf segment loading
|
-- Elf segment loading
|
||||||
|
|
||||||
|
reprConstraints :: AddrWidthRepr w -> ((Bits (ElfWordType w), Integral (ElfWordType w), MemWidth w) => a) -> a
|
||||||
|
reprConstraints Addr32 x = x
|
||||||
|
reprConstraints Addr64 x = x
|
||||||
|
|
||||||
-- | Load an elf file into memory.
|
-- | Load an elf file into memory.
|
||||||
insertElfSegment :: LoadOptions
|
insertElfSegment :: LoadOptions
|
||||||
-> ElfFileSectionMap (ElfWordType w)
|
-> ElfFileSectionMap (ElfWordType w)
|
||||||
@ -337,16 +347,6 @@ insertElfSegment opt shdrMap contents relocMap phdr = do
|
|||||||
mlsIndexMap %= Map.insert elfIdx (addr, sec)
|
mlsIndexMap %= Map.insert elfIdx (addr, sec)
|
||||||
_ -> fail "Unexpected shdr interval"
|
_ -> fail "Unexpected shdr interval"
|
||||||
|
|
||||||
|
|
||||||
elfAddrWidth :: ElfClass w -> AddrWidthRepr w
|
|
||||||
elfAddrWidth ELFCLASS32 = Addr32
|
|
||||||
elfAddrWidth ELFCLASS64 = Addr64
|
|
||||||
|
|
||||||
reprConstraints :: AddrWidthRepr w -> ((Bits (ElfWordType w), Integral (ElfWordType w), MemWidth w) => a) -> a
|
|
||||||
reprConstraints Addr32 x = x
|
|
||||||
reprConstraints Addr64 x = x
|
|
||||||
|
|
||||||
|
|
||||||
-- | Load an elf file into memory. This uses the Elf segments for loading.
|
-- | Load an elf file into memory. This uses the Elf segments for loading.
|
||||||
memoryForElfSegments
|
memoryForElfSegments
|
||||||
:: forall w
|
:: forall w
|
||||||
|
Loading…
Reference in New Issue
Block a user