1 #ifndef ROSE_BinaryAnalysis_Partitioner_Semantics_H
2 #define ROSE_BinaryAnalysis_Partitioner_Semantics_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 #include <Partitioner2/BasicTypes.h>
8 #include "SymbolicSemantics2.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>
17 namespace Partitioner2 {
40 typedef InstructionSemantics2::BaseSemantics::State
State;
55 template<
class Super = InstructionSemantics2::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);
225 static const size_t TRIM_THRESHOLD_DFLT = 100;
229 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
231 friend class boost::serialization::access;
234 void serialize(S &s,
const unsigned ) {
235 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
247 name(
"PartitionerSemantics");
249 trimThreshold(TRIM_THRESHOLD_DFLT);
255 name(
"PartitionerSemantics");
257 trimThreshold(TRIM_THRESHOLD_DFLT);
269 switch (memoryParadigm) {
282 static RiscOperatorsPtr
288 static RiscOperatorsPtr
313 static RiscOperatorsPtr
315 RiscOperatorsPtr retval = boost::dynamic_pointer_cast<RiscOperators>(x);
316 assert(retval!=NULL);
330 template<class Super>
334 InstructionSemantics2::
BaseSemantics::RiscOperators *addrOps,
335 InstructionSemantics2::
BaseSemantics::RiscOperators *valOps) {
336 return readOrPeekMemory(addr, dflt, addrOps, valOps,
true);
339 template<
class Super>
345 return readOrPeekMemory(addr, dflt, addrOps, valOps,
false);
348 template<
class Super>
354 bool withSideEffects) {
355 using namespace InstructionSemantics2;
361 if (map_ && addr->toUnsigned()) {
362 ASSERT_require2(8==dflt->nBits(),
"multi-byte reads should have been handled above this call");
363 rose_addr_t va = addr->toUnsigned().get();
364 bool isModifiable = map_->at(va).require(MemoryMap::WRITABLE).exists();
365 bool isInitialized = map_->at(va).require(MemoryMap::INITIALIZED).exists();
366 if (!isModifiable || isInitialized) {
368 if (1 == map_->at(va).limit(1).read(&byte).size()) {
374 SymbolicSemantics::SValuePtr val = SymbolicSemantics::SValue::promote(valOps->undefined_(8));
375 val->set_expression(expr);
381 if (withSideEffects) {
382 return Super::readMemory(addr, dflt, addrOps, valOps);
384 return Super::peekMemory(addr, dflt, addrOps, valOps);
388 template<
class Super>
392 InstructionSemantics2::BaseSemantics::RiscOperators *addrOps,
393 InstructionSemantics2::BaseSemantics::RiscOperators *valOps) {
396 Super::writeMemory(addr, value, addrOps, valOps);
399 template<
class Super>
401 MemoryState<Super>::print(std::ostream &out, InstructionSemantics2::BaseSemantics::Formatter &fmt)
const {
403 map_->dump(out, fmt.get_line_prefix());
405 out <<fmt.get_line_prefix() <<
"no memory map\n";
408 Super::print(out, fmt);
416 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
static RegisterStateGenericPtr instance(const SValuePtr &protoval, const RegisterDictionary *regdict)
Instantiate a new register state.
boost::shared_ptr< class MemoryCell > MemoryCellPtr
Shared-ownership pointer to a semantic memory cell.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
void memoryMap(const MemoryMap::Ptr &map)
The memory map for the specimen.
static RiscOperatorsPtr promote(const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &x)
Run-time promotion of a base RiscOperators pointer to our operators.
Defines RISC operators for the SymbolicSemantics domain.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
std::vector< SValuePtr > & addressesRead()
Property: concrete virtual addresses that were read.
static Ptr promote(const InstructionSemantics2::BaseSemantics::MemoryStatePtr &x)
Recasts a base pointer to a symbolic memory state.
Base class for machine instructions.
InstructionSemantics2::BaseSemantics::RegisterStateGeneric RegisterState
Register state for the partitioner.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to the RISC operators object.
LeafPtr makeIntegerConstant(size_t nBits, uint64_t value, const std::string &comment="", unsigned flags=0)
Leaf constructor.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a SymbolicSemantics value.
boost::shared_ptr< MemoryMapState > MemoryMapStatePtr
Shared-ownership pointer to a MemoryMapState.
void enabled(bool b)
Property: Enabled.
LeafPtr makeIntegerVariable(size_t nBits, const std::string &comment="", unsigned flags=0)
Leaf constructor.
virtual InstructionSemantics2::BaseSemantics::MemoryStatePtr create(const InstructionSemantics2::BaseSemantics::SValuePtr &addrProtoval, const InstructionSemantics2::BaseSemantics::SValuePtr &valProtoval) const ROSE_OVERRIDE
Virtual constructor.
const std::vector< SValuePtr > & addressesRead() const
Property: concrete virtual addresses that were read.
virtual InstructionSemantics2::BaseSemantics::RiscOperatorsPtr create(const InstructionSemantics2::BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
static Ptr instance(const InstructionSemantics2::BaseSemantics::MemoryCellPtr &protocell)
Instantiates a new memory state having specified prototypical cells and value.
Main namespace for the ROSE library.
InstructionSemantics2::SymbolicSemantics::SValuePtr SValuePtr
Reference counting pointer to semantic value.
Reference-counting intrusive smart pointer.
static RiscOperatorsPtr instance(const RegisterDictionary *regdict, const SmtSolverPtr &solver=SmtSolverPtr(), SemanticMemoryParadigm memoryParadigm=LIST_BASED_MEMORY)
Instantiate a new RiscOperators object and configure it using default values.
MemoryMap::Ptr memoryMap() const
The memory map for the specimen.
bool enabled() const
Property: Enabled.
Base classes for instruction semantics.
InstructionSemantics2::BaseSemantics::State State
Total state (registers and memory) for the partitioner.
static Ptr instance(const Ptr &other)
Instantiates a new deep copy of an existing state.
virtual InstructionSemantics2::BaseSemantics::MemoryStatePtr clone() const ROSE_OVERRIDE
Virtual copy constructor.
static SValuePtr instance()
Instantiate a new prototypical value.
boost::shared_ptr< MemoryState > Ptr
Shared-ownership pointer to a MemoryState.
SemanticMemoryParadigm
Organization of semantic memory.
virtual InstructionSemantics2::BaseSemantics::RiscOperatorsPtr create(const InstructionSemantics2::BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
ROSE_DLL_API bool isInitialized()
Checks whether the library has been initialized.
Base class for most instruction semantics RISC operators.
static RiscOperatorsPtr instance(const InstructionSemantics2::BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiate a new RiscOperators object with specified prototypical values.
static RiscOperatorsPtr instance(const InstructionSemantics2::BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiate a new RiscOperators with specified state.
InstructionSemantics2::BaseSemantics::StatePtr StatePtr
Reference counting pointer to total state.
virtual InstructionSemantics2::BaseSemantics::MemoryStatePtr create(const InstructionSemantics2::BaseSemantics::MemoryCellPtr &protocell) const ROSE_OVERRIDE
Virtual constructor.
Type of values manipulated by the SymbolicSemantics domain.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
static Ptr instance(const InstructionSemantics2::BaseSemantics::SValuePtr &addrProtoval, const InstructionSemantics2::BaseSemantics::SValuePtr &valProtoval)
Instantiates a new memory state having specified prototypical value.
A RegisterState for any architecture.
Ptr makeSet(const Ptr &a, const Ptr &b, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0)
Interior node constructor.
Defines registers available for a particular architecture.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
InstructionSemantics2::BaseSemantics::RegisterStateGenericPtr RegisterStatePtr
Reference counting pointer to register state.
InstructionSemantics2::SymbolicSemantics::SValue SValue
Semantic value in the partitioner.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
boost::shared_ptr< MemoryListState > MemoryListStatePtr
Shared-ownership pointer to a MemoryListState.