1 #ifndef ROSE_BinaryAnalysis_Partitioner_Semantics_H
2 #define ROSE_BinaryAnalysis_Partitioner_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>
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/base_object.hpp>
11 #include <boost/serialization/export.hpp>
12 #include <boost/serialization/vector.hpp>
15 namespace BinaryAnalysis {
16 namespace Partitioner2 {
54 template<
class Super = InstructionSemantics::SymbolicSemantics::MemoryListState>
58 typedef boost::shared_ptr<MemoryState>
Ptr;
62 std::vector<SValuePtr> addressesRead_;
65 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
67 friend class boost::serialization::access;
70 void serialize(S &s,
const unsigned ) {
71 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
72 s & BOOST_SERIALIZATION_NVP(map_);
73 s & BOOST_SERIALIZATION_NVP(addressesRead_);
74 s & BOOST_SERIALIZATION_NVP(enabled_);
83 : Super(protocell), enabled_(true) {}
87 : Super(addrProtoval, valProtoval), enabled_(true) {}
111 return instance(addrProtoval, valProtoval);
131 Ptr retval = boost::dynamic_pointer_cast<
MemoryState>(x);
161 const std::vector<SValuePtr>&
addressesRead()
const {
return addressesRead_; }
190 bool withSideEffects);
224 static const size_t TRIM_THRESHOLD_DFLT = 100;
228 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
230 friend class boost::serialization::access;
233 void serialize(S &s,
const unsigned ) {
234 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
246 name(
"PartitionerSemantics");
254 name(
"PartitionerSemantics");
268 switch (memoryParadigm) {
281 static RiscOperatorsPtr
287 static RiscOperatorsPtr
312 static RiscOperatorsPtr
314 RiscOperatorsPtr retval = boost::dynamic_pointer_cast<
RiscOperators>(x);
315 assert(retval!=NULL);
329 template<
class Super>
335 return readOrPeekMemory(addr, dflt, addrOps, valOps,
true);
338 template<
class Super>
344 return readOrPeekMemory(addr, dflt, addrOps, valOps,
false);
347 template<
class Super>
351 InstructionSemantics::BaseSemantics::RiscOperators *addrOps,
352 InstructionSemantics::BaseSemantics::RiscOperators *valOps,
353 bool withSideEffects) {
354 using namespace InstructionSemantics;
360 if (map_ && addr->toUnsigned()) {
361 ASSERT_require2(8==dflt->nBits(),
"multi-byte reads should have been handled above this call");
362 rose_addr_t va = addr->toUnsigned().get();
363 bool isModifiable = map_->at(va).require(MemoryMap::WRITABLE).exists();
364 bool isInitialized = map_->at(va).require(MemoryMap::INITIALIZED).exists();
365 if (!isModifiable || isInitialized) {
367 if (1 == map_->at(va).limit(1).read(&byte).size()) {
373 SymbolicSemantics::SValuePtr val = SymbolicSemantics::SValue::promote(valOps->undefined_(8));
374 val->set_expression(expr);
380 if (withSideEffects) {
381 return Super::readMemory(addr, dflt, addrOps, valOps);
383 return Super::peekMemory(addr, dflt, addrOps, valOps);
387 template<
class Super>
391 InstructionSemantics::BaseSemantics::RiscOperators *addrOps,
392 InstructionSemantics::BaseSemantics::RiscOperators *valOps) {
395 Super::writeMemory(addr, value, addrOps, valOps);
398 template<
class Super>
400 MemoryState<Super>::print(std::ostream &out, InstructionSemantics::BaseSemantics::Formatter &fmt)
const {
402 map_->dump(out, fmt.get_line_prefix());
404 out <<fmt.get_line_prefix() <<
"no memory map\n";
407 Super::print(out, fmt);
415 #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.
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
void memoryMap(const MemoryMap::Ptr &map)
The memory map for the specimen.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr clone() const override
Virtual copy constructor.
static RiscOperatorsPtr instance(const InstructionSemantics::BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiate a new RiscOperators with specified state.
virtual const std::string & name() const
Property: Name used for debugging.
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.
LeafPtr makeIntegerConstant(size_t nBits, uint64_t value, const std::string &comment="", unsigned flags=0)
Leaf constructor.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr create(const InstructionSemantics::BaseSemantics::MemoryCellPtr &protocell) const override
Virtual constructor.
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.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
LeafPtr makeIntegerVariable(size_t nBits, const std::string &comment="", unsigned flags=0)
Leaf constructor.
const std::vector< SValuePtr > & addressesRead() const
Property: concrete virtual addresses that were read.
Main namespace for the ROSE library.
static RegisterStateGenericPtr instance(const SValuePtr &protoval, const RegisterDictionary *regdict)
Instantiate a new register state.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
A RegisterState for any architecture.
Reference-counting intrusive smart pointer.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
static StatePtr instance(const RegisterStatePtr ®isters, const MemoryStatePtr &memory)
Instantiate a new state object with specified register and memory states.
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.
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
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.
Type of values manipulated by the SymbolicSemantics domain.
static SValuePtr instance()
Instantiate a new prototypical value.
virtual InstructionSemantics::BaseSemantics::MemoryStatePtr create(const InstructionSemantics::BaseSemantics::SValuePtr &addrProtoval, const InstructionSemantics::BaseSemantics::SValuePtr &valProtoval) const override
Virtual 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 RiscOperatorsPtr instance(const InstructionSemantics::BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiate a new RiscOperators object with specified prototypical values.
static Ptr promote(const InstructionSemantics::BaseSemantics::MemoryStatePtr &x)
Recasts a base pointer to a symbolic memory state.
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.
virtual InstructionSemantics::BaseSemantics::RiscOperatorsPtr create(const InstructionSemantics::BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
Ptr makeSet(const Ptr &a, const Ptr &b, const SmtSolverPtr &solver=SmtSolverPtr(), const std::string &comment="", unsigned flags=0)
Interior node constructor.
static RiscOperatorsPtr promote(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &x)
Run-time promotion of a base RiscOperators pointer to our operators.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
uint64_t trimThreshold() const
Property: Maximum size of expressions.
Base class for most instruction semantics RISC operators.
Defines registers available for a particular architecture.
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.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
boost::shared_ptr< MemoryListState > MemoryListStatePtr
Shared-ownership pointer to a MemoryListState.