ROSE 0.11.145.147
SymbolicMemory.h
1// Symbolic memory -- a memory state where memory is represented by an SMT function whose domain is the address space and whose
2// range are the bytes stored at those addresses.
3#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_SymbolicMemory_H
4#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_SymbolicMemory_H
5#include <featureTests.h>
6#ifdef ROSE_ENABLE_BINARY_ANALYSIS
7
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryState.h>
9#include <Rose/BinaryAnalysis/SymbolicExpression.h>
10
11namespace Rose {
12namespace BinaryAnalysis {
13namespace InstructionSemantics {
14namespace BaseSemantics {
15
17typedef boost::shared_ptr<class SymbolicMemory> SymbolicMemoryPtr;
18
25public:
28
31
32private:
34
35protected:
36 // All memory states should be heap allocated; use instance(), create(), or clone() instead.
37 explicit SymbolicMemory(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
38 : MemoryState(addrProtoval, valProtoval) {
39 // Initially assume that addresses are 32 bits wide and values are 8 bits wide. We can change this on the first access.
41 }
42
43public:
45 static SymbolicMemoryPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) {
46 return SymbolicMemoryPtr(new SymbolicMemory(addrProtoval, valProtoval));
47 }
48
49public:
50 // documented in base class
51 virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override {
52 return instance(addrProtoval, valProtoval);
53 }
54
55 // documented in base class
56 virtual MemoryStatePtr clone() const override {
57 return SymbolicMemoryPtr(new SymbolicMemory(*this));
58 }
59
64 SymbolicMemoryPtr retval = boost::dynamic_pointer_cast<SymbolicMemory>(x);
65 ASSERT_not_null(retval);
66 return retval;
67 }
68
69public:
73 SymbolicExpression::Ptr expression() const { return mem_; }
77public:
78 virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
79
80 virtual void clear() override;
81
82 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
83 RiscOperators *addrOps, RiscOperators *valOps) override;
84
85 virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
86 RiscOperators *addrOps, RiscOperators *valOps) override;
87
88 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
89 RiscOperators *addrOps, RiscOperators *valOps) override;
90
91public:
92 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
93
94 virtual void print(std::ostream&, Formatter&) const override;
95};
96
97} // namespace
98} // namespace
99} // namespace
100} // namespace
101
102#endif
103#endif
Base class for most instruction semantics RISC operators.
void expression(const SymbolicExpression::Ptr &mem)
Property: the symbolic expression for the memory.
virtual MemoryStatePtr clone() const override
Virtual allocating copy constructor.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge memory states for data flow analysis.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory without side effects.
static SymbolicMemoryPtr promote(const MemoryStatePtr &x)
Convert pointer to a SymbolicMemory pointer.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Calculate a hash for this memory state.
virtual void writeMemory(const SValuePtr &address, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override
Write a value to memory.
static SymbolicMemoryPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
Instantiate a new empty memory state on the heap.
SymbolicExpression::Ptr expression() const
Property: the symbolic expression for the memory.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory.
virtual void print(std::ostream &, Formatter &) const override
Print a memory state to more than one line of output.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override
Virtual allocating constructor.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< class SymbolicMemory > SymbolicMemoryPtr
Shared-ownership pointer for symbolic memory state.
LeafPtr makeMemoryVariable(size_t addressWidth, size_t valueWidth, const std::string &comment="", unsigned flags=0)
Leaf constructor.
The ROSE library.