1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_PartialSymbolicSemantics_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics_PartialSymbolicSemantics_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #ifndef __STDC_FORMAT_MACROS
7 #define __STDC_FORMAT_MACROS
15 #include "rosePublicConfig.h"
16 #ifdef ROSE_HAVE_LIBGCRYPT
20 #include <Rose/BinaryAnalysis/BasicTypes.h>
21 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
22 #include "integerOps.h"
23 #include <Rose/BinaryAnalysis/MemoryMap.h>
24 #include <Rose/FormatRestorer.h>
27 namespace BinaryAnalysis {
28 namespace InstructionSemantics {
43 namespace PartialSymbolicSemantics {
53 typedef std::map<uint64_t, uint64_t> Map;
58 uint64_t rename(uint64_t orig_name);
87 explicit SValue(
size_t nbits)
90 SValue(
size_t nbits, uint64_t number)
93 this->offset &= IntegerOps::genMask<uint64_t>(nbits);
100 SValue(
size_t nbits, uint64_t name, uint64_t offset,
bool negate)
101 :
BaseSemantics::SValue(nbits), name(name), offset(offset), negate(negate) {
102 this->offset &= IntegerOps::genMask<uint64_t>(nbits);
103 ASSERT_require(nbits <= 64 || name != 0);
128 static SValuePtr
instance(
size_t nbits, uint64_t value) {
133 static SValuePtr
instance(
size_t nbits, uint64_t name, uint64_t offset,
bool negate) {
155 SValuePtr retval(
new SValue(*
this));
156 if (new_width!=0 && new_width!=retval->nBits())
157 retval->set_width(new_width);
167 return instance(nbits, name, offset, negate);
177 ASSERT_not_null(retval);
198 if (nbits > 64 && name == 0) {
201 ASSERT_require(nbits <= 64 || name != 0);
203 offset &= IntegerOps::genMask<uint64_t>(nbits);
271 ASSERT_not_null(registers);
273 ASSERT_not_null(memory);
279 ASSERT_require(!mcl->byteRestricted());
307 StatePtr
self = promote(boost::const_pointer_cast<BaseSemantics::State>(shared_from_this()));
315 StatePtr retval = boost::dynamic_pointer_cast<
State>(x);
325 virtual void print_diff_registers(std::ostream&,
const StatePtr &other_state, Formatter&)
const;
408 virtual void interrupt(
int majr,
int minr)
override;
417 size_t begin_bit,
size_t end_bit)
override;
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override
Create a new undefined semantic value.
Base classes for instruction semantics.
virtual void set_width(size_t nbits)
Virtual API.
Simple list-based memory state.
virtual void discard_popped_memory()
Removes from memory those values at addresses below the current stack pointer.
boost::shared_ptr< class MemoryCellList > MemoryCellListPtr
Shared-ownership pointer to a list-based memory state.
Type of values manipulated by the PartialSymbolicSemantics domain.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with signed values.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Concatenates the bits of two values.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &other, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const override
Possibly create a new value by merging two existing values.
static MemoryCellListPtr promote(const BaseSemantics::MemoryStatePtr &m)
Promote a base memory state pointer to a BaseSemantics::MemoryCellList pointer.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a PartialSymbolicSemantics value.
virtual BaseSemantics::StatePtr create(const BaseSemantics::RegisterStatePtr ®isters, const BaseSemantics::MemoryStatePtr &memory) const override
Virtual constructor.
virtual BaseSemantics::SValuePtr create(size_t nbits, uint64_t name, uint64_t offset, bool negate) const
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) override
Two's complement.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Sign extends a value.
Holds a value or nothing.
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right logically (no sign bit).
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override
Data-flow bottom value.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
bool negate
Switch between name+offset and (-name)+offset; should be false for constants.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a_) override
One's complement.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise OR of two values.
virtual bool equal_registers(const StatePtr &other) const
Tests registers of two states for equality.
static StatePtr instance(const BaseSemantics::RegisterStatePtr ®isters, const BaseSemantics::MemoryStatePtr &memory)
Instantiates a new instance of memory state with specified register and memory states.
Main namespace for the ROSE library.
const MemoryMap::Ptr get_memory_map() const
A memory map can be used to provide default values for memory cells that are read before being writte...
virtual BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, const BaseSemantics::SValuePtr &c_, BaseSemantics::SValuePtr &carry_out) override
Add two values of equal size and a carry bit.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) const override
Create a new concrete semantic value.
boost::shared_ptr< class State > StatePtr
Shared-ownership pointer to partial symbolic semantics state.
A RegisterState for any architecture.
static uint64_t nextName()
Returns the next available name.
Reference-counting intrusive smart pointer.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise XOR of two values.
static RiscOperatorsPtr instanceFromProtoval(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical values.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to partial symbolic operators. ...
virtual BaseSemantics::StatePtr clone() const override
Virtual copy constructor.
uint64_t name
Zero for constants; non-zero ID number for everything else.
static SValuePtr instance()
Instantiate a new prototypical value.
static RiscOperatorsPtr instanceFromState(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators with specified state.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
uint64_t offset
The constant (if name==0) or an offset w.r.t.
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.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
virtual void print_diff_registers(std::ostream &, const StatePtr &other_state, Formatter &) const
Print info about how registers differ.
virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const override
Create a new value from an existing value, changing the width if new_width is non-zero.
IteStatus
Status for iteWithStatus operation.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two signed values.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Adds two integers of equal size.
Describes (part of) a physical CPU register.
virtual bool isBottom() const override
Determines whether a value is a data-flow bottom.
virtual void interrupt(int majr, int minr) override
Invoked for instructions that cause an interrupt.
static SValuePtr instance(size_t nbits, uint64_t value)
Instantiate a new concrete value.
Defines RISC operators for this semantic domain.
virtual uint64_t get_number() const override
Virtual API.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of least significant set bit; zero when no bits are set.
static SValuePtr instance(size_t nbits, uint64_t name, uint64_t offset, bool negate)
Insantiate a new value with all the necessary parts.
void set_memory_map(const MemoryMap::Ptr &m)
A memory map can be used to provide default values for memory cells that are read before being writte...
virtual void set_width(size_t nbits) override
Virtual API.
virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &a_, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a_) override
Determines whether a value is equal to zero.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Base class for semantic values.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
static SValuePtr instance(size_t nbits)
Instantiate a new undefined value of specified width.
static RiscOperatorsPtr instanceFromRegisters(const RegisterDictionaryPtr &)
Instantiates a new RiscOperators object and configures it to use semantic values and states that are ...
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the left.
Represents the entire state of the machine.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to partial symbolic semantics RISC operations.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted left.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiply two unsigned values.
static StatePtr instance(const StatePtr &other)
Instantiates a new copy of an existing state.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print a value to a stream using default format.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of most significant set bit; zero when no bits are set.
StatePtr Ptr
Shared-ownership pointer.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
Base class for most instruction semantics RISC operators.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two unsigned values.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &sel_, const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, IteStatus &) override
If-then-else with status.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a partial-symbolic semantic value.
virtual bool is_number() const override
Virtual API.
Base class for semantics machine states.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override
Create a new unspecified semantic value.
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right arithmetically (with sign bit).
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise AND of two values.