-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release current work as required by license
Credit to Ben Rudiak-Gould for the original version.
- Loading branch information
1 parent
45a7f30
commit dabfdd0
Showing
15 changed files
with
1,973 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Mrifk should build on any platform which supports GHC 6.2 (i.e. Win32 or | ||
Posix). GHC versions prior to 6.2 will almost work, except that showHex | ||
will prepend "0x" to hexadecimal numbers, which uglifies the output a bit. | ||
|
||
On UNIX platforms you'll probably want to delete the ".exe" from the first | ||
line of the Makefile. | ||
|
||
The code is licensed under the GPL, and is Copyright 2004 Ben Rudiak-Gould. | ||
You can contact me at [email protected]. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
EXE = .exe | ||
HFLAGS = -v -O | ||
|
||
all : mrifk$(EXE) | ||
|
||
mrifk$(EXE) : Mrifk*.hs | ||
ghc --make -XParallelListComp -o $@ ${HFLAGS} Mrifk.hs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{- | ||
Mrifk, a decompiler for Glulx story files. | ||
Copyright 2004 Ben Rudiak-Gould. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You can read the GNU General Public License at this URL: | ||
http://www.gnu.org/copyleft/gpl.html | ||
-} | ||
|
||
|
||
module Main ( | ||
main | ||
) where | ||
|
||
|
||
import Mrifk_cmdline | ||
import Mrifk_storyfile | ||
import Mrifk_disasm | ||
import Mrifk_decompile | ||
import Mrifk_strings | ||
import Mrifk_memmap | ||
import Mrifk_grammar | ||
import Mrifk_objects | ||
import Mrifk_print | ||
|
||
import Control.Monad.State (evalState) | ||
import Data.Array | ||
import Data.Tree | ||
import Data.Maybe (fromJust) | ||
import Numeric (showHex) | ||
|
||
|
||
mrifkRelease = "1-patched-v2" | ||
mrifkSerial = "160321" | ||
|
||
|
||
main = | ||
do putStrLn ("! \""++storyFileName++"\"") | ||
putStrLn ("! Decompiled by Mrifk release "++mrifkRelease++", serial "++mrifkSerial) | ||
-- putStrLn "\n! Dictionary\n" | ||
-- mapM_ print (elems dictionary) | ||
putStrLn "\n! Grammar" | ||
mapM_ putStrLn (ppVerbs verbs) | ||
putStrLn "\n! Object tree\n" | ||
mapM_ putStrLn (concatMap ppObjectTree objectForest) | ||
putStrLn "\n! Routines" | ||
mapM_ putStrLn ppRoutines | ||
putStrLn "\n! Strings\n" | ||
mapM_ putStrLn ppStrings | ||
|
||
|
||
routines = map (onFth4 maybeDecompile) $ evalState disasmRoutines informCode | ||
|
||
maybeDecompile | disassembleOnly = updateLabels | ||
| otherwise = decompile | ||
|
||
onFth4 f (a,b,c,d) = (a,b,c,f d) | ||
|
||
|
||
ppRoutines = concatMap ppRoutine routines | ||
|
||
ppStrings = map ppString strings | ||
|
||
ppString (addr,str) = "! 0x" ++ showHex addr (' ' : ppQuotedString str) | ||
|
||
|
||
ppObjectTree = ppObjectTree' 0 | ||
|
||
ppObjectTree' depth (Node obj children) = | ||
ppObject depth obj (fromJust (lookup obj objects)) | ||
++ concatMap (ppObjectTree' (depth+1)) children |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{- | ||
Mrifk, a decompiler for Glulx story files. | ||
Copyright 2004 Ben Rudiak-Gould. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You can read the GNU General Public License at this URL: | ||
http://www.gnu.org/copyleft/gpl.html | ||
-} | ||
|
||
|
||
module Mrifk_cmdline ( | ||
storyFileName, disassembleOnly | ||
) where | ||
|
||
|
||
import System.Environment (getArgs) | ||
import System.Exit (exitFailure) | ||
import System.IO (hPutStrLn,stderr) | ||
import System.IO.Unsafe (unsafePerformIO) | ||
|
||
|
||
storyFileName :: String | ||
disassembleOnly :: Bool | ||
|
||
(storyFileName,disassembleOnly) = unsafePerformIO parseArgs | ||
|
||
|
||
parseArgs = | ||
do args <- getArgs | ||
case args of | ||
[story] -> return (story,False) | ||
["-S",story] -> return (story,True) | ||
_ -> usage | ||
|
||
|
||
usage = | ||
do hPutStrLn stderr "usage: mrifk [-S] storyfile.ulx" | ||
hPutStrLn stderr " -S disassemble only (omit decompilation pass)" | ||
exitFailure |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{- | ||
Mrifk, a decompiler for Glulx story files. | ||
Copyright 2004 Ben Rudiak-Gould. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You can read the GNU General Public License at this URL: | ||
http://www.gnu.org/copyleft/gpl.html | ||
-} | ||
|
||
|
||
module Mrifk_code ( | ||
Statement(..), LabelType(..), Expr(..), Opcode(..), BinaryOp (..), | ||
binopEQ, binopNE, binopLT, binopGT, binopLE, binopGE, | ||
binopHas, binopOr, binopAnd, | ||
binopName, binopPrec | ||
) where | ||
|
||
|
||
data Statement = | ||
Push Expr | Eval String Expr | | ||
Print String Expr | NewLine | | ||
IfThenElse Expr [Statement] [Statement] | | ||
Label Int LabelType | JCond Expr Int | Jump Int | | ||
Give Expr Bool Int | | ||
GInstr (String,Int,Int,Int,Opcode) [Expr] | ||
deriving (Show,Eq) | ||
|
||
data LabelType = Single | Multi | Phantom deriving (Show,Eq) | ||
|
||
data Expr = | ||
SP | Imm Int | ImmString Int | Mem Int | Local Int | | ||
Unary String Int Expr | PostIncDec Expr String | | ||
Binary Expr BinaryOp Expr | | ||
Assign Expr Expr | Call Expr [Expr] | | ||
SpecialName String | ||
deriving (Show,Eq) | ||
|
||
data Opcode = | ||
OCopy | OJCond BinaryOp | OJump | OCall | OCallI | OReturn | | ||
OALoadBit | OAStore | OAStoreB | OAStoreBit | | ||
OStreamChar | OStreamNum | OStreamStr | | ||
OBinary BinaryOp | OGlk | OStkSwap | OSpecial | ||
deriving (Show,Eq) | ||
|
||
|
||
data BinaryOp = | ||
NormalOp String Int | PredicateOp String String | LogicalOp String String deriving (Show,Eq) | ||
|
||
|
||
binopEQ = PredicateOp " == " " ~= " | ||
binopNE = PredicateOp " ~= " " == " | ||
binopLT = PredicateOp " < " " >= " | ||
binopGT = PredicateOp " > " " <= " | ||
binopLE = PredicateOp " <= " " > " | ||
binopGE = PredicateOp " >= " " < " | ||
binopHas = PredicateOp " has " " hasnt " | ||
binopOr = LogicalOp " || " " && " | ||
binopAnd = LogicalOp " && " " || " | ||
|
||
binopName (PredicateOp s _) = s | ||
binopName (LogicalOp s _) = s | ||
binopName (NormalOp s _) = s | ||
|
||
binopPrec (PredicateOp _ _) = 3 | ||
binopPrec (LogicalOp _ _) = 2 | ||
binopPrec (NormalOp _ p) = p |
Oops, something went wrong.