ROSE  0.11.98.0
BinaryAnalysis/Concolic/BasicTypes.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_BasicTypes_H
2 #define ROSE_BinaryAnalysis_Concolic_BasicTypes_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 
6 #include <rose_strtoull.h>
7 
8 #include <Rose/Exception.h>
9 
10 #include <Sawyer/Callbacks.h>
11 #include <Sawyer/Message.h>
12 #include <Sawyer/SharedPointer.h>
13 
14 #include <boost/shared_ptr.hpp>
15 #include <memory>
16 
17 namespace Rose {
18 namespace BinaryAnalysis {
19 namespace Concolic {
20 
22 // Flags and enums
24 
25 enum class Update { NO, YES };
26 
27 enum class ShowEvents { NO, YES };
28 
29 enum class ShowAssertions { NO, YES };
30 
32 enum class InputType {
33  NONE,
34  ARGC,
35  ARGV,
36  ENVP,
37  SYSCALL_RET,
38  SHMEM_READ
39 };
40 
42 enum class IoDirection {
43  READ,
44  WRITE
45 };
46 
50 enum class When {
51  PRE,
52  POST
53 };
54 
56 enum class ConcolicPhase {
57  REPLAY,
58  EMULATION,
59  POST_EMULATION
60 };
61 
63 // Exceptions, errors, etc.
65 
68 
69 // Internal: called by Rose::Diagnostics::initialize
70 void initDiagnostics();
71 
73 class Exception: public Rose::Exception {
74 public:
75  explicit Exception(const std::string &mesg): Rose::Exception(mesg) {}
76  ~Exception() throw () {}
77 };
78 
80 // Forward references
82 
83 class Architecture;
84 using ArchitecturePtr = Sawyer::SharedPointer<Architecture>;
85 
86 class ConcolicExecutor;
87 using ConcolicExecutorPtr = Sawyer::SharedPointer<ConcolicExecutor>;
88 
89 class ConcreteExecutor;
90 using ConcreteExecutorPtr = Sawyer::SharedPointer<ConcreteExecutor>;
91 class ConcreteExecutorResult;
92 
93 class Database;
94 using DatabasePtr = Sawyer::SharedPointer<Database>;
95 
96 namespace Emulation {
97  class RiscOperators;
98  using RiscOperatorsPtr = boost::shared_ptr<class RiscOperators>;
99 }
100 
101 class ExecutionEvent;
102 using ExecutionEventPtr = Sawyer::SharedPointer<ExecutionEvent>;
103 
104 class ExecutionLocation;
105 
106 class ExecutionManager;
107 using ExecutionManagerPtr = Sawyer::SharedPointer<ExecutionManager>;
108 
109 class InputVariables;
110 using InputVariablesPtr = Sawyer::SharedPointer<InputVariables>;
111 
112 class LinuxExecutor;
113 using LinuxExecutorPtr = Sawyer::SharedPointer<LinuxExecutor>;
114 
115 class LinuxI386;
116 using LinuxI386Ptr = Sawyer::SharedPointer<LinuxI386>;
117 
118 class SharedMemoryCallback;
119 using SharedMemoryCallbackPtr = Sawyer::SharedPointer<SharedMemoryCallback>;
120 
121 using SharedMemoryCallbacks = Sawyer::Callbacks<SharedMemoryCallbackPtr>;
122 
123 class SharedMemoryContext;
124 
125 class Specimen;
126 using SpecimenPtr = Sawyer::SharedPointer<Specimen>;
127 
128 class SyscallCallback;
129 using SyscallCallbackPtr = std::shared_ptr<SyscallCallback>;
130 
131 using SyscallCallbacks = Sawyer::Callbacks<SyscallCallbackPtr>;
132 
133 class SyscallContext;
134 
135 class TestCase;
136 using TestCasePtr = Sawyer::SharedPointer<TestCase>;
137 
138 class TestSuite;
139 using TestSuitePtr = Sawyer::SharedPointer<TestSuite>;
140 
141 class LinuxExitStatus;
142 using LinuxExitStatusPtr = Sawyer::SharedPointer<LinuxExitStatus>;
143 
145 // Database
147 
149 template <class Tag>
150 class ObjectId: public Sawyer::Optional<size_t> {
151 public:
152  using Value = size_t;
153  using Super = Sawyer::Optional<Value>;
154  using Object = Tag;
155  using Pointer = Sawyer::SharedPointer<Tag>;
157  ObjectId() {}
158 
159  explicit
160  ObjectId(const Value& v)
161  : Super(v) {}
162 
163  ObjectId(const ObjectId& rhs)
164  : Super(rhs) {}
165 
166  explicit ObjectId(const Sawyer::Optional<size_t> &id)
167  : Super(id) {}
168 
174  explicit ObjectId(const std::string &s) {
175  char *rest = NULL;
176  uint64_t id = rose_strtoull(s.c_str(), &rest, 0);
177  while (*rest && isspace(*rest)) ++rest;
178  if (*rest)
179  throw Exception("invalid syntax for object ID: \"" + StringUtility::cEscape(s) + "\"");
180  try {
181  *this = boost::numeric_cast<Value>(id);
182  } catch (const boost::bad_numeric_cast&) {
183  throw Exception("parsed object ID out of range: \"" + StringUtility::cEscape(s) + "\"");
184  }
185  }
186 
188  ObjectId<Tag>& operator=(const ObjectId<Tag>& lhs) {
189  this->Super::operator=(lhs);
190  return *this;
191  }
192 
194  ObjectId<Tag>& operator=(const Value& v) {
195  this->Super::operator=(v);
196  return *this;
197  }
198 
199  explicit operator bool() const { // because it's not explicit in the super class due to C++03 support
200  return isEqual(Sawyer::Nothing()) ? false : true;
201  }
202 
204  template<class _Tag>
205  friend
206  bool operator<(const ObjectId<_Tag>& lhs, const ObjectId<_Tag>& rhs);
207 
208  // Useful for database operations
209  const Super& optional() const {
210  return *this;
211  }
212 };
213 
215 template<class Tag>
216 inline
217 bool operator<(const ObjectId<Tag>& lhs, const ObjectId<Tag>& rhs)
218 {
219  if (!rhs) return false;
220  if (!lhs) return true;
221 
222  return lhs.get() < rhs.get();
223 }
224 
225 using TestSuiteId = ObjectId<TestSuite>;
226 using SpecimenId = ObjectId<Specimen>;
227 using TestCaseId = ObjectId<TestCase>;
228 using ExecutionEventId = ObjectId<ExecutionEvent>;
233 template<class T>
234 struct ObjectTraits {
235  using Id = void;
236 };
237 
238 template<>
239 struct ObjectTraits<TestSuite> {
240  using Id = TestSuiteId;
241 };
242 
243 template<>
244 struct ObjectTraits<Specimen> {
245  using Id = SpecimenId;
246 };
247 
248 template<>
249 struct ObjectTraits<TestCase> {
250  using Id = TestCaseId;
251 };
252 
253 template<>
254 struct ObjectTraits<ExecutionEvent> {
255  using Id = ExecutionEventId;
256 };
257 
258 } // namespace
259 } // namespace
260 } // namespace
261 
262 #endif
263 #endif
const char * IoDirection(int64_t)
Convert Rose::BinaryAnalysis::Concolic::IoDirection enum constant to a string.
Collection of streams.
Definition: Message.h:1606
Only query an allocation.
Definition: CodeInserter.h:15
ROSE_DLL_API Sawyer::Message::Facility mlog
Diagnostic facility for the ROSE library as a whole.
const char * ShowAssertions(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ShowAssertions enum constant to a string. ...
Holds a value or nothing.
Definition: Optional.h:49
Main namespace for the ROSE library.
ROSE_UTIL_API std::string cEscape(const std::string &, char context= '"')
Escapes characters that are special to C/C++.
const char * When(int64_t)
Convert Rose::BinaryAnalysis::Concolic::When enum constant to a string.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Object
The five kind of objects manipulated by Rose::CodeGen::API and associated Rose::CodeGen::Factory.
Definition: Object.h:11
Allocate memory for real.
Definition: CodeInserter.h:16
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to concrete RISC operations.
const char * Update(int64_t)
Convert Rose::BinaryAnalysis::Concolic::Update enum constant to a string.
const char * ConcolicPhase(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ConcolicPhase enum constant to a string.
size_t Id
Attribute identification.
Definition: Attribute.h:140
Binary analysis.
const char * ShowEvents(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ShowEvents enum constant to a string.
void initDiagnostics()
Initialize diagnostics.
const char * InputType(int64_t)
Convert Rose::BinaryAnalysis::Concolic::InputType enum constant to a string.
Represents no value.
Definition: Optional.h:32
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::DisassemblerMips::Mips32::Architecture enum constant to a string...