Skip to content

Instantly share code, notes, and snippets.

@lucasdicioccio
Created June 5, 2021 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasdicioccio/ee7dac94f1cd61cd97acc6b9a1c89eb7 to your computer and use it in GitHub Desktop.
Save lucasdicioccio/ee7dac94f1cd61cd97acc6b9a1c89eb7 to your computer and use it in GitHub Desktop.
a Haskell script to detect garbled files on a shitty SD

Compile then run

$ ghc --make -O2 suspicious.hs
$ find . -name "IMG_*" -exec './suspicious' '{}' \; > suspicious-list

Excerpt of the output in suspicious-list:

./IMG_1269.JPG ok
./IMG_2107.CR3 ok
./IMG_2280.JPG suspicious
./IMG_1140.CR3 ok
./IMG_1357.CR3 ok
./IMG_2168.JPG ok
./IMG_1445.CR3 ok
./IMG_2051.JPG ok
./IMG_1604.CR3 ok
./IMG_1315.JPG ok
module Main where
import System.Environment
import qualified Data.ByteString.Char8 as ByteString
main :: IO ()
main = do
path:_ <- getArgs
dat <- ByteString.take 100 <$> ByteString.readFile path
if ByteString.all (=='\NUL') dat
then putStrLn $ path <> " suspicious"
else putStrLn $ path <> " ok"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment