Last active
February 22, 2018 10:56
-
-
Save chpatrick/27aaef49fcc23541527c6e0bfa93a63d to your computer and use it in GitHub Desktop.
Haskell virus scanner
This file contains hidden or 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
import qualified Data.ByteString as BS | |
import qualified Data.ByteString.Char8 as BSC | |
import System.Process.ByteString | |
import System.Exit | |
data VirusScanResult | |
= VSRClean | |
| VSRVirusFound BS.ByteString | |
deriving (Eq, Ord, Show) | |
virusScan :: BS.ByteString -> IO VirusScanResult | |
virusScan testData = do | |
( exitCode, stdout, stderr ) <- readProcessWithExitCode "clamscan" ["-"] testData | |
-- see "man clamscan" | |
case exitCode of | |
ExitSuccess -> return VSRClean | |
ExitFailure 1 -> return (VSRVirusFound stdout) | |
ExitFailure _ -> fail ("Virus scan failed: " ++ BSC.unpack stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment