still wtf
[mate.git] / Main.hs
1 {-# LANGUAGE ForeignFunctionInterface #-}
2 module Main where
3
4 import Data.Word
5 import Text.Printf
6 import Foreign
7
8 foreign import ccall "dynamic"
9    code_void :: FunPtr (IO ()) -> (IO ())
10
11 main :: IO ()
12 main = do
13   entryPtr <- (mallocBytes 2)
14   poke entryPtr (0xc390 :: Word16) -- nop (0x90); ret(0xc3) (little endian order)
15
16   _ <- printf "entry point: 0x%08x\n" ((fromIntegral $ ptrToIntPtr entryPtr) :: Int)
17   code_void $ castPtrToFunPtr entryPtr
18   putStrLn "welcome back"