ROSE  0.11.31.0
BinaryBestMapAddress.h
1 #ifndef ROSE_BinaryAnalysis_BestMapAddress
2 #define ROSE_BinaryAnalysis_BestMapAddress
3 
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 
7 #include <Diagnostics.h>
8 #include <Partitioner2/Engine.h>
9 #include <Progress.h>
10 #include <RoseException.h>
11 #include <Sawyer/Set.h>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 
24 public:
26  class Exception: public Rose::Exception {
27  public:
29  explicit Exception(const std::string &mesg)
30  : Rose::Exception(mesg) {}
31 
33  ~Exception() throw () {}
34  };
35 
38 
41 
43  struct Settings {
45  };
46 
47 private:
48  typedef Sawyer::Container::Map<size_t /*nMatches*/, std::vector<rose_addr_t>/*deltas*/> MatchedDeltas;
49 
50  Settings settings_;
51  AddressSet entryVas_; // set of function entry virtual addresses
52  AddressSet targetVas_; // set of call target (callee) addresses
53  MatchedDeltas results_; // results of analyze() call
54  bool upToDate_; // are results_ up-to-date w.r.t. address sets?
55  size_t maxMatches_; // maximum number of matches possible for results_
56  size_t nBits_; // number of bits in an address
57  Progress::Ptr progress_; // for progress reporting
58 
59 public:
62  : upToDate_(true), maxMatches_(0), nBits_(0), progress_(Progress::instance()) {}
63 
67  const Settings& settings() const {
68  return settings_;
69  }
71  return settings_;
72  }
82  void reset() {
83  entryVas_.clear();
84  targetVas_.clear();
85  results_.clear();
86  maxMatches_ = 0;
87  upToDate_ = true;
88  }
89 
93  static void initDiagnostics();
94 
101  Progress::Ptr progress() const { return progress_; }
102  void progress(const Progress::Ptr &p) { progress_ = p; }
117  size_t nBits() const { return nBits_; }
118  void nBits(size_t n);
125  rose_addr_t mask() const;
126 
136 
140  void insertEntryAddress(rose_addr_t va) {
141  if (entryVas_.insert(va))
142  upToDate_ = false;
143  }
144 
149  void insertTargetAddress(rose_addr_t va) {
150  if (targetVas_.insert(va))
151  upToDate_ = false;
152  }
153 
155  const AddressSet& entryAddresses() const {
156  return entryVas_;
157  }
158 
160  const AddressSet& targetAddresses() const {
161  return targetVas_;
162  }
163 
177  BestMapAddress& analyze(const AddressInterval &restrictEntryAddresses = AddressInterval::whole(),
178  const AddressInterval &restrictTargetAddresses = AddressInterval::whole());
179 
184  const std::vector<rose_addr_t>& bestDeltas() const;
185 
191  double bestDeltaRatio() const;
192 
197  static MemoryMap::Ptr align(const MemoryMap::Ptr&,
200 };
201 
202 } // namespace
203 } // namespace
204 
205 #endif
206 #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
Base class for engines driving the partitioner.
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:167
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.
Definition: Progress.h:165
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.