ROSE 0.11.145.281
|
Abstract location.
An abstract location represents either a register name or memory address. Addresses can be absolute or relative to the contents of a base register. Registers are represented by RegisterDescriptor and addresses are represented by semantic values (subclasses of BaseSemantics::SValue).
For instance, to represent abstract locations where memory addresses have symbolic values, one uses:
Abstract locations are immutable objects.
See also, ConcreteLocation.
Definition at line 34 of file AbstractLocation.h.
#include <Rose/BinaryAnalysis/AbstractLocation.h>
Public Types | |
using | Address = InstructionSemantics::BaseSemantics::SValuePtr |
Type of memory address. | |
Public Member Functions | |
AbstractLocation () | |
Default constructor. | |
AbstractLocation (const AbstractLocation &) | |
Copy constructor. | |
AbstractLocation & | operator= (const AbstractLocation &) |
Assignment operator. | |
AbstractLocation (const Address &, size_t nBytes=0) | |
Absolute memory referent. | |
virtual bool | isValid () const override |
Test whether this object is valid. | |
virtual uint64_t | hash () const override |
Compute a 64-bit hash of this object. | |
virtual std::string | toString () const override |
Convert location to string. | |
virtual void | print (std::ostream &) const override |
Output location to a stream. | |
virtual std::string | printableName () const override |
Convert location to escaped, parsable string. | |
virtual bool | isEqual (const Location &) const override |
Equality and inequality. | |
virtual bool | operator< (const Location &) const override |
virtual bool | operator<= (const Location &) const override |
virtual bool | operator> (const Location &) const override |
virtual bool | operator>= (const Location &) const override |
int | compare (const AbstractLocation &other) const |
Compare two abstract locations. | |
bool | isRegister () const |
Checks register reference. | |
bool | isAddress () const |
Checks memory reference. | |
bool | isAbsoluteAddress () const |
True if this is an absolute memory location. | |
bool | isRelativeAddress () const |
True if this is a register-relative memory location. | |
RegisterDictionaryPtr | registerDictionary () const |
Property: Register dictionary. | |
RegisterDescriptor | getRegister () const |
Returns register. | |
const Address | getAddress () const |
Returns memory absolute address. | |
const Address | getOffset () const |
Returns the memory offset. | |
size_t | nBytes () const |
Returns size of memory location in bytes. | |
bool | mayAlias (const AbstractLocation &other, const SmtSolverPtr &solver=SmtSolverPtr()) const |
True if two abstract locations could be aliases. | |
bool | mustAlias (const AbstractLocation &other, const SmtSolverPtr &solver=SmtSolverPtr()) const |
True if two abstract locations are certainly aliases. | |
AbstractLocation (RegisterDescriptor) | |
Register referent. | |
AbstractLocation (RegisterDescriptor, const RegisterDictionaryPtr ®dict) | |
Register referent. | |
AbstractLocation (RegisterDescriptor base, const Address &offset, size_t nBytes=0) | |
Relative memory referent. | |
AbstractLocation (RegisterDescriptor base, const RegisterDictionaryPtr &, const Address &offset, size_t nBytes=0) | |
Relative memory referent. | |
void | print (std::ostream &out, const RegisterDictionaryPtr ®dict) const |
Print an abstract location. | |
void | print (std::ostream &out, InstructionSemantics::BaseSemantics::Formatter &fmt) const |
Print an abstract location. | |
void | print (std::ostream &out, const RegisterDictionaryPtr ®dict, InstructionSemantics::BaseSemantics::Formatter &fmt) const |
Print an abstract location. | |
![]() | |
virtual bool | operator== (const Location &other) const final |
Equality and inequality. | |
virtual bool | operator!= (const Location &other) const final |
Equality and inequality. | |
virtual | operator bool () const final |
Test whether this object is valid. | |
virtual bool | operator! () const final |
Test whether this object is empty. | |
virtual bool | isEmpty () const final |
Test whether this object is empty. | |
Static Public Member Functions | |
static AbstractLocation | parse (const std::string &) |
Parse an abstract location from a string. | |
using Rose::BinaryAnalysis::AbstractLocation::Address = InstructionSemantics::BaseSemantics::SValuePtr |
Type of memory address.
Definition at line 36 of file AbstractLocation.h.
Rose::BinaryAnalysis::AbstractLocation::AbstractLocation | ( | ) |
Default constructor.
Constructs an abstract location that does not refer to any location. The isValid method will return false for such objects.
|
explicit |
Register referent.
Constructs an abstract location that refers to a register. The register dictionary (if supplied) is only used when converting this object to a string.
|
explicit |
Register referent.
Constructs an abstract location that refers to a register. The register dictionary (if supplied) is only used when converting this object to a string.
|
explicit |
Absolute memory referent.
Constructs an abstract location that refers to a memory location. The location is the direct memory address, not relative to any base address. The nBytes
argument is the size of the value stored at that location.
Rose::BinaryAnalysis::AbstractLocation::AbstractLocation | ( | RegisterDescriptor | base, |
const Address & | offset, | ||
size_t | nBytes = 0 |
||
) |
Relative memory referent.
Constructs an abstract location that refers to a memory location. The location is an offset from the contents of some register such as the stack pointer. The nBytes
argument is the size of the value stored at that location. The register dictionary (if supplied) is only used when converting this object to a string.
Rose::BinaryAnalysis::AbstractLocation::AbstractLocation | ( | RegisterDescriptor | base, |
const RegisterDictionaryPtr & | , | ||
const Address & | offset, | ||
size_t | nBytes = 0 |
||
) |
Relative memory referent.
Constructs an abstract location that refers to a memory location. The location is an offset from the contents of some register such as the stack pointer. The nBytes
argument is the size of the value stored at that location. The register dictionary (if supplied) is only used when converting this object to a string.
|
overridevirtual |
Test whether this object is valid.
Implements Rose::Location.
|
overridevirtual |
Compute a 64-bit hash of this object.
Implements Rose::Location.
|
overridevirtual |
Convert location to string.
Returns a string representation of the location. This representation is not necessarily parsable.
See also, print.
Implements Rose::Location.
|
overridevirtual |
Output location to a stream.
The format is the same as the toString method and is not necessarily parsable.
See also, toString.
Implements Rose::Location.
|
overridevirtual |
Convert location to escaped, parsable string.
Returns a string that can be safely emitted to a terminal. The format should also be parsable so the static parse
method in subclasses can create an equal object from the string.
Implements Rose::Location.
|
overridevirtual |
Equality and inequality.
Objects are equal if they are the same type and they point to the same location. Otherwise they are unequal.
The operator== is implemented in the base class only. For the expression a == b
it calls both a.isEqual(b)
and b.isEqual(a)
, returning true only if both tests return true. Subclasses should implement x.isEqual(y)
by dynamic casting y
to the type of x
and returning true if and only if the cast succeeds and x
and y
point to the same location.
The operator!= is implemented in the base class as the complement of operator==.
Implements Rose::Location.
|
overridevirtual |
Implements Rose::Location.
|
overridevirtual |
Implements Rose::Location.
|
overridevirtual |
Implements Rose::Location.
|
overridevirtual |
Implements Rose::Location.
int Rose::BinaryAnalysis::AbstractLocation::compare | ( | const AbstractLocation & | other | ) | const |
Compare two abstract locations.
Returns -1 if this location is less than other
, 1 if this location is greater than other
, or zero if this location is equal to other
.
bool Rose::BinaryAnalysis::AbstractLocation::isRegister | ( | ) | const |
Checks register reference.
Returns true if and only if this abstract location refers to a register. It is impossible for an abstract location to refer to both a register and memory; specifically, this returns false for register-relative memory locations.
bool Rose::BinaryAnalysis::AbstractLocation::isAddress | ( | ) | const |
Checks memory reference.
Returns true if and only if this abstract location refers to memory, either absolute or register-relative. It is impossible for an abstract location to refer to both a register and memory; specifically, this returns false for register locations.
bool Rose::BinaryAnalysis::AbstractLocation::isAbsoluteAddress | ( | ) | const |
True if this is an absolute memory location.
An absolute memory location has a memory address but no base register. This predicate implies isAddress.
bool Rose::BinaryAnalysis::AbstractLocation::isRelativeAddress | ( | ) | const |
True if this is a register-relative memory location.
A register-relative memory location consists of a register (the base register) and an address, but the address is relative to the contents of the base register. For example, if the base register is the stack pointer and the address is the constant 8, then the absolute address is formed by adding 8 to the contents of the base register.
RegisterDictionaryPtr Rose::BinaryAnalysis::AbstractLocation::registerDictionary | ( | ) | const |
Property: Register dictionary.
This is a read-only property that's initialized by the constructor.
RegisterDescriptor Rose::BinaryAnalysis::AbstractLocation::getRegister | ( | ) | const |
Returns register.
Returns the register to which this abstract location refers. This returns a valid register descriptor for register locations and for register-relative memory locations.
const Address Rose::BinaryAnalysis::AbstractLocation::getAddress | ( | ) | const |
Returns memory absolute address.
Returns the memory address to which this abstract location refers. When called for an abstract location for which isAbsoluteAddress returns false, the return value is a null pointer.
const Address Rose::BinaryAnalysis::AbstractLocation::getOffset | ( | ) | const |
Returns the memory offset.
Returns the offset from the base register to which this abstract location refers. When called for an abstract location for which isRelativeAddress returns false, the return value is a null pointer.
size_t Rose::BinaryAnalysis::AbstractLocation::nBytes | ( | ) | const |
Returns size of memory location in bytes.
Returns the size of the memory location in bytes if known, otherwise zero. It is not valid to call this for an abstract location that points to a register since registers are not always a multiple of the byte size.
bool Rose::BinaryAnalysis::AbstractLocation::mayAlias | ( | const AbstractLocation & | other, |
const SmtSolverPtr & | solver = SmtSolverPtr() |
||
) | const |
True if two abstract locations could be aliases.
Two abstract locations are aliases if they refer to the exact same register or memory address. By this definition, the AX and EAX registers in x86 are not aliases because they do not refer to the exact same register (one is 16 bits and the other is 32 bits, although the low-order 16 bits are aliases). Likewise, memory addresses are assumed to refer to 8 bit values and two memory addresses are aliases only when they might be equal.
Since memory addresses may be symbolic, this function uses an SMT solver to return true if and only if equality of two addresses is satisfiable.
bool Rose::BinaryAnalysis::AbstractLocation::mustAlias | ( | const AbstractLocation & | other, |
const SmtSolverPtr & | solver = SmtSolverPtr() |
||
) | const |
True if two abstract locations are certainly aliases.
Two abstract locations are aliases if they refer to the exact same register or memory address. By this definition, the AX and EAX registers in x86 are not aliases because they do not refer to the exact same register (one is 16 bits and the other is 32 bits, although the low-order 16 bits are aliases). Likewise, memory addresses are assumed to refer to 8 bit values and two memory addresses are aliases only when they are equal.
Since memory addresses may be symbolic, this function uses an SMT solver to return true if and only if the inequality of two addresses is unsatisfiable.
void Rose::BinaryAnalysis::AbstractLocation::print | ( | std::ostream & | out, |
const RegisterDictionaryPtr & | regdict | ||
) | const |
Print an abstract location.
The optional register dictionary is used for register names, the optional formatter is used for memory address expressions.
void Rose::BinaryAnalysis::AbstractLocation::print | ( | std::ostream & | out, |
InstructionSemantics::BaseSemantics::Formatter & | fmt | ||
) | const |
Print an abstract location.
The optional register dictionary is used for register names, the optional formatter is used for memory address expressions.
void Rose::BinaryAnalysis::AbstractLocation::print | ( | std::ostream & | out, |
const RegisterDictionaryPtr & | regdict, | ||
InstructionSemantics::BaseSemantics::Formatter & | fmt | ||
) | const |
Print an abstract location.
The optional register dictionary is used for register names, the optional formatter is used for memory address expressions.