ROSE 0.11.145.147
|
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>
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 AddressSet & | entryAddresses () const |
Returns set of entry addresses. | |
const AddressSet & | targetAddresses () const |
Returns set of target addresses. | |
BestMapAddress & | analyze (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 Settings & | settings () const |
Settings. | |
Settings & | settings () |
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. | |
typedef Sawyer::Container::Set<rose_addr_t> Rose::BinaryAnalysis::BestMapAddress::AddressSet |
Set of addresses.
Definition at line 36 of file BestMapAddress.h.
|
inline |
Construct an empty analysis.
Definition at line 60 of file BestMapAddress.h.
|
inline |
Definition at line 66 of file BestMapAddress.h.
|
inline |
Definition at line 69 of file BestMapAddress.h.
|
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().
|
static |
Initialize diagnostic streams.
This is called automatically by Rose::Diagnostics::initialize.
|
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.
|
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.
|
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.
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.
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.
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.
|
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().
|
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().
|
inline |
Returns set of entry addresses.
Definition at line 154 of file BestMapAddress.h.
|
inline |
Returns set of target addresses.
Definition at line 159 of file BestMapAddress.h.
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.
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.
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.
|
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.
|
static |
Facility for emitting diagnostics.
Definition at line 39 of file BestMapAddress.h.