Ghidra Decompiler Analysis Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
Address Class Reference

A low-level machine address for labelling bytes and data. More...

#include <address.hh>

Collaboration diagram for Address:
Collaboration graph
[legend]

Public Types

enum  mach_extreme { m_minimal, m_maximal }
 An enum for specifying extremal addresses. More...
 

Public Member Functions

 Address (mach_extreme ex)
 Initialize an extremal address. More...
 
 Address (void)
 Create an invalid address. More...
 
 Address (AddrSpace *id, uintb off)
 Construct an address with a space/offset pair. More...
 
 Address (const Address &op2)
 A copy constructor. More...
 
bool isInvalid (void) const
 Is the address invalid? More...
 
int4 getAddrSize (void) const
 Get the number of bytes in the address. More...
 
bool isBigEndian (void) const
 Is data at this address big endian encoded. More...
 
void printRaw (ostream &s) const
 Write a raw version of the address to a stream. More...
 
int4 read (const string &s)
 Read in the address from a string. More...
 
AddrSpacegetSpace (void) const
 Get the address space. More...
 
uintb getOffset (void) const
 Get the address offset. More...
 
void toPhysical (void)
 Convert this to a physical address. More...
 
char getShortcut (void) const
 Get the shortcut character for the address space. More...
 
Addressoperator= (const Address &op2)
 Copy an address. More...
 
bool operator== (const Address &op2) const
 Compare two addresses for equality. More...
 
bool operator!= (const Address &op2) const
 Compare two addresses for inequality. More...
 
bool operator< (const Address &op2) const
 Compare two addresses via their natural ordering. More...
 
bool operator<= (const Address &op2) const
 Compare two addresses via their natural ordering. More...
 
Address operator+ (int4 off) const
 Increment address by a number of bytes. More...
 
Address operator- (int4 off) const
 Decrement address by a number of bytes. More...
 
bool containedBy (int4 sz, const Address &op2, int4 sz2) const
 Determine if op2 range contains this range. More...
 
int4 justifiedContain (int4 sz, const Address &op2, int4 sz2, bool forceleft) const
 Determine if op2 is the least significant part of this. More...
 
int4 overlap (int4 skip, const Address &op, int4 size) const
 Determine how two address ranges overlap. More...
 
bool isContiguous (int4 sz, const Address &loaddr, int4 losz) const
 Does this form a contigous range with loaddr. More...
 
bool isConstant (void) const
 Is this a constant value. More...
 
void renormalize (int4 size)
 Make sure there is a backing JoinRecord if this is in the join space. More...
 
bool isJoin (void) const
 Is this a join value. More...
 
void saveXml (ostream &s) const
 Save this to a stream as an XML tag. More...
 
void saveXml (ostream &s, int4 size) const
 Save this and a size to a stream as an XML tag. More...
 

Static Public Member Functions

static Address restoreXml (const Element *el, const AddrSpaceManager *manage)
 Restore an address from parsed XML. More...
 
static Address restoreXml (const Element *el, const AddrSpaceManager *manage, int4 &size)
 Restore an address and size from parsed XML. More...
 
static AddrSpacegetSpaceFromConst (const Address &addr)
 Recover an encoded address space from an address. More...
 

Protected Attributes

AddrSpacebase
 Pointer to our address space.
 
uintb offset
 Offset (in bytes)
 

Friends

ostream & operator<< (ostream &s, const Address &addr)
 Write out an address to stream. More...
 

Detailed Description

A low-level machine address for labelling bytes and data.

All data that can be manipulated within the processor reverse engineering model can be labelled with an Address. It is simply an address space (AddrSpace) and an offset within that space. Note that processor registers are typically modelled by creating a dedicated address space for them, as distinct from RAM say, and then specifying certain addresses within the register space that correspond to particular registers. However, an arbitrary address could refer to anything, RAM, ROM, cpu register, data segment, coprocessor, stack, nvram, etc. An Address represents an offset only, not an offset and length

Member Enumeration Documentation

◆ mach_extreme

An enum for specifying extremal addresses.

Enumerator
m_minimal 

Smallest possible address.

m_maximal 

Biggest possible address.

Constructor & Destructor Documentation

◆ Address() [1/4]

Address::Address ( mach_extreme  ex)

Initialize an extremal address.

Some data structures sort on an Address, and it is convenient to be able to create an Address that is either bigger than or smaller than all other Addresses.

Parameters
exis either m_minimal or m_maximal

◆ Address() [2/4]

Address::Address ( void  )
inline

Create an invalid address.

An invalid address is possible in some circumstances. This deliberately constructs an invalid address

◆ Address() [3/4]

Address::Address ( AddrSpace id,
uintb  off 
)
inline

Construct an address with a space/offset pair.

This is the basic Address constructor

Parameters
idis the space containing the address
offis the offset of the address

◆ Address() [4/4]

Address::Address ( const Address op2)
inline

A copy constructor.

This is a standard copy constructor, copying the address space and the offset

Parameters
op2is the Address to copy

Member Function Documentation

◆ containedBy()

bool Address::containedBy ( int4  sz,
const Address op2,
int4  sz2 
) const

Determine if op2 range contains this range.

Return true if the range starting at this extending the given number of bytes is contained by the second given range.

Parameters
szis the given number of bytes in this range
op2is the start of the second given range
sz2is the number of bytes in the second given range
Returns
true if the second given range contains this range

◆ getAddrSize()

int4 Address::getAddrSize ( void  ) const
inline

Get the number of bytes in the address.

Get the number of bytes needed to encode the offset for this address.

Returns
the number of bytes in the encoding

◆ getOffset()

uintb Address::getOffset ( void  ) const
inline

Get the address offset.

Get the offset of the address as an integer.

Returns
the offset integer

◆ getShortcut()

char Address::getShortcut ( void  ) const
inline

Get the shortcut character for the address space.

Each address has a shortcut character associated with it for use with the read and printRaw methods.

Returns
the shortcut char

◆ getSpace()

AddrSpace * Address::getSpace ( void  ) const
inline

Get the address space.

Get the address space associated with this address.

Returns
the AddressSpace pointer, or NULL if invalid

◆ getSpaceFromConst()

AddrSpace * Address::getSpaceFromConst ( const Address addr)
inlinestatic

Recover an encoded address space from an address.

In LOAD and STORE instructions, the particular address space being read/written is encoded as a constant input parameter to the instruction. Internally, this constant is the actual pointer to the AddrSpace. This function allows the encoded pointer to be recovered from the address it is encoded in.

Parameters
addris the Address encoding the pointer
Returns
the AddrSpace pointer

◆ isBigEndian()

bool Address::isBigEndian ( void  ) const
inline

Is data at this address big endian encoded.

Determine if data stored at this address is big endian encoded.

Returns
true if the address is big endian

◆ isConstant()

bool Address::isConstant ( void  ) const
inline

Is this a constant value.

Determine if this address is from the constant space. All constant values are represented as an offset into the constant space.

Returns
true if this address represents a constant

◆ isContiguous()

bool Address::isContiguous ( int4  sz,
const Address loaddr,
int4  losz 
) const

Does this form a contigous range with loaddr.

Does the location this, sz form a contiguous region to loaddr, losz, where this forms the most significant piece of the logical whole

Parameters
szis the size of this hi region
loaddris the starting address of the low region
loszis the size of the low region
Returns
true if the pieces form a contiguous whole

◆ isInvalid()

bool Address::isInvalid ( void  ) const
inline

Is the address invalid?

Determine if this is an invalid address. This only detects deliberate invalid addresses.

Returns
true if the address is invalid

◆ isJoin()

bool Address::isJoin ( void  ) const
inline

Is this a join value.

Determine if this address represents a set of joined memory locations.

Returns
true if this address represents a join

◆ justifiedContain()

int4 Address::justifiedContain ( int4  sz,
const Address op2,
int4  sz2,
bool  forceleft 
) const

Determine if op2 is the least significant part of this.

Return -1 if (op2,sz2) is not properly contained in (this,sz). If it is contained, return the endian aware offset of (op2,sz2) I.e. if the least significant byte of the op2 range falls on the least significant byte of the this range, return 0. If it intersects the second least significant, return 1, etc. The -forceleft- toggle causes the check to be made against the left (lowest address) side of the container, regardless of the endianness. I.e. it forces a little endian interpretation.

Parameters
szis the size of this range
op2is the address of the second range
sz2is the size of the second range
forceleftis true if containments is forced to be on the left even for big endian
Returns
the endian aware offset, or -1

◆ operator!=()

bool Address::operator!= ( const Address op2) const
inline

Compare two addresses for inequality.

Check if two addresses are not equal. I.e. if either their address space or offset are different.

Parameters
op2is the address to compare to this
Returns
true if the addresses are different

◆ operator+()

Address Address::operator+ ( int4  off) const
inline

Increment address by a number of bytes.

Add an integer value to the offset portion of the address. The addition takes into account the size of the address space, and the Address will wrap around if necessary.

Parameters
offis the number to add to the offset
Returns
the new incremented address

◆ operator-()

Address Address::operator- ( int4  off) const
inline

Decrement address by a number of bytes.

Subtract an integer value from the offset portion of the address. The subtraction takes into account the size of the address space, and the Address will wrap around if necessary.

Parameters
offis the number to subtract from the offset
Returns
the new decremented address

◆ operator<()

bool Address::operator< ( const Address op2) const
inline

Compare two addresses via their natural ordering.

Do an ordering comparison of two addresses. Addresses are sorted first on space, then on offset. So two addresses in the same space compare naturally based on their offset, but addresses in different spaces also compare. Different spaces are ordered by their index.

Parameters
op2is the address to compare to
Returns
true if this comes before op2

◆ operator<=()

bool Address::operator<= ( const Address op2) const
inline

Compare two addresses via their natural ordering.

Do an ordering comparison of two addresses.

Parameters
op2is the address to compare to
Returns
true if this comes before or is equal to op2

◆ operator=()

Address & Address::operator= ( const Address op2)
inline

Copy an address.

This is a standard assignment operator, copying the address space pointer and the offset

Parameters
op2is the Address being assigned
Returns
a reference to altered address

◆ operator==()

bool Address::operator== ( const Address op2) const
inline

Compare two addresses for equality.

Check if two addresses are equal. I.e. if their address space and offset are the same.

Parameters
op2is the address to compare to this
Returns
true if the addresses are the same

◆ overlap()

int4 Address::overlap ( int4  skip,
const Address op,
int4  size 
) const

Determine how two address ranges overlap.

If this + skip falls in the range op to op + size, then a non-negative integer is returned indicating where in the interval it falls. I.e. if this + skip == op, then 0 is returned. Otherwise -1 is returned.

Parameters
skipis an adjust to this address
opis the start of the range to check
sizeis the size of the range
Returns
an integer indicating how overlap occurs

◆ printRaw()

void Address::printRaw ( ostream &  s) const
inline

Write a raw version of the address to a stream.

Write a short-hand or debug version of this address to a stream.

Parameters
sis the stream being written

◆ read()

int4 Address::read ( const string &  s)
inline

Read in the address from a string.

Convert a string into an address. The string format can be tailored for the particular address space.

Parameters
sis the string to parse
Returns
any size associated with the parsed string

◆ renormalize()

void Address::renormalize ( int4  size)

Make sure there is a backing JoinRecord if this is in the join space.

If this is (originally) a join address, reevaluate it in terms of its new offset and siz, changing the space and offset if necessary.

Parameters
sizeis the new size in bytes of the underlying object

◆ restoreXml() [1/2]

Address Address::restoreXml ( const Element el,
const AddrSpaceManager manage 
)
static

Restore an address from parsed XML.

This is usually used to build an address from an <addr> tag, but it can be used to create an address from any tag with the appropriate attributes

  • space indicates the address space of the tag
  • offset indicates the offset within the space

or a name attribute can be used to recover an address based on a register name.

Parameters
elis the parsed tag
manageis the address space manager for the program
Returns
the resulting Address

◆ restoreXml() [2/2]

Address Address::restoreXml ( const Element el,
const AddrSpaceManager manage,
int4 &  size 
)
static

Restore an address and size from parsed XML.

This is usually used to build an address from an <addr> tag, but it can be used to create an address from any tag with the appropriate attributes

  • space indicates the address space of the tag
  • offset indicates the offset within the space
  • size indicates the size of an address range

or a name attribute can be used to recover an address and size based on a register name. If a size is recovered it is stored in size reference.

Parameters
elis the parsed tag
manageis the address space manager for the program
sizeis the reference to any recovered size
Returns
the resulting Address

◆ saveXml() [1/2]

void Address::saveXml ( ostream &  s) const
inline

Save this to a stream as an XML tag.

Save an <addr> tag corresponding to this address to a stream. The exact format is determined by the address space, but this generally has a space and an offset attribute.

Parameters
sis the stream being written to

◆ saveXml() [2/2]

void Address::saveXml ( ostream &  s,
int4  size 
) const
inline

Save this and a size to a stream as an XML tag.

Save an <addr> tag corresponding to this address to a stream. The tag will also include an extra size attribute so that it can describe an entire memory range.

Parameters
sis the stream being written to
sizeis the number of bytes in the range

◆ toPhysical()

void Address::toPhysical ( void  )

Convert this to a physical address.

Deprecated:
Convert this to the most basic physical address. This routine is only present for backward compatibility with SLED

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  s,
const Address addr 
)
friend

Write out an address to stream.

This allows an Address to be written to a stream using the standard '<<' operator. This is a wrapper for the printRaw method and is intended for debugging and console mode uses.

Parameters
sis the stream being written to
addris the Address to write
Returns
the output stream

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