ROSE  0.11.50.0
Specimen.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_Specimen_H
2 #define ROSE_BinaryAnalysis_Concolic_Specimen_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 #include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
6 
7 #include <boost/filesystem.hpp>
8 #include <boost/serialization/access.hpp>
9 #include <boost/serialization/nvp.hpp>
10 #include <Sawyer/SharedObject.h>
11 #include <Sawyer/SharedPointer.h>
12 #include <string>
13 #include <vector>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace Concolic {
18 
23 class Specimen: public Sawyer::SharedObject, public Sawyer::SharedFromThis<Specimen> {
24 public:
27 
29  typedef std::vector<uint8_t> BinaryData;
30 
31 private:
32  mutable SAWYER_THREAD_TRAITS::Mutex mutex_; // protects the following data members
33  std::string name_; // name of specimen (e.g., for debugging)
34  std::string timestamp_; // time of creation
35  BinaryData content_; // content of the binary executable file
36  mutable bool read_only_; // safe guards from writing content after it has been shared;
37  bool empty_; // indicates if this object is empty
38 
39 private:
40  friend class boost::serialization::access;
41 
42  template<class S>
43  void serialize(S &s, const unsigned /*version*/) {
44  s & BOOST_SERIALIZATION_NVP(name_);
45  s & BOOST_SERIALIZATION_NVP(content_);
46  s & BOOST_SERIALIZATION_NVP(empty_);
47  }
48 
49 protected:
50  Specimen();
51 
52 public:
53  ~Specimen();
54 
57  static Ptr instance(const boost::filesystem::path &executableName);
58  static Ptr instance();
67  void open(const boost::filesystem::path &executableName);
68 
75  void close();
76 
82  bool isEmpty() const;
83 
92  std::string name() const; // value return is intentional for thread safety
93  void name(const std::string&);
101  std::string printableName(const DatabasePtr &db = DatabasePtr());
102 
104  void toYaml(std::ostream&, const DatabasePtr&, std::string prefix);
105 
116  std::string timestamp() const;
117  void timestamp(const std::string&);
126  const std::vector<uint8_t>& content() const;
127 
128  // FIXME[Robb Matzke 2019-08-12]: content is read-only, created by constructor. Therefore this member shouldn't be defined,
129  // or at least should be private.
132  void content(std::vector<uint8_t> binary_data);
133 };
134 
135 } // namespace
136 } // namespace
137 } // namespace
138 
139 #endif
140 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:156
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
Main namespace for the ROSE library.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Creates SharedPointer from this.
Base class for reference counted objects.
Definition: SharedObject.h:64