import Data.List
import qualified Data.Map as M
import qualified Data.ByteString.Lazy as B
+import Data.Maybe
import JVM.ClassFile
import JVM.Converter
parseMethod :: Class Direct -> B.ByteString -> MethodSignature -> IO RawMethod
parseMethod cls methodname sig = do
- let method = case lookupMethodSig methodname sig cls of
- Just m -> m
- Nothing -> error $ "method " ++ (show . toString) methodname ++ " not found"
- let codeseg = case attrByName method "Code" of
- Just m -> m
- Nothing -> error $ "codeseg " ++ (show . toString) methodname ++ " not found"
+ let method = fromMaybe
+ (error $ "method " ++ (show . toString) methodname ++ " not found")
+ (lookupMethodSig methodname sig cls)
+ let codeseg = fromMaybe
+ (error $ "codeseg " ++ (show . toString) methodname ++ " not found")
+ (attrByName method "Code")
let decoded = decodeMethod codeseg
let mapbb = testCFG decoded
let locals = fromIntegral (codeMaxLocals decoded)
-- place a nop at the end, therefore the disasm doesn't screw up
emit32 (0xffff9090 :: Word32) >> emit8 (0x90 :: Word8)
-- discard arguments on stack
- let argcnt = ((if hasThis then 1 else 0) + (methodGetArgsCount $ methodNameTypeByIdx cls cpidx)) * ptrSize
+ let argcnt = ((if hasThis then 1 else 0) + methodGetArgsCount (methodNameTypeByIdx cls cpidx)) * ptrSize
when (argcnt > 0) (add esp argcnt)
-- push result on stack if method has a return value
when (methodHaveReturnValue cls cpidx) (push eax)
calladdr <- getCurrentOffset
call (Disp offset, eax)
-- discard arguments on stack (`+1' for "this")
- let argcnt = ptrSize * (1 + (methodGetArgsCount $ methodNameTypeByIdx cls cpidx))
+ let argcnt = ptrSize * (1 + methodGetArgsCount (methodNameTypeByIdx cls cpidx))
when (argcnt > 0) (add esp argcnt)
-- push result on stack if method has a return value
when (methodHaveReturnValue cls cpidx) (push eax)