ROSE  0.11.2.0
BinaryHotPatch.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_HotPatch_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_HotPatch_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BaseSemanticsTypes.h>
7 #include <BinaryHotPatch.h>
8 #include <BinarySmtSolver.h>
9 #include <Sawyer/Message.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/nvp.hpp>
13 #include <boost/serialization/shared_ptr.hpp>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 
22 class HotPatch {
23 public:
26 
28  class Record {
29  public:
31  enum Type {
34  };
35 
37  enum Behavior {
40  };
41 
42  private:
43  Type type_; // record type
44  RegisterDescriptor register_; // register to be modified for PATCH_REGISTER types.
45  InstructionSemantics2::BaseSemantics::SValuePtr oldValue_; // value to match
46  InstructionSemantics2::BaseSemantics::SValuePtr newValue_; // replacement value
47  Behavior behavior_; // whether to continue matching more records
48 
49 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
50  private:
51  friend class boost::serialization::access;
52 
53  template<class S>
54  void serialize(S &s, const unsigned /*version*/) {
55  s & BOOST_SERIALIZATION_NVP(type_);
56  s & BOOST_SERIALIZATION_NVP(register_);
57  s & BOOST_SERIALIZATION_NVP(oldValue_);
58  s & BOOST_SERIALIZATION_NVP(newValue_);
59  s & BOOST_SERIALIZATION_NVP(behavior_);
60  }
61 #endif
62 
63  public:
66  : type_(PATCH_NONE), behavior_(MATCH_CONTINUE) {}
67 
74  : type_(PATCH_REGISTER), register_(reg), oldValue_(oldValue), newValue_(newValue), behavior_(behavior) {
75  ASSERT_not_null(newValue);
76  }
77 
81  Type type() const {
82  return type_;
83  }
84 
92  return register_;
93  }
95  register_ = r;
96  }
106  return oldValue_;
107  }
109  oldValue_ = v;
110  }
120  return newValue_;
121  }
123  newValue_ = v;
124  }
133  Behavior behavior() const {
134  return behavior_;
135  }
136  void behavior(Behavior b) {
137  behavior_ = b;
138  }
140  };
141 
142 
144  typedef std::vector<Record> Records;
145 
146 private:
147  Records records_;
148 
149  // Serialization
150 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
151 private:
152  friend class boost::serialization::access;
153 
154  template<class S>
155  void serialize(S &s, const unsigned /*version*/) {
156  s & BOOST_SERIALIZATION_NVP(records_);
157  }
158 #endif
159 
160 public:
166  const Records& records() const {
167  return records_;
168  }
169  Records& records() {
170  return records_;
171  }
175  size_t nRecords() const {
176  return records_.size();
177  }
178 
180  void clear() {
181  records_.clear();
182  }
183 
188  size_t append(const Record &record) {
189  records_.push_back(record);
190  return records_.size() - 1;
191  }
192 
198  const Record& operator[](size_t idx) const {
199  ASSERT_require(idx < records_.size());
200  return records_[idx];
201  }
202  Record& operator[](size_t idx) {
203  ASSERT_require(idx < records_.size());
204  return records_[idx];
205  }
219  return apply(ops);
220  }
224  static void initDiagnostics();
225 };
226 
227 
228 } // namespace
229 } // namespace
230 
231 #endif
232 #endif
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
void newValue(const InstructionSemantics2::BaseSemantics::SValuePtr &v)
Property: Replacement value.
void reg(RegisterDescriptor r)
Property: Register to be matched.
Type for default-constructed records.
Describes how to modify machine state after each instruction.
Behavior behavior() const
Property: Behavior after matching.
Collection of streams.
Definition: Message.h:1599
InstructionSemantics2::BaseSemantics::SValuePtr oldValue() const
Property: Value to match.
void oldValue(const InstructionSemantics2::BaseSemantics::SValuePtr &v)
Property: Value to match.
Describes a single hot patch.
Record(RegisterDescriptor reg, const InstructionSemantics2::BaseSemantics::SValuePtr &oldValue, const InstructionSemantics2::BaseSemantics::SValuePtr &newValue, Behavior behavior=MATCH_CONTINUE)
Construct a record that substitutes a register.
Main namespace for the ROSE library.
Records & records()
Property: Hot patch records.
size_t nRecords() const
Number of hot-patch records in this object.
const Records & records() const
Property: Hot patch records.
Don't try to match more records after a match is found.
void behavior(Behavior b)
Property: Behavior after matching.
Try to match additional subsequent records.
Describes (part of) a physical CPU register.
size_t operator()(const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &ops) const
Apply records to a machine state.
const Record & operator[](size_t idx) const
Reference a particular record.
RegisterDescriptor reg() const
Property: Register to be matched.
InstructionSemantics2::BaseSemantics::SValuePtr newValue() const
Property: Replacement value.
size_t append(const Record &record)
Append a hot-patch record.
Type type() const
Property: Type of record.
Record & operator[](size_t idx)
Reference a particular record.
std::vector< Record > Records
Ordered list of hot patch records.
Record()
Construct a no-op record.
static Sawyer::Message::Facility mlog
Diagnostic output for hot patching.
size_t apply(const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &) const
Apply records to a machine state.
static void initDiagnostics()
Initialize diagnostic output.
Behavior
Behavior when a record matches.
void clear()
Remove all records from this object.