ROSE  0.11.101.0
NoOperation.h
1 #ifndef ROSE_BinaryAnalysis_NoOperation_H
2 #define ROSE_BinaryAnalysis_NoOperation_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
8 #include <Sawyer/Message.h>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 
14 class NoOperation {
15 public:
18 
20  typedef std::vector<IndexInterval> IndexIntervals;
21 
24  protected:
25  size_t ignorePoppedMemory_;
26  StateNormalizer(): ignorePoppedMemory_(8192) {}
27  public:
28  virtual ~StateNormalizer() {}
29 
32 
34  static Ptr instance() {
35  return Ptr(new StateNormalizer);
36  }
37 
45  size_t ignorePoppedMemory() const { return ignorePoppedMemory_; }
46  void ignorePoppedMemory(size_t nbytes) { ignorePoppedMemory_ = nbytes; }
52 
58  };
59 
60 private:
62  StateNormalizer::Ptr normalizer_;
64  bool ignoreTerminalBranches_ = true;
65 
66 public:
69 public:
74  NoOperation();
75 
78  : cpu_(cpu), normalizer_(StateNormalizer::instance()) {}
79 
84 
96  StateNormalizer::Ptr stateNormalizer() const { return normalizer_; }
97  void stateNormalizer(const StateNormalizer::Ptr &f) { normalizer_ = f; }
106  const Sawyer::Optional<rose_addr_t> initialStackPointer() const { return initialSp_; }
107  void initialStackPointer(const Sawyer::Optional<rose_addr_t> &v) { initialSp_ = v; }
116  bool ignoreTerminalBranches() const { return ignoreTerminalBranches_; }
117  void ignoreTerminalBranches(bool b) { ignoreTerminalBranches_ = b; }
121  bool isNoop(SgAsmInstruction*) const;
122 
124  bool isNoop(const std::vector<SgAsmInstruction*>&) const;
125 
127  IndexIntervals findNoopSubsequences(const std::vector<SgAsmInstruction*>&) const;
128 
136  static IndexIntervals largestEarliestNonOverlapping(const IndexIntervals&);
137 
142  static std::vector<bool> toVector(const IndexIntervals&, size_t size=0);
143 
145  static void initDiagnostics();
146 
147 protected:
149  std::string normalizeState(const InstructionSemantics::BaseSemantics::StatePtr&) const;
150 };
151 
152 } // namespace
153 } // namespace
154 
155 #endif
156 #endif
Base class for normalizing a state.
Definition: NoOperation.h:23
size_t ignorePoppedMemory() const
Property: ignore recently popped memory.
Definition: NoOperation.h:45
std::vector< IndexInterval > IndexIntervals
A vector of instruction indices.
Definition: NoOperation.h:20
Base class for machine instructions.
Collection of streams.
Definition: Message.h:1606
bool isNoop(SgAsmInstruction *) const
Determines if an instruction is a no-op.
Main namespace for the ROSE library.
static void initDiagnostics()
Initializes and registers disassembler diagnostic streams.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
void initialStackPointer(const Sawyer::Optional< rose_addr_t > &v)
Property: initial concrete value for stack pointer.
Definition: NoOperation.h:107
NoOperation(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu)
Construct a new analysis with specified virtual CPU.
Definition: NoOperation.h:77
void ignoreTerminalBranches(bool b)
Property: Whether terminal branches can be no-ops.
Definition: NoOperation.h:117
void stateNormalizer(const StateNormalizer::Ptr &f)
Property: state normalizer.
Definition: NoOperation.h:97
static std::vector< bool > toVector(const IndexIntervals &, size_t size=0)
Return a boolean vector.
virtual std::string toString(const InstructionSemantics::BaseSemantics::DispatcherPtr &, const InstructionSemantics::BaseSemantics::StatePtr &)
Takes a state and returns a normalized string.
IndexIntervals findNoopSubsequences(const std::vector< SgAsmInstruction * > &) const
Finds all sequences of instructions that are equivalent to no-operation.
Binary analysis.
NoOperation()
Default constructor.
Base class for reference counted objects.
Definition: SharedObject.h:64
static IndexIntervals largestEarliestNonOverlapping(const IndexIntervals &)
Select certain no-op sequences.
static Sawyer::Message::Facility mlog
Diagnostic streams.
Definition: NoOperation.h:67
const Sawyer::Optional< rose_addr_t > initialStackPointer() const
Property: initial concrete value for stack pointer.
Definition: NoOperation.h:106
Sawyer::Container::Interval< size_t > IndexInterval
An interval of instruction indices.
Definition: NoOperation.h:17
void ignorePoppedMemory(size_t nbytes)
Property: ignore recently popped memory.
Definition: NoOperation.h:46
StateNormalizer::Ptr stateNormalizer() const
Property: state normalizer.
Definition: NoOperation.h:96
static Ptr instance()
Allocating constructor.
Definition: NoOperation.h:34
Analysis that looks for no-op equivalents.
Definition: NoOperation.h:14
bool ignoreTerminalBranches() const
Property: Whether terminal branches can be no-ops.
Definition: NoOperation.h:116
virtual InstructionSemantics::BaseSemantics::StatePtr initialState(const InstructionSemantics::BaseSemantics::DispatcherPtr &, SgAsmInstruction *firstInsn)
Constructs an initial state.
Sawyer::SharedPointer< StateNormalizer > Ptr
Shared ownership pointer to a StateNormalizer.
Definition: NoOperation.h:31