ROSE 0.11.145.192
BestMapAddress.h
1#ifndef ROSE_BinaryAnalysis_BestMapAddress_H
2#define ROSE_BinaryAnalysis_BestMapAddress_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/Diagnostics.h>
7#include <Rose/BinaryAnalysis/Partitioner2/Engine.h>
8#include <Rose/Progress.h>
9#include <Rose/Exception.h>
10#include <Sawyer/Set.h>
11
12namespace Rose {
13namespace BinaryAnalysis {
14
23public:
25 class Exception: public Rose::Exception {
26 public:
28 explicit Exception(const std::string &mesg)
29 : Rose::Exception(mesg) {}
30
32 ~Exception() throw () {}
33 };
34
37
40
45
46private:
47 typedef Sawyer::Container::Map<size_t /*nMatches*/, std::vector<rose_addr_t>/*deltas*/> MatchedDeltas;
48
49 Settings settings_;
50 AddressSet entryVas_; // set of function entry virtual addresses
51 AddressSet targetVas_; // set of call target (callee) addresses
52 MatchedDeltas results_; // results of analyze() call
53 bool upToDate_; // are results_ up-to-date w.r.t. address sets?
54 size_t maxMatches_; // maximum number of matches possible for results_
55 size_t nBits_; // number of bits in an address
56 Progress::Ptr progress_; // for progress reporting
57
58public:
61 : upToDate_(true), maxMatches_(0), nBits_(0), progress_(Progress::instance()) {}
62
66 const Settings& settings() const {
67 return settings_;
68 }
70 return settings_;
71 }
81 void reset() {
82 entryVas_.clear();
83 targetVas_.clear();
84 results_.clear();
85 maxMatches_ = 0;
86 upToDate_ = true;
87 }
88
92 static void initDiagnostics();
93
100 Progress::Ptr progress() const { return progress_; }
101 void progress(const Progress::Ptr &p) { progress_ = p; }
116 size_t nBits() const { return nBits_; }
117 void nBits(size_t n);
124 rose_addr_t mask() const;
125
135
139 void insertEntryAddress(rose_addr_t va) {
140 if (entryVas_.insert(va))
141 upToDate_ = false;
142 }
143
148 void insertTargetAddress(rose_addr_t va) {
149 if (targetVas_.insert(va))
150 upToDate_ = false;
151 }
152
154 const AddressSet& entryAddresses() const {
155 return entryVas_;
156 }
157
160 return targetVas_;
161 }
162
177 const AddressInterval &restrictTargetAddresses = AddressInterval::whole());
178
183 const std::vector<rose_addr_t>& bestDeltas() const;
184
190 double bestDeltaRatio() const;
191
199};
200
201} // namespace
202} // namespace
203
204#endif
205#endif
Exception(const std::string &mesg)
Construct an exception with a message.
Finds best address for mapping code.
void reset()
Clear gathered addresses.
void gatherAddresses(Partitioner2::Engine &engine)
Gather addresses for future analysis.
void progress(const Progress::Ptr &p)
Property: Progress reporter.
Progress::Ptr progress() const
Property: Progress reporter.
void nBits(size_t n)
Property: Number of bits in an address.
static Diagnostics::Facility mlog
Facility for emitting diagnostics.
BestMapAddress & analyze(const AddressInterval &restrictEntryAddresses=AddressInterval::whole(), const AddressInterval &restrictTargetAddresses=AddressInterval::whole())
Analyze the addresses that have been provided.
void insertEntryAddress(rose_addr_t va)
Insert a function entry address.
double bestDeltaRatio() const
How well the best shift amounts performed.
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.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of addresses.
size_t nBits() const
Property: Number of bits in an address.
BestMapAddress()
Construct an empty analysis.
static void initDiagnostics()
Initialize diagnostic streams.
const AddressSet & entryAddresses() const
Returns set of entry addresses.
const Settings & settings() const
Settings.
const AddressSet & targetAddresses() const
Returns set of target addresses.
rose_addr_t mask() const
Property: Mask to use when doing address arithmetic.
void insertTargetAddress(rose_addr_t va)
Insert a call target address.
const std::vector< rose_addr_t > & bestDeltas() const
Return the best shift amounts.
Base class for engines driving the partitioner.
Base class for all ROSE exceptions.
A general, thread-safe way to report progress made on some task.
Definition Progress.h:167
static Interval whole()
Construct an interval that covers the entire domain.
Definition Interval.h:191
Container associating values with keys.
Definition Sawyer/Map.h:72
Map & clear()
Remove all nodes.
Definition Sawyer/Map.h:732
Ordered set of values.
Definition Set.h:56
bool insert(const Value &value)
Insert a value.
Definition Set.h:258
void clear()
Erase all values.
Definition Set.h:298
Collection of streams.
Definition Message.h:1606
Holds a value or nothing.
Definition Optional.h:56
The ROSE library.
Settings to control the analysis.
Sawyer::Optional< size_t > nThreads
Number of threads to use, overriding the global setting.