ROSE  0.9.9.139
BinaryNoOperation.h
1 #ifndef ROSE_BinaryAnalysis_BinaryNoOperation_H
2 #define ROSE_BinaryAnalysis_BinaryNoOperation_H
3 
4 #include <BaseSemantics2.h>
5 #include <Sawyer/Message.h>
6 
7 namespace Rose {
8 namespace BinaryAnalysis {
9 
10 class Disassembler;
11 
13 class NoOperation {
14 public:
17 
19  typedef std::vector<IndexInterval> IndexIntervals;
20 
23  protected:
24  size_t ignorePoppedMemory_;
25  StateNormalizer(): ignorePoppedMemory_(8192) {}
26  public:
27  virtual ~StateNormalizer() {}
28 
31 
33  static Ptr instance() {
34  return Ptr(new StateNormalizer);
35  }
36 
44  size_t ignorePoppedMemory() const { return ignorePoppedMemory_; }
45  void ignorePoppedMemory(size_t nbytes) { ignorePoppedMemory_ = nbytes; }
51 
57  };
58 
59 private:
61  StateNormalizer::Ptr normalizer_;
63  bool ignoreTerminalBranches_;
64 
65 public:
68 public:
74  : ignoreTerminalBranches_(true) {}
75 
78  : cpu_(cpu), normalizer_(StateNormalizer::instance()), ignoreTerminalBranches_(true) {}
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 InstructionSemantics2::BaseSemantics::StatePtr&) const;
150 };
151 
152 } // namespace
153 } // namespace
154 
155 #endif
Base class for normalizing a state.
virtual InstructionSemantics2::BaseSemantics::StatePtr initialState(const InstructionSemantics2::BaseSemantics::DispatcherPtr &, SgAsmInstruction *firstInsn)
Constructs an initial state.
size_t ignorePoppedMemory() const
Property: ignore recently popped memory.
std::vector< IndexInterval > IndexIntervals
A vector of instruction indices.
Base class for machine instructions.
Collection of streams.
Definition: Message.h:1579
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< class State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< class 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.
virtual std::string toString(const InstructionSemantics2::BaseSemantics::DispatcherPtr &, const InstructionSemantics2::BaseSemantics::StatePtr &)
Takes a state and returns a normalized string.
void ignoreTerminalBranches(bool b)
Property: Whether terminal branches can be no-ops.
void stateNormalizer(const StateNormalizer::Ptr &f)
Property: state normalizer.
static std::vector< bool > toVector(const IndexIntervals &, size_t size=0)
Return a boolean vector.
IndexIntervals findNoopSubsequences(const std::vector< SgAsmInstruction * > &) const
Finds all sequences of instructions that are equivalent to no-operation.
NoOperation()
Default constructor.
Base class for reference counted objects.
Definition: SharedObject.h:22
static IndexIntervals largestEarliestNonOverlapping(const IndexIntervals &)
Select certain no-op sequences.
static Sawyer::Message::Facility mlog
Diagnostic streams.
const Sawyer::Optional< rose_addr_t > initialStackPointer() const
Property: initial concrete value for stack pointer.
Sawyer::Container::Interval< size_t > IndexInterval
An interval of instruction indices.
void ignorePoppedMemory(size_t nbytes)
Property: ignore recently popped memory.
StateNormalizer::Ptr stateNormalizer() const
Property: state normalizer.
static Ptr instance()
Allocating constructor.
NoOperation(const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu)
Construct a new analysis with specified virtual CPU.
Analysis that looks for no-op equivalents.
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:41
bool ignoreTerminalBranches() const
Property: Whether terminal branches can be no-ops.
Sawyer::SharedPointer< StateNormalizer > Ptr
Shared ownership pointer to a StateNormalizer.