ROSE  0.9.9.109
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 <Sawyer/Set.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 
20 public:
22  class Exception: public std::runtime_error {
23  public:
25  explicit Exception(const std::string &mesg)
26  : std::runtime_error(mesg) {}
27 
29  ~Exception() throw () {}
30  };
31 
34 
37 
38 private:
39  typedef Sawyer::Container::Map<size_t /*nMatches*/, std::vector<rose_addr_t>/*deltas*/> MatchedDeltas;
40 
41  AddressSet entryVas_; // set of function entry virtual addresses
42  AddressSet targetVas_; // set of call target (callee) addresses
43  MatchedDeltas results_; // results of analyze() call
44  bool upToDate_; // are results_ up-to-date w.r.t. address sets?
45  size_t maxMatches_; // maximum number of matches possible for results_
46  size_t nBits_; // number of bits in an address
47  Progress::Ptr progress_; // for progress reporting
48 
49 public:
52  : upToDate_(true), maxMatches_(0), nBits_(0), progress_(Progress::instance()) {}
53 
61  void reset() {
62  entryVas_.clear();
63  targetVas_.clear();
64  results_.clear();
65  maxMatches_ = 0;
66  upToDate_ = true;
67  }
68 
72  static void initDiagnostics();
73 
80  Progress::Ptr progress() const { return progress_; }
81  void progress(const Progress::Ptr &p) { progress_ = p; }
96  size_t nBits() const { return nBits_; }
97  void nBits(size_t n);
104  rose_addr_t mask() const;
105 
115 
119  void insertEntryAddress(rose_addr_t va) {
120  if (entryVas_.insert(va))
121  upToDate_ = false;
122  }
123 
128  void insertTargetAddress(rose_addr_t va) {
129  if (targetVas_.insert(va))
130  upToDate_ = false;
131  }
132 
134  const AddressSet& entryAddresses() const {
135  return entryVas_;
136  }
137 
139  const AddressSet& targetAddresses() const {
140  return targetVas_;
141  }
142 
156  BestMapAddress& analyze(const AddressInterval &restrictEntryAddresses = AddressInterval::whole(),
157  const AddressInterval &restrictTargetAddresses = AddressInterval::whole());
158 
163  const std::vector<rose_addr_t>& bestDeltas() const;
164 
170  double bestDeltaRatio() const;
171 };
172 
173 } // namespace
174 } // namespace
175 
176 #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
Collection of streams.
Definition: Message.h:1579
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:100
static Diagnostics::Facility mlog
Facility for emitting diagnostics.
double bestDeltaRatio() const
How well the best shift amounts performed.
const AddressSet & targetAddresses() const
Returns set of target addresses.
STL namespace.
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:616
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.
const AddressSet & entryAddresses() const
Returns set of entry addresses.
Container associating values with keys.
Definition: Sawyer/Map.h:64
rose_addr_t mask() const
Property: Mask to use when doing address arithmetic.
BestMapAddress()
Construct an empty analysis.