mirror of
https://github.com/GaloisInc/macaw.git
synced 2024-12-25 23:23:18 +03:00
Implement 'identifyCall' for PowerPC
The current heuristic isn't great, but is probably okay for now. It just checks to see if the LNK register is an address plus four. Something more precise would require knowing the address of the next instruction, but we can't get that from the IP, which has already been changed due to the call.
This commit is contained in:
parent
a648a4c50b
commit
65bc1231fb
@ -5,27 +5,35 @@ module Data.Macaw.PPC.Identify (
|
||||
identifyReturn
|
||||
) where
|
||||
|
||||
import Control.Lens ( (^.) )
|
||||
import qualified Data.Sequence as Seq
|
||||
|
||||
import qualified Data.Macaw.CFG as MC
|
||||
import qualified Data.Macaw.Memory as MM
|
||||
|
||||
import Data.Macaw.PPC.PPCReg
|
||||
import Data.Macaw.PPC.Arch
|
||||
import Data.Macaw.PPC.PPCReg
|
||||
import Data.Macaw.PPC.Simplify ( simplifyValue )
|
||||
|
||||
import Debug.Trace (trace)
|
||||
import Data.List (intercalate)
|
||||
import Debug.Trace (trace)
|
||||
|
||||
identifyCall :: MC.ArchConstraints ppc
|
||||
|
||||
identifyCall :: (PPCArchConstraints ppc)
|
||||
=> proxy ppc
|
||||
-> MM.Memory (MC.ArchAddrWidth ppc)
|
||||
-> [MC.Stmt ppc ids]
|
||||
-> MC.RegState (MC.ArchReg ppc) (MC.Value ppc ids)
|
||||
-> Maybe (Seq.Seq (MC.Stmt ppc ids), MC.ArchSegmentOff ppc)
|
||||
identifyCall _ mem stmts rs = trace ("identifyCall:\n\n" ++
|
||||
intercalate "\n" (map show stmts)) $
|
||||
trace ("reg state = " ++ show rs) $
|
||||
Nothing
|
||||
identifyCall _ mem stmts0 rs
|
||||
| trace ("Identify call: " ++ unlines (map show stmts0)) False = undefined
|
||||
| not (null stmts0)
|
||||
, MC.AssignedValue (MC.Assignment { MC.assignRhs = MC.EvalApp app }) <- rs ^. MC.boundValue PPC_LNK
|
||||
, MC.BVAdd _ (MC.RelocatableValue {}) (MC.BVValue _ 0x4) <- app
|
||||
, Just retVal <- simplifyValue (rs ^. MC.boundValue PPC_LNK)
|
||||
, Just retAddrVal <- MC.asLiteralAddr retVal
|
||||
, Just retAddr <- MM.asSegmentOff mem retAddrVal =
|
||||
Just (Seq.fromList stmts0, retAddr)
|
||||
| otherwise = Nothing
|
||||
|
||||
identifyReturn :: (PPCArchConstraints ppc)
|
||||
=> proxy ppc
|
||||
|
Loading…
Reference in New Issue
Block a user