Truly random idents to foil #haskell games

This commit is contained in:
dons 2006-04-30 02:01:14 +00:00
parent 493be17566
commit 2ba550faa1
2 changed files with 23 additions and 5 deletions

8
TODO
View File

@ -1,6 +1,14 @@
For 1.0
----------
+ broken on mac.
symbols with suspiciously many _ chars
+ Add verbose versions of the load functions, to avoid -DDEBUG
+ mention that you need .o archives, not .a ones. Use Cabal, ghc-pkg -u
or ld -r --whole-archive
+ hs-plugins doesn't know to look for packages in the user packages,
only in the global packages

View File

@ -53,9 +53,12 @@ import AltData.Typeable ( Typeable )
import Data.Either
import Data.Map as Map
import Data.Char
import System.IO
import System.Directory
import System.Random
import System.IO.Unsafe
-- import Foreign.C
-- import Foreign
@ -158,7 +161,7 @@ unsafeEval src mods = do
tmpf <- mkUniqueWith wrap src mods
status <- make tmpf []
m_rsrc <- case status of
MakeSuccess _ obj -> do
MakeSuccess _ obj -> do
m_v <- load obj [pwd] [] symbol
case m_v of LoadFailure _ -> return Nothing
LoadSuccess _ rsrc -> return $ Just rsrc
@ -235,8 +238,13 @@ dynwrap expr nm mods =
"module "++nm++ "( resource ) where\n" ++
concatMap (\m-> "import "++m++"\n") mods ++
"import AltData.Dynamic\n" ++
"resource = let { yhjulwwiefzojcbxybbruweejw = \n" ++
"{-# LINE 1 \"<eval>\" #-}\n" ++ expr ++ ";} in toDyn yhjulwwiefzojcbxybbruweejw"
"resource = let { "++x++" = \n" ++
"{-# LINE 1 \"<eval>\" #-}\n" ++ expr ++ ";} in toDyn "++x
where
x = ident ()
ident () = unsafePerformIO $
sequence (take 3 (repeat $ getStdRandom (randomR (97,122)) >>= return . chr))
-- ---------------------------------------------------------------------
-- unsafe wrapper
@ -245,8 +253,10 @@ wrap :: String -> String -> [Import] -> String
wrap expr nm mods =
"module "++nm++ "( resource ) where\n" ++
concatMap (\m-> "import "++m++"\n") mods ++
"resource = let { yhjulwwiefzojcbxybbruweejw = \n" ++
"{-# LINE 1 \"<Plugins.Eval>\" #-}\n" ++ expr ++ ";} in yhjulwwiefzojcbxybbruweejw"
"resource = let { "++x++" = \n" ++
"{-# LINE 1 \"<Plugins.Eval>\" #-}\n" ++ expr ++ ";} in "++x
where
x = ident ()
-- what is this big variable name?
-- its a random value, so that it won't clash if the accidently mistype