ROSE  0.9.9.139
BinaryPointerDetection.h
1 #ifndef ROSE_BinaryAnalysis_PointerDetection_H
2 #define ROSE_BinaryAnalysis_PointerDetection_H
3 
4 #include <BaseSemantics2.h>
5 #include <MemoryCellList.h>
6 #include <Sawyer/Set.h>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 
11 // Forwards
12 class Disassembler;
13 namespace Partitioner2 {
14  class Partitioner;
15  class Function;
16 }
17 
18 
111 namespace PointerDetection {
112 
116 void initDiagnostics();
117 
122 
124 struct Settings {
131 
137 
140  : ignoreConstIp(true), ignoreStrangeSizes(true) {}
141 };
142 
146  size_t nBits;
148  PointerDescriptor(const SymbolicExpr::Ptr &lvalue, size_t nBits)
149  : lvalue(lvalue), nBits(nBits) {}
150 };
151 
154 public:
155  bool operator()(const PointerDescriptor &a, const PointerDescriptor &b);
156 };
157 
159 typedef std::set<PointerDescriptor, PointerDescriptorLessp> PointerDescriptors;
160 
165 class Analysis {
166 public:
167 
168 private:
169  Settings settings_;
171  bool hasResults_; // Are the following data members initialized?
172  bool didConverge_; // Are the following data members valid (else only appoximations)?
173  PointerDescriptors codePointers_; // Memory addresses that hold a pointer to code
174  PointerDescriptors dataPointers_; // Memory addresses that hold a pointer to data
175  InstructionSemantics2::BaseSemantics::StatePtr initialState_; // Initial state for analysis
176  InstructionSemantics2::BaseSemantics::StatePtr finalState_; // Final state for analysis
177 
178 public:
185  : hasResults_(false), didConverge_(false) {}
186 
190  explicit Analysis(Disassembler *d, const Settings &settings = Settings())
191  : hasResults_(false), didConverge_(false) {
192  init(d);
193  }
194 
202  const Settings &settings = Settings())
203  : cpu_(cpu), hasResults_(false), didConverge_(false) {}
204 
208  const Settings& settings() const { return settings_; }
209 
216 
221  bool hasResults() const { return hasResults_; }
222 
227  bool didConverge() const { return didConverge_; }
228 
233  void clearResults();
234 
239  void clearNonResults();
240 
245  const PointerDescriptors& codePointers() const {
246  return codePointers_;
247  }
248 
253  const PointerDescriptors& dataPointers() const {
254  return dataPointers_;
255  }
256 
263  return initialState_;
264  }
265 
272  return finalState_;
273  }
274 
275 private:
276  void init(Disassembler*);
277 
279  makeRiscOperators(const Partitioner2::Partitioner&) const;
280 
281  // Prints instructions to the mlog[DEBUG] diagnostic stream if that stream is enabled.
282  void
283  printInstructionsForDebugging(const Partitioner2::Partitioner&, const Sawyer::SharedPointer<Partitioner2::Function>&);
284 
285  // Given a potential pointer's r-value, determine if the r-value is a pointer and if so, store its address in the
286  // result. The pointer's value and the defining instructions are added to the two sets, and the result is not updated for
287  // values and instructions that have already been processed.
288  void
289  conditionallySavePointer(const InstructionSemantics2::BaseSemantics::SValuePtr &ptrValue,
290  Sawyer::Container::Set<uint64_t> &ptrValueSeen,
291  size_t wordSize, PointerDescriptors &result);
292 };
293 
294 } // namespace
295 } // namespace
296 } // namespace
297 
298 #endif
Ordered set of values.
Definition: Set.h:46
Settings to control the pointer analysis.
InstructionSemantics2::BaseSemantics::StatePtr finalState() const
Final state for analysis.
Collection of streams.
Definition: Message.h:1579
bool didConverge() const
Whether the analysis results are valid.
Analysis(Disassembler *d, const Settings &settings=Settings())
Construct an analysis using a specific disassembler.
InstructionSemantics2::BaseSemantics::StatePtr initialState() const
Initial state for analysis.
const Settings & settings() const
Property: Analysis settings.
bool ignoreConstIp
Whether to ignore branches to concrete addresses.
void clearNonResults()
Clears everything but results.
Main namespace for the ROSE library.
boost::shared_ptr< class State > StatePtr
Shared-ownership pointer to a semantic state.
Analysis(const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu, const Settings &settings=Settings())
Construct an analysis using a specified dispatcher.
boost::shared_ptr< class Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
Sawyer::Message::Facility mlog
Facility for diagnostic output.
void initDiagnostics()
Initialize diagnostics.
Functor to compare two PointerLocation objects.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
void clearResults()
Clear analysis results.
SymbolicExpr::Ptr lvalue
Symbolic address of pointer.
const PointerDescriptors & codePointers() const
Property: Code pointers.
std::set< PointerDescriptor, PointerDescriptorLessp > PointerDescriptors
Set of pointers.
const PointerDescriptors & dataPointers() const
Property: Data pointers.
bool ignoreStrangeSizes
Whether to ignore strange-sized pointers.
void analyzeFunction(const Partitioner2::Partitioner &, const Sawyer::SharedPointer< Partitioner2::Function > &)
Analyze one function.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:290
bool hasResults() const
Whether a function has been analyzed.
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:41