Skip to content

Instantly share code, notes, and snippets.

@yasar11732
Created December 16, 2019 14:37
Show Gist options
  • Save yasar11732/d2c5e0a583bd68ed4b0eb6dfed8f4016 to your computer and use it in GitHub Desktop.
Save yasar11732/d2c5e0a583bd68ed4b0eb6dfed8f4016 to your computer and use it in GitHub Desktop.
module ExeMagic where
import qualified Data.ByteString.Lazy as L
hasExeMagic :: L.ByteString -> Bool
hasExeMagic content = L.take 2 content == exeMagic
where exeMagic = L.pack [0x4D, 0x5A]
isExeFile :: FilePath -> IO Bool
isExeFile path = do
content <- L.readFile path
return (hasExeMagic content)
module Main (main) where
import System.Environment (getArgs)
import ExeMagic (isExeFile)
main = do
args <- getArgs
case args of
[inputFile] -> do
result <- isExeFile inputFile
print result
_ -> print "You must pass 1 command line argument"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment