module Main where
import System.Environment(getArgs)
import qualified Data.ByteString as B (readFile, writeFile, map)
main = do
args <- getArgs
case args of
[from, out, direction] ->
case direction of
"exe2txt" -> do
s <- B.readFile from
let s1 = B.map (/x->x+1) s
B.writeFile out s1
"txt2exe" -> do
s <- B.readFile from
let s1 = B.map (/x->x-1) s
B.writeFile out s1
otherwise -> do
Prelude.putStrLn "usage: hs20101004-1.exe from out direction"
otherwise ->
Prelude.putStrLn "usage: hs20101004-1.exe from out direction"
本文介绍了一个使用Haskell编写的简单工具,该工具能够读取一个二进制文件,并根据指定的方向参数对文件内容进行逐字节加1或减1的操作,最后将处理后的结果保存到另一个文件中。此工具通过命令行参数接受输入文件名、输出文件名及转换方向。

2883

被折叠的 条评论
为什么被折叠?



