{-# LANGUAGE PartialTypeSignatures , FlexibleContexts, Strict, DeriveGeneric#-}
{-# OPTIONS_HADDOCK prune #-}
module Data.JSON_Taxonomy where
import Base
import Data.SValue
import Data.SymbolicExpression
import Generic.Binary
import Generic.SymbolicConstituents
import Analysis.Context
import qualified Generic.Address as GA
import qualified Generic.Operand as GO
import qualified Generic.Instruction as GI
import qualified X86.Instruction as X86
import X86.Opcode
import X86.Prefix
import X86.Register
import Generic.HasSize (HasSize(sizeof))
import qualified Data.Map as M
import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.Set as S
import qualified Data.Set.NonEmpty as NES
import Data.Maybe (fromJust,catMaybes,mapMaybe)
import Data.List
import Data.Foldable
import Data.Word
import Data.Aeson
import GHC.Generics
data JSON = JSON {
JSON -> [Instruction]
instructions :: [Instruction],
JSON -> ControlFlow
control_flow :: ControlFlow,
JSON -> [(Word64, FunctionBoundary)]
function_boundaries :: [(Word64,FunctionBoundary)],
JSON -> [(Word64, FunctionSummary)]
function_summaries :: [(Word64,FunctionSummary)],
JSON -> [(Word64, [Invariant])]
invariants :: [(Word64,[Invariant])],
JSON -> [(Word64, Word64, [Maybe SValue])]
pointer_domains :: [(Word64, Word64,[Maybe SValue])]
}
deriving (forall x. JSON -> Rep JSON x)
-> (forall x. Rep JSON x -> JSON) -> Generic JSON
forall x. Rep JSON x -> JSON
forall x. JSON -> Rep JSON x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JSON x -> JSON
$cfrom :: forall x. JSON -> Rep JSON x
Generic
type ControlFlow = [(Word64, [Word64])]
type FunctionBoundary = String
data FunctionSummary = FunctionSummary {
FunctionSummary -> FunctionBoundary
precondition :: String,
FunctionSummary -> Postcondition
postcondition :: Postcondition
}
deriving (forall x. FunctionSummary -> Rep FunctionSummary x)
-> (forall x. Rep FunctionSummary x -> FunctionSummary)
-> Generic FunctionSummary
forall x. Rep FunctionSummary x -> FunctionSummary
forall x. FunctionSummary -> Rep FunctionSummary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FunctionSummary x -> FunctionSummary
$cfrom :: forall x. FunctionSummary -> Rep FunctionSummary x
Generic
type Invariant = (Word64,Data.JSON_Taxonomy.Predicate)
data Postcondition =
Terminating
| ReturningWith Data.JSON_Taxonomy.Predicate
| UnknownRetBehavior
deriving (forall x. Postcondition -> Rep Postcondition x)
-> (forall x. Rep Postcondition x -> Postcondition)
-> Generic Postcondition
forall x. Rep Postcondition x -> Postcondition
forall x. Postcondition -> Rep Postcondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Postcondition x -> Postcondition
$cfrom :: forall x. Postcondition -> Rep Postcondition x
Generic
type Predicate = M.Map StatePart SValue
data Instruction = Instruction {
Instruction -> Word64
addr :: Word64,
Instruction -> Maybe Prefix
prefix :: Maybe Prefix,
Instruction -> Opcode
opcode :: Opcode,
Instruction -> [Operand]
operands :: [Operand],
Instruction -> Int
size :: Int
}
deriving (forall x. Instruction -> Rep Instruction x)
-> (forall x. Rep Instruction x -> Instruction)
-> Generic Instruction
forall x. Rep Instruction x -> Instruction
forall x. Instruction -> Rep Instruction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Instruction x -> Instruction
$cfrom :: forall x. Instruction -> Rep Instruction x
Generic
data Operand =
Memory Address Int
| EffectiveAddress Address
| Register Register
| Immediate Word64
deriving (forall x. Operand -> Rep Operand x)
-> (forall x. Rep Operand x -> Operand) -> Generic Operand
forall x. Rep Operand x -> Operand
forall x. Operand -> Rep Operand x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Operand x -> Operand
$cfrom :: forall x. Operand -> Rep Operand x
Generic
data Address =
AddressRegister Register
| AddressImm Word64
| AddressPlus Address Address
| AddressMinus Address Address
| AddressTimes Address Address
deriving (forall x. Address -> Rep Address x)
-> (forall x. Rep Address x -> Address) -> Generic Address
forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Address x -> Address
$cfrom :: forall x. Address -> Rep Address x
Generic
mk_json_address :: GenericAddress Register -> Address
mk_json_address (GA.AddressStorage Register
r) = Register -> Address
AddressRegister Register
r
mk_json_address (GA.AddressImm Word64
i) = Word64 -> Address
AddressImm Word64
i
mk_json_address (GA.AddressPlus GenericAddress Register
a0 GenericAddress Register
a1) = Address -> Address -> Address
AddressPlus (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a0) (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a1)
mk_json_address (GA.AddressMinus GenericAddress Register
a0 GenericAddress Register
a1) = Address -> Address -> Address
AddressMinus (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a0) (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a1)
mk_json_address (GA.AddressTimes GenericAddress Register
a0 GenericAddress Register
a1) = Address -> Address -> Address
AddressTimes (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a0) (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a1)
mk_json_operand :: GenericOperand Register -> Operand
mk_json_operand (GO.Memory GenericAddress Register
a Int
si) = Address -> Int -> Operand
Memory (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a) Int
si
mk_json_operand (GO.EffectiveAddress GenericAddress Register
a) = Address -> Operand
EffectiveAddress (GenericAddress Register -> Address
mk_json_address GenericAddress Register
a)
mk_json_operand (GO.Storage Register
r) = Register -> Operand
Register Register
r
mk_json_operand (GO.Immediate Word64
i) = Word64 -> Operand
Immediate Word64
i
mk_json_instruction :: GenericInstruction AddressWord64 Register Prefix Opcode annotation
-> Instruction
mk_json_instruction i :: GenericInstruction AddressWord64 Register Prefix Opcode annotation
i@(GI.Instruction (GA.AddressWord64 Word64
a) Maybe Prefix
p Opcode
op Maybe (GenericOperand Register)
Nothing [GenericOperand Register]
srcs Maybe annotation
_) = Word64 -> Maybe Prefix -> Opcode -> [Operand] -> Int -> Instruction
Instruction Word64
a Maybe Prefix
p Opcode
op ((GenericOperand Register -> Operand)
-> [GenericOperand Register] -> [Operand]
forall a b. (a -> b) -> [a] -> [b]
map GenericOperand Register -> Operand
mk_json_operand [GenericOperand Register]
srcs) (GenericInstruction AddressWord64 Register Prefix Opcode annotation
-> Int
forall a. HasSize a => a -> Int
sizeof GenericInstruction AddressWord64 Register Prefix Opcode annotation
i)
mk_json_predicate :: Analysis.Context.Predicate -> Data.JSON_Taxonomy.Predicate
mk_json_predicate :: Predicate -> Predicate
mk_json_predicate (Sstate Map Register SValue
regs Map (SPointer, RegionSize) SValue
mem FlagStatus
flg) = (Register -> StatePart) -> Map Register SValue -> Predicate
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
M.mapKeys Register -> StatePart
mk_reg Map Register SValue
regs
where
mk_reg :: Register -> StatePart
mk_reg Register
r = Register -> StatePart
SP_Reg Register
r
mk_json_post :: Maybe FReturnBehavior -> Postcondition
mk_json_post Maybe FReturnBehavior
Nothing = Postcondition
Data.JSON_Taxonomy.UnknownRetBehavior
mk_json_post (Just FReturnBehavior
Analysis.Context.UnknownRetBehavior) = Postcondition
Data.JSON_Taxonomy.UnknownRetBehavior
mk_json_post (Just FReturnBehavior
Analysis.Context.Terminating) = Postcondition
Data.JSON_Taxonomy.Terminating
mk_json_post (Just (Analysis.Context.ReturningWith Predicate
q)) = Predicate -> Postcondition
Data.JSON_Taxonomy.ReturningWith (Predicate -> Postcondition) -> Predicate -> Postcondition
forall a b. (a -> b) -> a -> b
$ Predicate -> Predicate
mk_json_predicate Predicate
q