1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Semantics_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Semantics_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/SymbolicSemantics.h>
8 #include <Rose/BinaryAnalysis/SymbolicExpression.h>
10 #include <boost/serialization/access.hpp>
11 #include <boost/serialization/base_object.hpp>
12 #include <boost/serialization/export.hpp>
13 #include <boost/serialization/vector.hpp>
16 namespace BinaryAnalysis {
17 namespace Partitioner2 {
55 template<
class Super = InstructionSemantics::SymbolicSemantics::MemoryListState>
59 typedef boost::shared_ptr<MemoryState>
Ptr;
63 std::vector<SValuePtr> addressesRead_;
66 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
68 friend class boost::serialization::access;
71 void serialize(S &s,
const unsigned ) {
72 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
73 s & BOOST_SERIALIZATION_NVP(map_);
74 s & BOOST_SERIALIZATION_NVP(addressesRead_);
75 s & BOOST_SERIALIZATION_NVP(enabled_);
84 : Super(protocell), enabled_(true) {}
88 : Super(addrProtoval, valProtoval), enabled_(true) {}
112 return instance(addrProtoval, valProtoval);
132 Ptr retval = boost::dynamic_pointer_cast<
MemoryState>(x);
162 const std::vector<SValuePtr>&
addressesRead()
const {
return addressesRead_; }
191 bool withSideEffects);
226 static const size_t TRIM_THRESHOLD_DFLT = 100;
230 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
232 friend class boost::serialization::access;
235 void serialize(S &s,
const unsigned ) {
236 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Super);
309 template<
class Super>
315 return readOrPeekMemory(addr, dflt, addrOps, valOps,
true);
318 template<
class Super>
324 return readOrPeekMemory(addr, dflt, addrOps, valOps,
false);
327 template<
class Super>
331 InstructionSemantics::BaseSemantics::RiscOperators *addrOps,
332 InstructionSemantics::BaseSemantics::RiscOperators *valOps,
333 bool withSideEffects) {
334 using namespace InstructionSemantics;
340 if (map_ && addr->toUnsigned()) {
341 ASSERT_require2(8==dflt->nBits(),
"multi-byte reads should have been handled above this call");
342 rose_addr_t va = addr->toUnsigned().get();
343 bool isModifiable = map_->at(va).require(MemoryMap::WRITABLE).exists();
344 bool isInitialized = map_->at(va).require(MemoryMap::INITIALIZED).exists();
345 if (!isModifiable || isInitialized) {
347 if (1 == map_->at(va).limit(1).read(&byte).size()) {
353 SymbolicSemantics::SValuePtr val = SymbolicSemantics::SValue::promote(valOps->undefined_(8));
354 val->set_expression(expr);
360 if (withSideEffects) {
361 return Super::readMemory(addr, dflt, addrOps, valOps);
363 return Super::peekMemory(addr, dflt, addrOps, valOps);
367 template<
class Super>
371 InstructionSemantics::BaseSemantics::RiscOperators *addrOps,
372 InstructionSemantics::BaseSemantics::RiscOperators *valOps) {
375 Super::writeMemory(addr, value, addrOps, valOps);
378 template<
class Super>
380 MemoryState<Super>::print(std::ostream &out, InstructionSemantics::BaseSemantics::Formatter &fmt)
const {
382 map_->dump(out, fmt.get_line_prefix());
384 out <<fmt.get_line_prefix() <<
"no memory map\n";
387 Super::print(out, fmt);
395 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
InstructionSemantics::BaseSemantics::State State
Total state (registers and memory) for the partitioner.
InstructionSemantics::BaseSemantics::StatePtr StatePtr
Reference counting pointer to total state.
virtual InstructionSemantics::BaseSemantics::RiscOperatorsPtr create(const InstructionSemantics::BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
void memoryMap(const MemoryMap::Ptr &map)
The memory map for the specimen.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr clone() const override
Virtual copy constructor.
std::vector< SValuePtr > & addressesRead()
Property: concrete virtual addresses that were read.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Base class for machine instructions.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to the RISC operators object.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a SymbolicSemantics value.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr create(const InstructionSemantics::BaseSemantics::MemoryCellPtr &protocell) const override
Virtual constructor.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
boost::shared_ptr< MemoryMapState > MemoryMapStatePtr
Shared-ownership pointer to a MemoryMapState.
static Ptr instance(const InstructionSemantics::BaseSemantics::MemoryCellPtr &protocell)
Instantiates a new memory state having specified prototypical cells and value.
void enabled(bool b)
Property: Enabled.
const std::vector< SValuePtr > & addressesRead() const
Property: concrete virtual addresses that were read.
Main namespace for the ROSE library.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
A RegisterState for any architecture.
static RiscOperatorsPtr promote(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to our operators.
Reference-counting intrusive smart pointer.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
static RiscOperatorsPtr instance(const RegisterDictionaryPtr &)
Instantiate a new RiscOperators object and configure it using default values.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
MemoryMap::Ptr memoryMap() const
The memory map for the specimen.
bool enabled() const
Property: Enabled.
InstructionSemantics::SymbolicSemantics::SValuePtr SValuePtr
Reference counting pointer to semantic value.
InstructionSemantics::BaseSemantics::RegisterStateGenericPtr RegisterStatePtr
Reference counting pointer to register state.
static Ptr instance(const Ptr &other)
Instantiates a new deep copy of an existing state.
boost::shared_ptr< MemoryState > Ptr
Shared-ownership pointer to a MemoryState.
SemanticMemoryParadigm
Organization of semantic memory.
LeafPtr makeIntegerVariable(size_t nBits, const std::string &comment="", unsigned flags=0)
Leaf constructor.
Type of values manipulated by the SymbolicSemantics domain.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr create(const InstructionSemantics::BaseSemantics::SValuePtr &addrProtoval, const InstructionSemantics::BaseSemantics::SValuePtr &valProtoval) const override
Virtual constructor.
Ptr makeSet(const Ptr &a, const Ptr &b, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0)
Interior node constructor.
ROSE_DLL_API bool isInitialized()
Checks whether the library has been initialized.
Defines RISC operators for the SymbolicSemantics domain.
static Ptr instance(const InstructionSemantics::BaseSemantics::SValuePtr &addrProtoval, const InstructionSemantics::BaseSemantics::SValuePtr &valProtoval)
Instantiates a new memory state having specified prototypical value.
static Ptr promote(const InstructionSemantics::BaseSemantics::MemoryStatePtr &x)
Recasts a base pointer to a symbolic memory state.
LeafPtr makeIntegerConstant(size_t nBits, uint64_t value, const std::string &comment="", unsigned flags=0)
Leaf constructor.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
InstructionSemantics::BaseSemantics::RegisterStateGeneric RegisterState
Register state for the partitioner.
virtual void startInstruction(SgAsmInstruction *) override
Called at the beginning of every instruction.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
virtual InstructionSemantics::BaseSemantics::RiscOperatorsPtr create(const InstructionSemantics::BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
Base class for most instruction semantics RISC operators.
MemoryState< InstructionSemantics::SymbolicSemantics::MemoryMapState > MemoryMapState
Memory state indexed by hash of address expressions.
MemoryState< InstructionSemantics::SymbolicSemantics::MemoryListState > MemoryListState
Memory state using a chronological list of cells.
InstructionSemantics::SymbolicSemantics::SValue SValue
Semantic value in the partitioner.
Base class for semantics machine states.
boost::shared_ptr< MemoryListState > MemoryListStatePtr
Shared-ownership pointer to a MemoryListState.