Skip to content

Commit

Permalink
Merge pull request #304 from GaloisInc/vr/details-on-finding-addrs
Browse files Browse the repository at this point in the history
make info output of type-based code discovery more explicit
  • Loading branch information
Ptival authored Feb 22, 2024
2 parents f1443f8 + de0ce05 commit 492b35a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/Reopt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2603,12 +2603,8 @@ checkNoSymbolUsesReservedPrefix unnamedFunPrefix symAddrMap = do
"No symbol in the binary may start with the prefix %d."
(BSC.unpack unnamedFunPrefix)

-- | Checks whether a given `FnStmt` has a potential code pointer address we
-- want to try and investigate. We intended for such addresses to be identified
-- via type reconstruction, but it turns out that we can just get away with
-- identifying code-pointer-sized values pointing into an executable segment.
-- However, we could double-check with the results of type reconstruction to
-- potentially avoid some spurious pointers.
-- | Checks whether a given `FnStmt` has a potential code pointer address we want to try and
-- investigate.
fnStmtHasCandidate ::
forall arch r.
FnArchConstraints arch =>
Expand All @@ -2622,14 +2618,32 @@ fnStmtHasCandidate ::
fnStmtHasCandidate modConstraints fun (FnCall fn args _mRet) = do
let ty = runGetInferredType (fnName fun) modConstraints (Proxy @arch) fn
let
keepIfPromising :: (Some (FnValue arch), FTy) -> ReoptM arch r [Macaw.ArchSegmentOff arch]
keepIfPromising (Some (FnCodePointer addr), FFunPtrTy{}) = return [addr]
keepIfPromising (Some (FnCodePointer addr), FPreFunPtrTy{}) = return [addr]
keepIfPromising (Some (FnCodePointer addr), FUnknownFunPtrTy{}) = return [addr]
keepIfPromising pair = do

infoKeeping :: ArchSegmentOff arch -> ReoptM arch r ()
infoKeeping addr =
globalStepInfo Events.DebugTypeInference -- FIXME: may need new global steps
("Keeping " <> show addr <> " as promising in " <> BSC.unpack (fnName fun))
infoNotKeepingAddr :: ArchSegmentOff arch -> FTy -> ReoptM arch r ()
infoNotKeepingAddr addr aty =
globalStepInfo Events.DebugTypeInference -- FIXME: may need new global steps
("Not keeping " <> show addr <> " as promising in " <> BSC.unpack (fnName fun)
<> " because of its type " <> show aty)
infoNotKeepingOther :: (Some (FnValue arch), FTy) -> ReoptM arch r ()
infoNotKeepingOther other =
globalStepInfo Events.DebugTypeInference -- FIXME: may need new global steps
("Not keeping " <> show pair <> " as promising") -- only while debugging
return []
("Not keeping " <> show other <> " as promising in " <> BSC.unpack (fnName fun)
<> " because it does not explicitly contain an address")

keepIfPromising :: (Some (FnValue arch), FTy) -> ReoptM arch r [Macaw.ArchSegmentOff arch]
keepIfPromising (Some (FnCodePointer addr), FFunPtrTy{}) =
infoKeeping addr >> return [addr]
keepIfPromising (Some (FnCodePointer addr), FPreFunPtrTy{}) =
infoKeeping addr >> return [addr]
keepIfPromising (Some (FnCodePointer addr), FUnknownFunPtrTy{}) =
infoKeeping addr >> return [addr]
keepIfPromising (Some (FnCodePointer addr), aty) = infoNotKeepingAddr addr aty >> return []
keepIfPromising pair = infoNotKeepingOther pair >> return []

case ty of
Just (FFunPtrTy argsTy _retTy) ->
if length args /= length argsTy
Expand Down
1 change: 1 addition & 0 deletions src/Reopt/CFG/FnRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ type FnArchConstraints arch =
, Macaw.MemWidth (ArchAddrWidth arch)
, HasRepr (ArchFn arch (FnValue arch)) TypeRepr
, HasRepr (ArchReg arch) TypeRepr
, ShowF (ArchReg arch)
)

instance Macaw.MemWidth (ArchAddrWidth arch) => PP.Pretty (FnValue arch tp) where
Expand Down

0 comments on commit 492b35a

Please sign in to comment.