ROSE  0.11.50.0
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 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 
23 public:
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 
42  struct Settings {
44  };
45 
46 private:
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 
58 public:
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 
134  void gatherAddresses(Partitioner2::Engine &engine);
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 
159  const AddressSet& targetAddresses() const {
160  return targetVas_;
161  }
162 
176  BestMapAddress& analyze(const AddressInterval &restrictEntryAddresses = AddressInterval::whole(),
177  const AddressInterval &restrictTargetAddresses = AddressInterval::whole());
178 
183  const std::vector<rose_addr_t>& bestDeltas() const;
184 
190  double bestDeltaRatio() const;
191 
196  static MemoryMap::Ptr align(const MemoryMap::Ptr&,
197  const Partitioner2::Engine::Settings &settings = Partitioner2::Engine::Settings(),
199 };
200 
201 } // namespace
202 } // namespace
203 
204 #endif
205 #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:268
Collection of streams.
Definition: Message.h:1606
Finds best address for mapping code.
bool insert(const Value &value)
Insert a value.
Definition: Set.h:228
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 Settings & settings() const
Settings.
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:180
Progress::Ptr progress() const
Property: Progress reporter.
Sawyer::Optional< size_t > nThreads
Number of threads to use, overriding the global setting.
A general, thread-safe way to report progress made on some task.
Exception(const std::string &mesg)
Construct an exception with a message.
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
const AddressSet & entryAddresses() const
Returns set of entry addresses.
Settings to control the analysis.
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.