Created
December 16, 2019 14:37
-
-
Save yasar11732/d2c5e0a583bd68ed4b0eb6dfed8f4016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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