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.symbolNames
|
||||
, State.ppDiscoveryStateBlocks
|
||||
, State.unexploredFunctions
|
||||
, Data.Macaw.Discovery.cfgFromAddrs
|
||||
, Data.Macaw.Discovery.markAddrsAsFunction
|
||||
, State.CodeAddrReason(..)
|
||||
@ -46,6 +47,7 @@ module Data.Macaw.Discovery
|
||||
, State.emptySymbolAddrMap
|
||||
, State.symbolAddrMap
|
||||
, State.symbolAddrs
|
||||
, State.symbolAtAddr
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
@ -161,8 +163,13 @@ rewriteTermStmt tstmt = do
|
||||
case tstmt of
|
||||
FetchAndExecute regs ->
|
||||
FetchAndExecute <$> traverseF rewriteValue regs
|
||||
Branch c t f ->
|
||||
Branch <$> rewriteValue c <*> pure t <*> pure f
|
||||
Branch c t f -> do
|
||||
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 <$> traverseF rewriteValue regs
|
||||
TranslateError regs msg ->
|
||||
@ -913,7 +920,6 @@ analyzeFunction addr rsn s = do
|
||||
-- analyzed all function entry points.
|
||||
analyzeDiscoveredFunctions :: DiscoveryState arch -> DiscoveryState arch
|
||||
analyzeDiscoveredFunctions info =
|
||||
-- If local block frontier is empty, then try function frontier.
|
||||
case Map.lookupMin (info^.unexploredFunctions) of
|
||||
Nothing -> info
|
||||
Just (addr, rsn) ->
|
||||
|
@ -24,6 +24,7 @@ module Data.Macaw.Memory.ElfLoader
|
||||
-- * Symbol resolution utilities
|
||||
, resolvedSegmentedElfFuncSymbols
|
||||
, ppElfUnresolvedSymbols
|
||||
, elfAddrWidth
|
||||
) where
|
||||
|
||||
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 (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
|
||||
|
||||
@ -307,6 +313,10 @@ relocMapOfDynamic d cl mach virtMap dynContents =
|
||||
------------------------------------------------------------------------
|
||||
-- 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.
|
||||
insertElfSegment :: LoadOptions
|
||||
-> ElfFileSectionMap (ElfWordType w)
|
||||
@ -337,16 +347,6 @@ insertElfSegment opt shdrMap contents relocMap phdr = do
|
||||
mlsIndexMap %= Map.insert elfIdx (addr, sec)
|
||||
_ -> 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.
|
||||
memoryForElfSegments
|
||||
:: forall w
|
||||
|
Loading…
Reference in New Issue
Block a user