ROSE 0.11.145.192
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Rose::BinaryAnalysis::BestMapAddress Class Reference

Description

Finds best address for mapping code.

This analysis looks at function addresses and function calls to create two lists of addresses: entry addresses and target addresses, respectively. Only function calls using absolute addressing are considered. It then calculates how much the set of entry addresses should be shifted up or down in memory in order to best line up with target addresses. The assumption is that most of the function calls found by disassembling refer to functions that were also disassembled, and that by shifting the entire executable to higher or lower addresses we can get these to match up.

Definition at line 22 of file BestMapAddress.h.

#include <Rose/BinaryAnalysis/BestMapAddress.h>

Collaboration diagram for Rose::BinaryAnalysis::BestMapAddress:
Collaboration graph
[legend]

Classes

class  Exception
 Exceptions for this analysis. More...
 
struct  Settings
 Settings to control the analysis. More...
 

Public Types

typedef Sawyer::Container::Set< rose_addr_t > AddressSet
 Set of addresses.
 

Public Member Functions

 BestMapAddress ()
 Construct an empty analysis.
 
void reset ()
 Clear gathered addresses.
 
rose_addr_t mask () const
 Property: Mask to use when doing address arithmetic.
 
void gatherAddresses (Partitioner2::Engine &engine)
 Gather addresses for future analysis.
 
void insertEntryAddress (rose_addr_t va)
 Insert a function entry address.
 
void insertTargetAddress (rose_addr_t va)
 Insert a call target address.
 
const AddressSetentryAddresses () const
 Returns set of entry addresses.
 
const AddressSettargetAddresses () const
 Returns set of target addresses.
 
BestMapAddressanalyze (const AddressInterval &restrictEntryAddresses=AddressInterval::whole(), const AddressInterval &restrictTargetAddresses=AddressInterval::whole())
 Analyze the addresses that have been provided.
 
const std::vector< rose_addr_t > & bestDeltas () const
 Return the best shift amounts.
 
double bestDeltaRatio () const
 How well the best shift amounts performed.
 
const Settingssettings () const
 Settings.
 
Settingssettings ()
 Settings.
 
Progress::Ptr progress () const
 Property: Progress reporter.
 
void progress (const Progress::Ptr &p)
 Property: Progress reporter.
 
size_t nBits () const
 Property: Number of bits in an address.
 
void nBits (size_t n)
 Property: Number of bits in an address.
 

Static Public Member Functions

static void initDiagnostics ()
 Initialize diagnostic streams.
 
static MemoryMapPtr align (const MemoryMapPtr &, const Partitioner2::Engine::Settings &settings=Partitioner2::Engine::Settings(), const Progress::Ptr &progress=Progress::Ptr())
 Align executable regions of a memory map.
 

Static Public Attributes

static Diagnostics::Facility mlog
 Facility for emitting diagnostics.
 

Member Typedef Documentation

◆ AddressSet

Set of addresses.

Definition at line 36 of file BestMapAddress.h.

Constructor & Destructor Documentation

◆ BestMapAddress()

Rose::BinaryAnalysis::BestMapAddress::BestMapAddress ( )
inline

Construct an empty analysis.

Definition at line 60 of file BestMapAddress.h.

Member Function Documentation

◆ settings() [1/2]

const Settings & Rose::BinaryAnalysis::BestMapAddress::settings ( ) const
inline

Settings.

Definition at line 66 of file BestMapAddress.h.

◆ settings() [2/2]

Settings & Rose::BinaryAnalysis::BestMapAddress::settings ( )
inline

Settings.

Definition at line 69 of file BestMapAddress.h.

◆ reset()

void Rose::BinaryAnalysis::BestMapAddress::reset ( )
inline

Clear gathered addresses.

Returns the analysis to its initial state but without clearing any properties that might have been configured. To clear the analysis and reset properties, assign a default constructed analysis.

Note this method is named "reset" instead of "clear" because it doesn't entirely clear the object in the sense that STL "clear" methods clear their objects.

Definition at line 81 of file BestMapAddress.h.

References Sawyer::Container::Map< K, T, Cmp, Alloc >::clear(), and Sawyer::Container::Set< T, C, A >::clear().

◆ initDiagnostics()

static void Rose::BinaryAnalysis::BestMapAddress::initDiagnostics ( )
static

Initialize diagnostic streams.

This is called automatically by Rose::Diagnostics::initialize.

◆ progress() [1/2]

Progress::Ptr Rose::BinaryAnalysis::BestMapAddress::progress ( ) const
inline

Property: Progress reporter.

Optional progress reporter object. If non-null, then some of the long-running methods will update this object with periodic progress reports.

Definition at line 100 of file BestMapAddress.h.

◆ progress() [2/2]

void Rose::BinaryAnalysis::BestMapAddress::progress ( const Progress::Ptr p)
inline

Property: Progress reporter.

Optional progress reporter object. If non-null, then some of the long-running methods will update this object with periodic progress reports.

Definition at line 101 of file BestMapAddress.h.

◆ nBits() [1/2]

size_t Rose::BinaryAnalysis::BestMapAddress::nBits ( ) const
inline

Property: Number of bits in an address.

This analysis represents address deltas using the same C data type as addresses, namely rose_addr_t. Therefore, the analysis needs to know the total size of the address space in order to represent negative deltas. The address space size is stored as a power of two.

Functions that have enough information to determine the address space size (such as from a partitioner engine), set this property as part of their operation.

Returns zero if the address size is not yet known. An address space of size one is never valid.

Definition at line 116 of file BestMapAddress.h.

◆ nBits() [2/2]

void Rose::BinaryAnalysis::BestMapAddress::nBits ( size_t  n)

Property: Number of bits in an address.

This analysis represents address deltas using the same C data type as addresses, namely rose_addr_t. Therefore, the analysis needs to know the total size of the address space in order to represent negative deltas. The address space size is stored as a power of two.

Functions that have enough information to determine the address space size (such as from a partitioner engine), set this property as part of their operation.

Returns zero if the address size is not yet known. An address space of size one is never valid.

◆ mask()

rose_addr_t Rose::BinaryAnalysis::BestMapAddress::mask ( ) const

Property: Mask to use when doing address arithmetic.

This is the bit mask to use for doing address arithmetic. It has the N low-order bits set, where N is the number of bits stored in the nBits property.

◆ gatherAddresses()

void Rose::BinaryAnalysis::BestMapAddress::gatherAddresses ( Partitioner2::Engine engine)

Gather addresses for future analysis.

Given a configured partitioning engine with a memory map already defined, disassemble and partition the executable areas of the map that fall within the specified interval and create the two lists of addresses used by future analysis. See the class description for details about these lists.

Although calls to this method can be expensive, the progress report associated with this analyzer (if any) is not used; rather, the progress reporting associated with the engine is used instead.

◆ insertEntryAddress()

void Rose::BinaryAnalysis::BestMapAddress::insertEntryAddress ( rose_addr_t  va)
inline

Insert a function entry address.

Inserts a function entry address into the set of addresses that will be used during later analysis.

Definition at line 139 of file BestMapAddress.h.

References Sawyer::Container::Set< T, C, A >::insert().

◆ insertTargetAddress()

void Rose::BinaryAnalysis::BestMapAddress::insertTargetAddress ( rose_addr_t  va)
inline

Insert a call target address.

Insert the target address (i.e., the callee) of a function call into the set of addresses that will be used during later analysis.

Definition at line 148 of file BestMapAddress.h.

References Sawyer::Container::Set< T, C, A >::insert().

◆ entryAddresses()

const AddressSet & Rose::BinaryAnalysis::BestMapAddress::entryAddresses ( ) const
inline

Returns set of entry addresses.

Definition at line 154 of file BestMapAddress.h.

◆ targetAddresses()

const AddressSet & Rose::BinaryAnalysis::BestMapAddress::targetAddresses ( ) const
inline

Returns set of target addresses.

Definition at line 159 of file BestMapAddress.h.

◆ analyze()

BestMapAddress & Rose::BinaryAnalysis::BestMapAddress::analyze ( const AddressInterval restrictEntryAddresses = AddressInterval::whole(),
const AddressInterval restrictTargetAddresses = AddressInterval::whole() 
)

Analyze the addresses that have been provided.

Analyses all the previously provided addresses to find the best amounts by which to shift the entry addresses so they line up with the target addresses. Only those entry addresses and target addresses that fall within the specified intervals are used.

This method operates in parallel according to the global setting for the number of threads. That property is normally configured with the –threads command-line switch and stored in CommandLine::GenericSwitchArgs::threads.

If a progress reporting object has been configured for this analysis, then this method periodically updates it with progress reports.

Returns a reference to the analysis object for easy chaining to a query.

◆ bestDeltas()

const std::vector< rose_addr_t > & Rose::BinaryAnalysis::BestMapAddress::bestDeltas ( ) const

Return the best shift amounts.

Returns a list of the best shift amounts. Usually this is a single value, but in the case when multiple shift amounts tie for best, they're all returned.

◆ bestDeltaRatio()

double Rose::BinaryAnalysis::BestMapAddress::bestDeltaRatio ( ) const

How well the best shift amounts performed.

Returns a ratio between zero and one, inclusive, that indicates how will the best deltas performed. A return value of zero means that shifting the functions by any of the best deltas caused none of the function call targets to line up with functions, and a return value of one means all of them line up.

◆ align()

static MemoryMapPtr Rose::BinaryAnalysis::BestMapAddress::align ( const MemoryMapPtr ,
const Partitioner2::Engine::Settings settings = Partitioner2::Engine::Settings(),
const Progress::Ptr progress = Progress::Ptr() 
)
static

Align executable regions of a memory map.

Runs the BestMapAddress repeatedly on the specified memory map in order to create a new map with the executable regions of the input map moved to better addresses.

Member Data Documentation

◆ mlog

Diagnostics::Facility Rose::BinaryAnalysis::BestMapAddress::mlog
static

Facility for emitting diagnostics.

Definition at line 39 of file BestMapAddress.h.


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