ROSE  0.9.11.145
BinaryBestMapAddress.h
1 #ifndef ROSE_BinaryAnalysis_BestMapAddress
2 #define ROSE_BinaryAnalysis_BestMapAddress
3 
4 #include <Diagnostics.h>
5 #include <Partitioner2/Engine.h>
6 #include <Progress.h>
7 #include <RoseException.h>
8 #include <Sawyer/Set.h>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 
21 public:
23  class Exception: public Rose::Exception {
24  public:
26  explicit Exception(const std::string &mesg)
27  : Rose::Exception(mesg) {}
28 
30  ~Exception() throw () {}
31  };
32 
35 
37  static Diagnostics::Facility mlog;
38 
39 private:
40  typedef Sawyer::Container::Map<size_t /*nMatches*/, std::vector<rose_addr_t>/*deltas*/> MatchedDeltas;
41 
42  AddressSet entryVas_; // set of function entry virtual addresses
43  AddressSet targetVas_; // set of call target (callee) addresses
44  MatchedDeltas results_; // results of analyze() call
45  bool upToDate_; // are results_ up-to-date w.r.t. address sets?
46  size_t maxMatches_; // maximum number of matches possible for results_
47  size_t nBits_; // number of bits in an address
48  Progress::Ptr progress_; // for progress reporting
49 
50 public:
53  : upToDate_(true), maxMatches_(0), nBits_(0), progress_(Progress::instance()) {}
54 
62  void reset() {
63  entryVas_.clear();
64  targetVas_.clear();
65  results_.clear();
66  maxMatches_ = 0;
67  upToDate_ = true;
68  }
69 
73  static void initDiagnostics();
74 
81  Progress::Ptr progress() const { return progress_; }
82  void progress(const Progress::Ptr &p) { progress_ = p; }
97  size_t nBits() const { return nBits_; }
98  void nBits(size_t n);
105  rose_addr_t mask() const;
106 
116 
120  void insertEntryAddress(rose_addr_t va) {
121  if (entryVas_.insert(va))
122  upToDate_ = false;
123  }
124 
129  void insertTargetAddress(rose_addr_t va) {
130  if (targetVas_.insert(va))
131  upToDate_ = false;
132  }
133 
135  const AddressSet& entryAddresses() const {
136  return entryVas_;
137  }
138 
140  const AddressSet& targetAddresses() const {
141  return targetVas_;
142  }
143 
157  BestMapAddress& analyze(const AddressInterval &restrictEntryAddresses = AddressInterval::whole(),
158  const AddressInterval &restrictTargetAddresses = AddressInterval::whole());
159 
164  const std::vector<rose_addr_t>& bestDeltas() const;
165 
171  double bestDeltaRatio() const;
172 
177  static MemoryMap::Ptr align(const MemoryMap::Ptr&,
180 };
181 
182 } // namespace
183 } // namespace
184 
185 #endif
void reset()
Clear gathered addresses.
void insertEntryAddress(rose_addr_t va)
Insert a function entry address.
static void initDiagnostics()
Initialize diagnostic streams.
void clear()
Erase all values.
Definition: Set.h:262
Finds best address for mapping code.
bool insert(const Value &value)
Insert a value.
Definition: Set.h:222
Base class for engines driving the partitioner.
Definition: Engine.h:111
static Diagnostics::Facility mlog
Facility for emitting diagnostics.
static MemoryMap::Ptr align(const MemoryMap::Ptr &, const Partitioner2::Engine::Settings &settings=Partitioner2::Engine::Settings(), const Progress::Ptr &progress=Progress::Ptr())
Align executable regions of a memory map.
double bestDeltaRatio() const
How well the best shift amounts performed.
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.
Main namespace for the ROSE library.
Map & clear()
Remove all nodes.
Definition: Sawyer/Map.h:680
const std::vector< rose_addr_t > & bestDeltas() const
Return the best shift amounts.
void gatherAddresses(Partitioner2::Engine &engine)
Gather addresses for future analysis.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of addresses.
size_t nBits() const
Property: Number of bits in an address.
void progress(const Progress::Ptr &p)
Property: Progress reporter.
void insertTargetAddress(rose_addr_t va)
Insert a call target address.
static Interval whole()
Construct an interval that covers the entire domain.
Definition: Interval.h:167
Progress::Ptr progress() const
Property: Progress reporter.
A general, thread-safe way to report progress made on some task.
Definition: Progress.h:164
Exception(const std::string &mesg)
Construct an exception with a message.
Base class for all ROSE exceptions.
Definition: RoseException.h:9
const AddressSet & entryAddresses() const
Returns set of entry addresses.
Container associating values with keys.
Definition: Sawyer/Map.h:66
rose_addr_t mask() const
Property: Mask to use when doing address arithmetic.
BestMapAddress()
Construct an empty analysis.