Skip to content

Commit

Permalink
more WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptival committed Jul 25, 2024
1 parent 4dac368 commit 18cb04b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
26 changes: 21 additions & 5 deletions src/Reopt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ import Reopt.X86 (
)
import Debug.Trace (traceM, trace)
import qualified Data.List as List
import Data.Parameterized (type (:~:)(Refl), testEquality)
import Data.Parameterized (type (:~:)(Refl), testEquality, viewSome)
import qualified Data.Macaw.Analysis.RegisterUse as Macaw

copyrightNotice :: String
copyrightNotice = "Copyright 2014-21 Galois, Inc."
Expand Down Expand Up @@ -2326,16 +2327,31 @@ reoptResolveCallArgsFn mem resolveFunName resolveFunType callSite callRegs = do
case asSegmentOff mem addr of
Just off -> do
traceM $ "off is: " <> show off
<> show (List.lookup addr (Macaw.relativeSegmentContents [segoffSegment off]))
traceM $ show (List.lookup addr (Macaw.relativeSegmentContents [segoffSegment off]))
case List.lookup addr (Macaw.relativeSegmentContents [segoffSegment off]) of
Just (Macaw.RelocationRegion r) -> do
case Macaw.relocationSym r of
Macaw.SymbolRelocation nm _version -> do
traceM $ BSC.unpack nm
traceM $ show $ resolveFunType nm
case x86TranslateCallType mem nm callRegs (fromMaybe (error "sad") (resolveFunType nm)) of
Right rr -> Right (callArgValues rr)
Left _ -> giveUp
Right rr -> do
traceM "x86TranslateCallType success: "
let showCValue :: forall arch tp. Macaw.CValue arch tp -> String
showCValue s = case s of
Macaw.RelocatableCValue _ addr' -> ("Relocatable " :: String) <> show addr'
_ -> "Something else"
let showValue s = case s of
Macaw.CValue cv -> showCValue cv
Macaw.AssignedValue{} -> "AssignedValue"
Macaw.Initial{} -> "Initial"
forM_ (callArgValues rr) $ \ s -> do
traceM $ viewSome showValue s
-- TODO: Try to add any address found above to the exploration frontier
Right (callArgValues rr)
Left reason -> do
traceM $ "x86TranslateCallType failure" <> Macaw.ppRegisterUseErrorReason reason
giveUp
_ ->
trace ("relocationSym failed for " <> show off)
giveUp
Expand Down Expand Up @@ -2368,7 +2384,7 @@ x86ArgumentAnalysis sysp resolveFunName funTypeMap funTypeMap' discState = do
traceM "The funtype we resolve from is:"
forM_ (Map.assocs funTypeMap) $ \ (k, v) -> do
traceM $ "Entry " <> show k <> "" <> show v
traceM $ "Number of entries: " <> (show $ length $ Map.assocs funTypeMap)
traceM $ "Number of entries: " <> show (length $ Map.assocs funTypeMap)

-- let resolveFunType fnm = snd <$> Map.lookup fnm funTypeMap
let resolveFunType fnm = Map.lookup fnm funTypeMap'
Expand Down
4 changes: 2 additions & 2 deletions src/Reopt/CFG/Recovery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,8 @@ x86CallRegs mem funNameMap funTypeMap _callSite regs = do
AssignedValue{} ->
Left $ Reason IndirectCallTarget ()
_ ->
Left $ Reason IndirectCallTarget () -- FIXME: this is not why but I don't want error
-- error $ "x86CallRegs, consider: " <> show ipVal
-- Left $ Reason IndirectCallTarget () -- FIXME: this is not why but I don't want error
error $ "x86CallRegs, consider: " <> show ipVal
case funTypeMap nm of
Just tp -> x86TranslateCallType mem nm regs tp
Nothing -> Left $ Reason UnknownCallTargetArguments nm
Expand Down

0 comments on commit 18cb04b

Please sign in to comment.