still wtf
[mate.git] / Main.hs
diff --git a/Main.hs b/Main.hs
new file mode 100644 (file)
index 0000000..44669ac
--- /dev/null
+++ b/Main.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+module Main where
+
+import Data.Word
+import Text.Printf
+import Foreign
+
+foreign import ccall "dynamic"
+   code_void :: FunPtr (IO ()) -> (IO ())
+
+main :: IO ()
+main = do
+  entryPtr <- (mallocBytes 2)
+  poke entryPtr (0xc390 :: Word16) -- nop (0x90); ret(0xc3) (little endian order)
+
+  _ <- printf "entry point: 0x%08x\n" ((fromIntegral $ ptrToIntPtr entryPtr) :: Int)
+  code_void $ castPtrToFunPtr entryPtr
+  putStrLn "welcome back"