1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_NativeSemantics_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_NativeSemantics_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/Debugger.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics2/ConcreteSemantics.h>
9 #include <boost/noncopyable.hpp>
10 #include <boost/filesystem.hpp>
13 namespace BinaryAnalysis {
14 namespace InstructionSemantics2 {
17 namespace NativeSemantics {
61 ASSERT_not_null(process);
75 ASSERT_not_null(protoval);
86 ASSERT_not_implemented(
"not applicable for this class");
90 ASSERT_not_implemented(
"not applicable for this class");
98 RegisterStatePtr retval = boost::dynamic_pointer_cast<
RegisterState>(x);
99 ASSERT_not_null(retval);
119 TODO(
"[Robb Matzke 2019-09-05]");
123 ASSERT_not_implemented(
"[Robb Matzke 2019-09-05]");
139 virtual void print(std::ostream&, Formatter&)
const override;
172 ASSERT_not_null(process);
196 ASSERT_not_implemented(
"not applicable for this class");
200 ASSERT_not_implemented(
"not applicable for this class");
208 MemoryStatePtr retval = boost::dynamic_pointer_cast<
MemoryState>(x);
209 ASSERT_not_null(retval);
230 ASSERT_not_implemented(
"not applicable for this class");
236 return peekMemory(address, dflt, addrOps, valOps);
245 ASSERT_not_implemented(
"[Robb Matzke 2019-09-05]");
250 ASSERT_not_implemented(
"[Robb Matzke 2021-03-26]");
254 ASSERT_not_implemented(
"[Robb Matzke 2019-09-05]");
282 : ConcreteSemantics::
State(registers, memory) {
283 (void) RegisterState::promote(registers);
284 (void) MemoryState::promote(memory);
331 StatePtr state = State::instance(registers, memory);
341 (void) State::promote(state);
351 TODO(
"[Robb Matzke 2019-09-05]");
361 RiscOperatorsPtr retval = boost::dynamic_pointer_cast<
RiscOperators>(x);
362 ASSERT_not_null(retval);
374 return RegisterState::promote(
currentState()->registerState())->process();
401 : process_(process) {
446 notApplicable(
"create");
479 notApplicable(
"iprocReplace");
482 notApplicable(
"iprocSet");
485 notApplicable(
"iprocKey");
490 [[noreturn]]
void notApplicable(
const std::string &what)
const {
491 ASSERT_not_implemented(what +
" is not applicable for this class");
Debugger::Ptr process() const
Property: Subordinate process storing the registers.
static RegisterStatePtr instance()
Construct a state not attached to any subordinate process.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval) const override
Virtual allocating constructor.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print a memory state to more than one line of output.
Defines RISC operators for the ConcreteSemantics domain.
RegisterStatePtr Ptr
Shared-ownership pointer.
const RegisterDictionary * registerDictionary() const
Property: Register dictionary.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
virtual void writeRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &value, BaseSemantics::RiscOperators *) override
Write a value to a register.
virtual BaseSemantics::MemoryStatePtr clone() const override
Virtual allocating copy constructor.
Debugger::Ptr process() const
Property: Subordinate process storing the registers.
ConcreteSemantics::Formatter Formatter
Formatter for printing values.
static SValuePtr instance()
Instantiate a new prototypical value.
virtual bool merge(const BaseSemantics::MemoryStatePtr &other, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Merge memory states for data flow analysis.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *) override
Read a register without side effects.
RiscOperatorsPtr Ptr
Shared-ownership pointer.
MemoryStatePtr Ptr
Shared-ownership pointer.
Base class for machine instructions.
virtual void clear() override
Removes stored values from the register state.
boost::shared_ptr< class RegisterState > RegisterStatePtr
Shared-ownership pointer to RegisterState.
Type of values manipulated by the concrete domain.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< class Dispatcher > DispatcherPtr
Shared-ownership pointer to Dispatcher.
virtual SValuePtr protoval() const
Return the prototypical value.
StatePtr Ptr
Shared-ownership pointer.
virtual void hash(Combinatorics::Hasher &, BaseSemantics::RiscOperators *) const override
Hash the register state.
virtual int iprocKey(SgAsmInstruction *) const override
Disabled in this class.
static Ptr instance()
Create a debugger object that isn't attached to any subordinate process.
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
static MemoryStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval, const Debugger::Ptr &process)
Construct a state attached to the specified process.
virtual SgAsmInstruction * currentInstruction() const override
Decode the current instruction.
Main namespace for the ROSE library.
static DispatcherPtr instance(const BaseSemantics::RiscOperatorsPtr &ops)
Create a new dispatcher using the specified operators.
static RiscOperatorsPtr instance(const BaseSemantics::StatePtr &state)
Instantiate a new RiscOperators object.
virtual BaseSemantics::RegisterStatePtr clone() const override
Make a copy of this register state.
Collection of memory address/value pairs.
virtual void print(std::ostream &, Formatter &) const override
Print the register contents.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *ops) override
Read a value from a register.
Reference-counting intrusive smart pointer.
boost::shared_ptr< class State > StatePtr
Shared-ownership pointer to State.
The set of all registers and their values.
virtual void writeMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &value, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Write a value to memory.
virtual StatePtr currentState() const
Property: Current semantic state.
Debugger::Ptr process() const
Property: Process storing the state.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
virtual void hash(Combinatorics::Hasher &, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) const override
Calculate a hash for this memory state.
static RegisterStatePtr instance(const BaseSemantics::SValuePtr &protoval, const Debugger::Ptr &process)
Construct a state attached to the specified process.
virtual BaseSemantics::RegisterStatePtr create(const BaseSemantics::SValuePtr &protoval, const RegisterDictionary *regdict) const override
Virtual constructor.
const RegisterDictionary * registerDictionary() const
Property: Register dictionary.
Base classes for instruction semantics.
virtual bool merge(const BaseSemantics::RegisterStatePtr &other, BaseSemantics::RiscOperators *ops) override
Merge register states for data flow analysis.
virtual RegisterDescriptor stackPointerRegister() const override
Returns the stack pointer register.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to MemoryState.
Describes (part of) a physical CPU register.
size_t addressWidth() const
Property: Width of memory addresses.
ConcreteSemantics::SValuePtr SValuePtr
Shared-ownership pointer to SValue.
Base class for semantics machine states.
virtual RiscOperatorsPtr operators() const
Property: RISC operators.
static RiscOperatorsPtr instance(const BaseSemantics::SValuePtr &protoval, const Debugger::Ptr &process)
Instantiate a new RiscOperators object.
Describes the specimen to be debugged.
Functor that knows how to dispatch a single kind of instruction.
virtual void iprocSet(int key, BaseSemantics::InsnProcessor *) override
Disabled in this class.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a SymbolicSemantics value.
virtual RegisterDescriptor stackFrameRegister() const override
Returns the stack call frame register.
Base class for most instruction semantics RISC operators.
Represents all memory in the state.
Dispatches instructions through the RISC layer.
const RegisterDictionary * regdict
Registers that are able to be stored by this state.
ConcreteSemantics::SValue SValue
Concrete values from the specimen.
virtual BaseSemantics::SValuePtr peekMemory(const BaseSemantics::SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a value from memory without side effects.
virtual void zero() override
Set all registers to the zero.
virtual void iprocReplace(SgAsmInstruction *, BaseSemantics::InsnProcessor *) override
Disabled in this class.
virtual void processInstruction(SgAsmInstruction *insn) override
Process an instruction.
virtual BaseSemantics::DispatcherPtr create(const BaseSemantics::RiscOperatorsPtr &ops, size_t addrWidth=0, const RegisterDictionary *regs=NULL) const override
Virtual constructor.
virtual BaseSemantics::SValuePtr readMemory(const BaseSemantics::SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a value from memory.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual RegisterDescriptor instructionPointerRegister() const override
Returns the instruction pointer register.
Defines registers available for a particular architecture.
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
static DispatcherPtr instance(const Debugger::Ptr &process, const BaseSemantics::SValuePtr &protoval=SValue::instance())
Create a new dispatcher using the specified process.
virtual const std::string & name() const
Property: Name used for debugging.
virtual void clear() override
Clear memory.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to RiscOperators.
virtual RegisterDescriptor callReturnRegister() const override
Returns the function call return address register.
static DispatcherPtr instance(const Debugger::Specimen &specimen, const BaseSemantics::SValuePtr &protoval=SValue::instance())
Create a new dispatcher using the specified executable specimen.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &x)
Run-time promotion of a base object to a NativeSemantics RiscOperators.
DispatcherPtr Ptr
Shared-ownership pointer.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
SValuePtr protoval() const
Return the protoval.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
static MemoryStatePtr instance()
Construct a state not attached to any subordinate process.