ROSE 0.11.145.281
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Rose::BinaryAnalysis::AbstractLocation Class Reference

Description

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:

using namespace Rose::BinaryAnalysis;
AbstractLocation aloc1(REG_EAX); // REG_EAX is a RegisterDescriptor
AbstractLocation aloc2(addr); // addr is an SValuePtr for the symbolic semantics domain
AbstractLocation aloc3(REG_SP, offset); // addr is an SValuePtr offset from the contents of the stack pointer register
Binary analysis.

Abstract locations are immutable objects.

See also, ConcreteLocation.

Definition at line 34 of file AbstractLocation.h.

#include <Rose/BinaryAnalysis/AbstractLocation.h>

Inheritance diagram for Rose::BinaryAnalysis::AbstractLocation:
Inheritance graph
[legend]
Collaboration diagram for Rose::BinaryAnalysis::AbstractLocation:
Collaboration graph
[legend]

Public Types

using Address = InstructionSemantics::BaseSemantics::SValuePtr
 Type of memory address.
 

Public Member Functions

 AbstractLocation ()
 Default constructor.
 
 AbstractLocation (const AbstractLocation &)
 Copy constructor.
 
AbstractLocationoperator= (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 &regdict)
 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 &regdict) 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 &regdict, InstructionSemantics::BaseSemantics::Formatter &fmt) const
 Print an abstract location.
 
- Public Member Functions inherited from Rose::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.
 

Member Typedef Documentation

◆ Address

Type of memory address.

Definition at line 36 of file AbstractLocation.h.

Constructor & Destructor Documentation

◆ AbstractLocation() [1/6]

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.

◆ AbstractLocation() [2/6]

Rose::BinaryAnalysis::AbstractLocation::AbstractLocation ( RegisterDescriptor  )
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.

◆ AbstractLocation() [3/6]

Rose::BinaryAnalysis::AbstractLocation::AbstractLocation ( RegisterDescriptor  ,
const RegisterDictionaryPtr regdict 
)
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.

◆ AbstractLocation() [4/6]

Rose::BinaryAnalysis::AbstractLocation::AbstractLocation ( const Address ,
size_t  nBytes = 0 
)
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.

◆ AbstractLocation() [5/6]

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.

◆ AbstractLocation() [6/6]

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.

Member Function Documentation

◆ isValid()

virtual bool Rose::BinaryAnalysis::AbstractLocation::isValid ( ) const
overridevirtual

Test whether this object is valid.

Implements Rose::Location.

◆ hash()

virtual uint64_t Rose::BinaryAnalysis::AbstractLocation::hash ( ) const
overridevirtual

Compute a 64-bit hash of this object.

Implements Rose::Location.

◆ toString()

virtual std::string Rose::BinaryAnalysis::AbstractLocation::toString ( ) const
overridevirtual

Convert location to string.

Returns a string representation of the location. This representation is not necessarily parsable.

See also, print.

Implements Rose::Location.

◆ print() [1/4]

virtual void Rose::BinaryAnalysis::AbstractLocation::print ( std::ostream &  ) const
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.

◆ printableName()

virtual std::string Rose::BinaryAnalysis::AbstractLocation::printableName ( ) const
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.

◆ isEqual()

virtual bool Rose::BinaryAnalysis::AbstractLocation::isEqual ( const Location other) const
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.

◆ operator<()

virtual bool Rose::BinaryAnalysis::AbstractLocation::operator< ( const Location ) const
overridevirtual

Implements Rose::Location.

◆ operator<=()

virtual bool Rose::BinaryAnalysis::AbstractLocation::operator<= ( const Location ) const
overridevirtual

Implements Rose::Location.

◆ operator>()

virtual bool Rose::BinaryAnalysis::AbstractLocation::operator> ( const Location ) const
overridevirtual

Implements Rose::Location.

◆ operator>=()

virtual bool Rose::BinaryAnalysis::AbstractLocation::operator>= ( const Location ) const
overridevirtual

Implements Rose::Location.

◆ compare()

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.

◆ isRegister()

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.

◆ isAddress()

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.

◆ isAbsoluteAddress()

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.

◆ isRelativeAddress()

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.

◆ registerDictionary()

RegisterDictionaryPtr Rose::BinaryAnalysis::AbstractLocation::registerDictionary ( ) const

Property: Register dictionary.

This is a read-only property that's initialized by the constructor.

◆ getRegister()

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.

◆ getAddress()

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.

◆ getOffset()

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.

◆ nBytes()

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.

◆ mayAlias()

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.

◆ mustAlias()

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.

◆ print() [2/4]

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.

◆ print() [3/4]

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.

◆ print() [4/4]

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.


The documentation for this class was generated from the following file: