ROSE  0.11.50.0
Architecture.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_Architecture_H
2 #define ROSE_BinaryAnalysis_Concolic_Architecture_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 
6 #include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/Concolic/ExecutionLocation.h>
8 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics/Types.h>
9 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
10 #include <Rose/BinaryAnalysis/RegisterDescriptor.h>
11 #include <Rose/BinaryAnalysis/SmtSolver.h>
12 #include <ByteOrder.h>
13 
14 #include <Sawyer/BitVector.h>
15 
16 #include <boost/filesystem.hpp>
17 
18 namespace Rose {
19 namespace BinaryAnalysis {
20 namespace Concolic {
21 
23 class Architecture: public Sawyer::SharedObject, public Sawyer::SharedFromThis<Architecture> {
24 public:
26  using Ptr = ArchitecturePtr;
27 
29  using SystemCallMap = Sawyer::Container::Map<int /*syscall*/, SyscallCallbacks>;
30 
33 
34 private:
35  DatabasePtr db_;
36  TestCaseId testCaseId_;
37  TestCasePtr testCase_;
38  const Partitioner2::Partitioner &partitioner_;
39  ExecutionLocation currentLocation_; // incremented when the instruction begins execution
40  SystemCallMap systemCalls_; // callbacks for syscalls
41  SharedMemoryMap sharedMemory_; // callbacks for shared memory
42  SymbolicExpr::ExprExprHashMap variableValues_; // used for substitutions
43 
44 protected:
45  // See "instance" methods in subclasses
46  Architecture(const DatabasePtr&, TestCaseId, const Partitioner2::Partitioner&);
47 public:
48  virtual ~Architecture();
49 
51  // Properties
53 public:
58  DatabasePtr database() const;
59 
64  TestCaseId testCaseId() const;
65 
70  TestCasePtr testCase() const;
71 
75  const Partitioner2::Partitioner& partitioner() const;
76 
89  ExecutionLocation currentLocation() const;
90  void currentLocation(const ExecutionLocation&);
104  const SystemCallMap& systemCalls() const;
105  SystemCallMap& systemCalls();
122  const SharedMemoryMap& sharedMemory() const;
123  SharedMemoryMap& sharedMemory();
126  // Functions that can be called before execution starts.
129 public:
133  virtual void configureSystemCalls() = 0;
134 
139  virtual void configureSharedMemory() = 0;
140 
142  void sharedMemory(const AddressInterval&, const SharedMemoryCallbackPtr&);
143 
145  void systemCalls(size_t syscallId, const SyscallCallbackPtr&);
146 
156  virtual void load(const boost::filesystem::path &tempDirectory) = 0;
157 
162  virtual bool isTerminated() = 0;
163 
165  // Functions that create execution events. These query the concrete state but do not modify it.
167 public:
172  virtual std::vector<ExecutionEventPtr> createMemoryRestoreEvents() = 0;
173 
178  virtual std::vector<ExecutionEventPtr> createMemoryHashEvents() = 0;
179 
184  virtual std::vector<ExecutionEventPtr> createRegisterRestoreEvents() = 0;
185 
190  void saveEvents(const std::vector<ExecutionEventPtr>&, When);
191 
193  // High-level functions controlling concrete execution.
195 public:
201  size_t playAllEvents(const Partitioner2::Partitioner&);
202 
209  virtual bool playEvent(const ExecutionEventPtr&);
210 
214  virtual void runToEvent(const ExecutionEventPtr&, const Partitioner2::Partitioner&);
215 
219  uint64_t readMemoryUnsigned(rose_addr_t va, size_t nBytes);
220 
226  virtual std::string readCString(rose_addr_t va, size_t maxBytes = UNLIMITED);
227 
229  // Low-level functions controlling concrete execution.
231 public:
235  virtual ByteOrder::Endianness memoryByteOrder() = 0;
236 
240  virtual rose_addr_t ip() = 0;
241  virtual void ip(rose_addr_t) = 0;
248  virtual void mapMemory(const AddressInterval &where, unsigned permissions) {}
249 
253  virtual void unmapMemory(const AddressInterval &where) {}
254 
258  virtual size_t writeMemory(rose_addr_t startVa, const std::vector<uint8_t> &bytes) = 0;
259 
264  virtual std::vector<uint8_t> readMemory(rose_addr_t startVa, size_t nBytes) = 0;
265 
272  virtual void writeRegister(RegisterDescriptor, uint64_t value) = 0;
273  virtual void writeRegister(RegisterDescriptor, const Sawyer::Container::BitVector&) = 0;
277  virtual Sawyer::Container::BitVector readRegister(RegisterDescriptor) = 0;
278 
284  virtual void executeInstruction(const Partitioner2::Partitioner&) = 0;
285  virtual void executeInstruction(const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr&, SgAsmInstruction*) = 0;
292  const ExecutionLocation& nextInstructionLocation();
293 
300  const ExecutionLocation& nextEventLocation(When);
309  const SymbolicExpr::ExprExprHashMap& variableValues() const;
310  SymbolicExpr::ExprExprHashMap& variableValues();
317  std::vector<ExecutionEventPtr> getRelatedEvents(const ExecutionEventPtr&) const;
318 
320  // Functions related to symbolic states.
322 public:
330  virtual void createInputVariables(InputVariables &inputVariables /*in,out*/, const Partitioner2::Partitioner&,
332  const SmtSolver::Ptr&) = 0;
333 
351  virtual void restoreInputVariables(InputVariables &inputVariables /*in,out*/, const Partitioner2::Partitioner&,
353  const SmtSolver::Ptr&);
354 
356  // Functions related to operating system emulation
358 public:
363  virtual void systemCall(const Partitioner2::Partitioner&, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr&) {}
364 
369  virtual std::pair<ExecutionEventPtr, SymbolicExprPtr>
370  sharedMemoryRead(const SharedMemoryCallbacks&, const Partitioner2::Partitioner&,
371  const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr&, rose_addr_t memVa, size_t nBytes);
372 };
373 
374 } // namespace
375 } // namespace
376 } // namespace
377 
378 #endif
379 #endif
SmtSolverPtr Ptr
Reference counting pointer for SMT solvers.
Definition: SmtSolver.h:39
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:156
An associative container whose keys are non-overlapping intervals.
Definition: IntervalMap.h:171
const size_t UNLIMITED(-1)
Effictively unlimited size.
Base class for machine instructions.
Main namespace for the ROSE library.
Creates SharedPointer from this.
Base class for reference counted objects.
Definition: SharedObject.h:64
Range of values delimited by endpoints.
Definition: Interval.h:33
const char * Architecture(int64_t)
Convert Rose::BinaryAnalysis::DisassemblerMips::Mips32::Architecture enum constant to a string...
Definition: stringify.C:40051
Container associating values with keys.
Definition: Sawyer/Map.h:66