foxdec-0.1.0.0: Formally Verified x86-64 Decompilation
Safe HaskellNone
LanguageHaskell2010

Data.SimplePred

Description

A datatype for symbolic predicates, tailored to storing information on equalities between the current values stored in state parts (lhs) and constant expressions (rhs).

Synopsis

Documentation

data Pred Source #

A symbolic predicate consists of:

  • A mapping from stateparts to symbolic expressions.
  • The status of the flags.
  • A set of verification conditions.

Instances

Instances details
Eq Pred Source # 
Instance details

Defined in Data.SimplePred

Methods

(==) :: Pred -> Pred -> Bool #

(/=) :: Pred -> Pred -> Bool #

Ord Pred Source # 
Instance details

Defined in Data.SimplePred

Methods

compare :: Pred -> Pred -> Ordering #

(<) :: Pred -> Pred -> Bool #

(<=) :: Pred -> Pred -> Bool #

(>) :: Pred -> Pred -> Bool #

(>=) :: Pred -> Pred -> Bool #

max :: Pred -> Pred -> Pred #

min :: Pred -> Pred -> Pred #

Show Pred Source # 
Instance details

Defined in Data.SimplePred

Methods

showsPrec :: Int -> Pred -> ShowS #

show :: Pred -> String #

showList :: [Pred] -> ShowS #

Generic Pred Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep Pred :: Type -> Type #

Methods

from :: Pred -> Rep Pred x #

to :: Rep Pred x -> Pred #

Serialize Pred Source # 
Instance details

Defined in Data.SimplePred

Methods

put :: Putter Pred #

get :: Get Pred #

Propagator FContext Pred Source # 
Instance details

Defined in Analysis.SymbolicExecution

type Rep Pred Source # 
Instance details

Defined in Data.SimplePred

data StatePart Source #

A statepart is either a register or a region in memory

Constructors

SP_StackPointer String

The stack pointer of the given function

SP_Reg Register

A register

SP_Mem SimpleExpr Int

A region with a symbolic address and an immediate size.

Instances

Instances details
Eq StatePart Source # 
Instance details

Defined in Data.SimplePred

Ord StatePart Source # 
Instance details

Defined in Data.SimplePred

Show StatePart Source # 
Instance details

Defined in Data.SimplePred

Generic StatePart Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep StatePart :: Type -> Type #

Serialize StatePart Source # 
Instance details

Defined in Data.SimplePred

type Rep StatePart Source # 
Instance details

Defined in Data.SimplePred

data SimpleExpr Source #

A symbolic expression with as leafs either immediates, variables, live values of stateparts, or malloced addresses. A variable is a constant representing some initial value, e.g., RDI_0, or [RSP_0,8]_0. A statepart evaluates to its current value, e.g., RDI or [RSP,8].

Constructors

SE_Immediate Word64

An immediate word

SE_Var StatePart

A variable representing the initial value stored in the statepart (e.g., RSP0)

SE_StatePart StatePart

The value stored currently in the statepart

SE_Malloc (Maybe Word64) (Maybe String)

A malloc return value with possibly an ID

SE_Op Operator [SimpleExpr]

Application of an Operator to the list of arguments

SE_Bit Int SimpleExpr

Taking the lower bits of a value

SE_SExtend Int Int SimpleExpr

Sign extension

SE_Overwrite Int SimpleExpr SimpleExpr

Overwriting certain bits of a value with bits from another value

Bottom BotTyp

Bottom (unknown value)

Instances

Instances details
Eq SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

Ord SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

Show SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

Generic SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep SimpleExpr :: Type -> Type #

Serialize SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

type Rep SimpleExpr Source # 
Instance details

Defined in Data.SimplePred

type Rep SimpleExpr = D1 ('MetaData "SimpleExpr" "Data.SimplePred" "foxdec-0.1.0.0-KhdyLJGQiCJLT7iSdXA91t" 'False) (((C1 ('MetaCons "SE_Immediate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Word64)) :+: C1 ('MetaCons "SE_Var" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 StatePart))) :+: (C1 ('MetaCons "SE_StatePart" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 StatePart)) :+: C1 ('MetaCons "SE_Malloc" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe Word64)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe String))))) :+: ((C1 ('MetaCons "SE_Op" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Operator) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 [SimpleExpr])) :+: C1 ('MetaCons "SE_Bit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SimpleExpr))) :+: (C1 ('MetaCons "SE_SExtend" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SimpleExpr))) :+: (C1 ('MetaCons "SE_Overwrite" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SimpleExpr) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SimpleExpr))) :+: C1 ('MetaCons "Bottom" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 BotTyp))))))

data FlagStatus Source #

Symbolically represent the status of all flags in the current state

Constructors

None

No information known, flags could have any value

FS_CMP (Maybe Bool) Operand Operand

The flags are set by the x86 CMP instruction applied to the given operands.

Instances

Instances details
Eq FlagStatus Source # 
Instance details

Defined in Data.SimplePred

Ord FlagStatus Source # 
Instance details

Defined in Data.SimplePred

Show FlagStatus Source # 
Instance details

Defined in Data.SimplePred

Generic FlagStatus Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep FlagStatus :: Type -> Type #

Serialize FlagStatus Source # 
Instance details

Defined in Data.SimplePred

type Rep FlagStatus Source # 
Instance details

Defined in Data.SimplePred

data BotTyp Source #

Bot represents an unknown (bottom) value. We annotate each occurence of Bot with a BotTyp. This type indicates where the bottom value originates from. The latter six are all equal, we just use them for debugging and information. They indicate that the value is unknown, but was computed using the set of sources.

Constructors

FromNonDeterminism (Set SimpleExpr)

The expression evaluates to one of the expressions in the set

FromPointerBases (Set PointerBase)

The expression is a pointer-computation with known base(s)

FromCall String

Return value of a function call

FromSources (Set BotSrc)

The expression is some computation based on sources.

FromOverlap (Set BotSrc)

A read from two possibly overlapping regions

FromMemWrite (Set BotSrc)

A write to two possibly overlapping regions

FromSemantics (Set BotSrc)

An instruction with unknown semantics

FromBitMode (Set BotSrc)

Should not happen, but if a register writes to a registeralias with unknown bit size

FromUninitializedMemory (Set BotSrc)

Reading from memory not written to yet

Instances

Instances details
Eq BotTyp Source # 
Instance details

Defined in Data.SimplePred

Methods

(==) :: BotTyp -> BotTyp -> Bool #

(/=) :: BotTyp -> BotTyp -> Bool #

Ord BotTyp Source # 
Instance details

Defined in Data.SimplePred

Show BotTyp Source # 
Instance details

Defined in Data.SimplePred

Generic BotTyp Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep BotTyp :: Type -> Type #

Methods

from :: BotTyp -> Rep BotTyp x #

to :: Rep BotTyp x -> BotTyp #

Serialize BotTyp Source # 
Instance details

Defined in Data.SimplePred

type Rep BotTyp Source # 
Instance details

Defined in Data.SimplePred

type Rep BotTyp = D1 ('MetaData "BotTyp" "Data.SimplePred" "foxdec-0.1.0.0-KhdyLJGQiCJLT7iSdXA91t" 'False) (((C1 ('MetaCons "FromNonDeterminism" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set SimpleExpr))) :+: C1 ('MetaCons "FromPointerBases" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set PointerBase)))) :+: (C1 ('MetaCons "FromCall" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 String)) :+: C1 ('MetaCons "FromSources" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc))))) :+: ((C1 ('MetaCons "FromOverlap" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc))) :+: C1 ('MetaCons "FromMemWrite" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc)))) :+: (C1 ('MetaCons "FromSemantics" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc))) :+: (C1 ('MetaCons "FromBitMode" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc))) :+: C1 ('MetaCons "FromUninitializedMemory" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Set BotSrc)))))))

data BotSrc Source #

Sources that may be used to compute an expression. That is, the inputs to an expression.

Constructors

Src_Var StatePart

An initial variable, i.e., a constant

Src_StackPointer String

The stack pointer of the given function

Src_Malloc (Maybe Word64) (Maybe String)

A malloced address

Src_ImmediateAddress Word64

An immediate used in the computation of the pointer

Src_Function String

A return value from a function

Instances

Instances details
Eq BotSrc Source # 
Instance details

Defined in Data.SimplePred

Methods

(==) :: BotSrc -> BotSrc -> Bool #

(/=) :: BotSrc -> BotSrc -> Bool #

Ord BotSrc Source # 
Instance details

Defined in Data.SimplePred

Show BotSrc Source # 
Instance details

Defined in Data.SimplePred

Generic BotSrc Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep BotSrc :: Type -> Type #

Methods

from :: BotSrc -> Rep BotSrc x #

to :: Rep BotSrc x -> BotSrc #

Serialize BotSrc Source # 
Instance details

Defined in Data.SimplePred

type Rep BotSrc Source # 
Instance details

Defined in Data.SimplePred

data Operator Source #

An operator is a pure operation over bit-vectors, annotated with the bit-size of its operands. For example, Plus 64 denotes 64-bit addition. Udiv and Times are operators op type w -> w -> w with all words same length. Div and Div_Rem are operators of type w -> w -> w -> w performing concatenation of the first two words and then doing division/remainder.

Instances

Instances details
Eq Operator Source # 
Instance details

Defined in Data.SimplePred

Ord Operator Source # 
Instance details

Defined in Data.SimplePred

Show Operator Source # 
Instance details

Defined in Data.SimplePred

Generic Operator Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep Operator :: Type -> Type #

Methods

from :: Operator -> Rep Operator x #

to :: Rep Operator x -> Operator #

Serialize Operator Source # 
Instance details

Defined in Data.SimplePred

type Rep Operator Source # 
Instance details

Defined in Data.SimplePred

type Rep Operator = D1 ('MetaData "Operator" "Data.SimplePred" "foxdec-0.1.0.0-KhdyLJGQiCJLT7iSdXA91t" 'False) ((((C1 ('MetaCons "Minus" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Plus" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) :+: (C1 ('MetaCons "Times" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "And" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)))) :+: ((C1 ('MetaCons "Or" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Xor" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) :+: (C1 ('MetaCons "Not" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "SetXX" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bsr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)))))) :+: (((C1 ('MetaCons "Div_Rem" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Div" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) :+: (C1 ('MetaCons "Shl" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "Shr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Sar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))))) :+: ((C1 ('MetaCons "Udiv" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Ror" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int))) :+: (C1 ('MetaCons "Rol" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "Bswap" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "Pextr" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Int)))))))

data PointerBase Source #

A pointerbase is a positive addend of a symbolic expression that may represent a pointer.

Constructors

StackPointer String

The stack frame of the given function

Malloc (Maybe Word64) (Maybe String)

A malloc (at the heap) at a given address (hash is unused for now)

GlobalAddress Word64

A global address in the range of the sections of the binary.

PointerToSymbol Word64 String

An address with an associated symbol.

Instances

Instances details
Eq PointerBase Source # 
Instance details

Defined in Data.SimplePred

Ord PointerBase Source # 
Instance details

Defined in Data.SimplePred

Show PointerBase Source # 
Instance details

Defined in Data.SimplePred

Generic PointerBase Source # 
Instance details

Defined in Data.SimplePred

Associated Types

type Rep PointerBase :: Type -> Type #

Serialize PointerBase Source # 
Instance details

Defined in Data.SimplePred

type Rep PointerBase Source # 
Instance details

Defined in Data.SimplePred

is_immediate :: SimpleExpr -> Bool Source #

Returns true iff the expression is an immediate value

is_mem_sp :: StatePart -> Bool Source #

Is the statepart memory?

is_reg_sp :: StatePart -> Bool Source #

Is the statepart a register?

contains_bot :: SimpleExpr -> Bool Source #

Returns true iff the expression contains Bot

contains_bot_sp :: StatePart -> Bool Source #

Returns true iff the statepart contains Bot

all_bot_satisfy :: (BotTyp -> Bool) -> SimpleExpr -> Bool Source #

Do all occurences of Bottom satisfy the given predicate?

simp :: SimpleExpr -> SimpleExpr Source #

Simplification of symbolic expressions.

Must always produce an expression logically equivalent to the original. TODO: overwrite(8,Bot[src|RSP_0x1000070ec,malloc100007204()|],b8(Bot[m|RSP_0x1000070ec,malloc100007204()|]))

rock_bottom :: SimpleExpr Source #

The lowest botom element

pp_expr :: SimpleExpr -> [Char] Source #

Pretty print expression, showing Bottom expressions only as Bot

pp_pred :: Pred -> String Source #

Pretty print predicate, showing Bottom expressions only as Bot