ROSE  0.11.101.0
ExecutionEvent.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_ExecutionEvent_H
2 #define ROSE_BinaryAnalysis_Concolic_ExecutionEvent_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 
6 #include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/Concolic/Database.h>
8 #include <Rose/BinaryAnalysis/Concolic/ExecutionLocation.h>
9 #include <Rose/BinaryAnalysis/Debugger.h>
10 #include <Rose/BinaryAnalysis/SymbolicExpression.h>
11 #include <Combinatorics.h> // rose
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace Concolic {
16 
64 class ExecutionEvent: public Sawyer::SharedObject, public Sawyer::SharedFromThis<ExecutionEvent> {
65 public:
67  using Ptr = ExecutionEventPtr;
68 
70  enum class Action {
72  NONE,
73 
77  BULK_MEMORY_MAP,
78 
82  BULK_MEMORY_UNMAP,
83 
88  BULK_MEMORY_WRITE,
89 
94  BULK_MEMORY_HASH,
95 
100  MEMORY_WRITE,
101 
106  BULK_REGISTER_WRITE,
107 
112  REGISTER_WRITE,
113 
122  OS_SYSCALL,
123 
139  OS_SHARED_MEMORY
140  };
141 
142 private:
143  // These are the data members that get read/written to the database. The API properties defined for the various event
144  // types are not necessarily a 1:1 mapping to these data members.
145 
146  // Event identification data members
147  std::string timestamp_; // time of creation, needed by the database
148  TestCasePtr testCase_; // each event belongs to a particular test case
149  std::string name_; // optional name for debugging
150  ExecutionLocation location_; // location event occurs
151  rose_addr_t ip_ = 0; // address of instruction associated with event
152 
153  // These data members map to properties, but not necessarily 1:1. It's done this way for efficiency in the database.
154  Action action_ = Action::NONE; // type of action
155  AddressInterval memoryVas_; // affected memory
156  unsigned u_ = 0; // permission bits, register, or syscall function number
157  std::vector<uint8_t> bytes_; // byte data, hash digest, or syscall arguments
158  SymbolicExpressionPtr variable_, value_, expression_; // for computing concrete result from input
159  InputType inputType_ = InputType::NONE; // what kind of input is variable_?
160  size_t idx1_ = INVALID_INDEX; // indices for the input type, such as argv[i][j]
161  size_t idx2_ = INVALID_INDEX;
162 
163 protected:
164  ExecutionEvent();
165 public:
166  ~ExecutionEvent();
167 
168 public:
170  // Event constructors. These have camelCase names identical to the action.
172 
174  Ptr copy() const;
175 
177  static Ptr instance();
178 
180  static Ptr noAction(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip);
181 
182 
184  static Ptr bulkMemoryMap(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
185  const AddressInterval &where, unsigned permissions);
186 
188  static Ptr bulkMemoryUnmap(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
189  const AddressInterval &where);
190 
194  static Ptr bulkMemoryWrite(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
195  const AddressInterval &where, const std::vector<uint8_t> &bytes);
196 
200  static Ptr bulkMemoryHash(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
201  const AddressInterval &where, const Combinatorics::Hasher::Digest&);
202 
204  static Ptr memoryWrite(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
205  const AddressInterval &where, const SymbolicExpressionPtr &variable,
206  const SymbolicExpressionPtr &value, const SymbolicExpressionPtr &expression);
207 
209  static Ptr bulkRegisterWrite(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
210  const Debugger::AllRegisters&);
211 
213  static Ptr registerWrite(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
214  RegisterDescriptor where, const SymbolicExpressionPtr &variable,
215  const SymbolicExpressionPtr &value, const SymbolicExpressionPtr &expression);
216 
218  static Ptr osSyscall(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
219  unsigned function, const std::vector<uint64_t> &arguments);
220 
222  static Ptr osSharedMemory(const TestCasePtr&, const ExecutionLocation&, rose_addr_t ip,
223  const AddressInterval &where, const SymbolicExpressionPtr &variable,
224  const SymbolicExpressionPtr &value, const SymbolicExpressionPtr &expression);
225 
227  // Properties that are used by all event types.
229 
237  TestCasePtr testCase() const;
238  void testCase(const TestCasePtr&);
251  const std::string& timestamp() const;
252  void timestamp(const std::string&);
263  std::string name() const;
264  void name(const std::string&);
274  ExecutionLocation location() const;
275  void location(const ExecutionLocation&);
287  rose_addr_t instructionPointer() const;
288  void instructionPointer(rose_addr_t);
298  Action action() const;
299  void action(Action);
302  // Properties specific to certain types of events.
305 
314  AddressInterval memoryLocation() const;
315  void memoryLocation(const AddressInterval&);
326  RegisterDescriptor registerDescriptor() const;
327  void registerDescriptor(RegisterDescriptor);
338  unsigned permissions() const;
339  void permissions(unsigned);
350  const std::vector<uint8_t>& bytes() const;
351  void bytes(const std::vector<uint8_t>&);
359  Debugger::AllRegisters registerValues() const;
360  void registerValues(const Debugger::AllRegisters&);
371  const Combinatorics::Hasher::Digest& hash() const;
372  void hash(const Combinatorics::Hasher::Digest&);
384  SymbolicExpressionPtr variable() const;
385  void variable(const SymbolicExpressionPtr&);
398  SymbolicExpressionPtr value() const;
399  void value(const SymbolicExpressionPtr&);
415  SymbolicExpressionPtr expression() const;
416  void expression(const SymbolicExpressionPtr&);
426  unsigned syscallFunction() const;
427  void syscallFunction(unsigned);
439  std::vector<uint64_t> syscallArguments() const;
440  void syscallArguments(const std::vector<uint64_t>&);
443  // Properties related to test case input variables.
446 
458  InputType inputType() const;
459  void inputType(InputType, size_t idx1, size_t idx2);
460  std::pair<size_t, size_t> inputIndices() const;
463  // Actions valid for all events
466 
473  SymbolicExpressionPtr inputVariable() const;
474 
476  // Actions defined for some event types.
478 
479 
488  SymbolicExpressionPtr calculateResult(const SymbolicExpression::ExprExprHashMap &bindings) const;
489 
497  std::string printableName(const DatabasePtr &db = DatabasePtr());
498 
505  void toYaml(std::ostream&, const DatabasePtr&, std::string prefix);
506 
508  // Database operations
510 private:
511  friend class DatabaseAccess;
512 
513  // Recreate the table for storing execution events. Is only called from the database layer.
514  static void recreateTable(Sawyer::Database::Connection);
515 
516  // Save this object to the database. Is only called from the database layer.
517  void toDatabase(const DatabasePtr&, ExecutionEventId);
518 
519  // Restore this object from the database. Is only called from the database layer.
520  void fromDatabase(const DatabasePtr&, ExecutionEventId);
521 };
522 
523 } // namespace
524 } // namespace
525 } // namespace
526 
527 #endif
528 #endif
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.
const char * Action(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ExecutionEvent::Action enum constant to a string...
Main namespace for the ROSE library.
std::vector< uint8_t > Digest
The digest of the input message.
Creates SharedPointer from this.
Binary analysis.
Base class for reference counted objects.
Definition: SharedObject.h:64
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
const char * InputType(int64_t)
Convert Rose::BinaryAnalysis::Concolic::InputType enum constant to a string.
const size_t INVALID_INDEX(static_cast< size_t >(-1))
Invalid array index.
Hash hash(const std::vector< Ptr > &)
Hash zero or more expressions.