ROSE  0.11.31.0
BinaryNoOperation.h
1 #ifndef ROSE_BinaryAnalysis_BinaryNoOperation_H
2 #define ROSE_BinaryAnalysis_BinaryNoOperation_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <BaseSemantics2.h>
7 #include <Sawyer/Message.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 
12 class Disassembler;
13 
15 class NoOperation {
16 public:
19 
21  typedef std::vector<IndexInterval> IndexIntervals;
22 
25  protected:
26  size_t ignorePoppedMemory_;
27  StateNormalizer(): ignorePoppedMemory_(8192) {}
28  public:
29  virtual ~StateNormalizer() {}
30 
33 
35  static Ptr instance() {
36  return Ptr(new StateNormalizer);
37  }
38 
46  size_t ignorePoppedMemory() const { return ignorePoppedMemory_; }
47  void ignorePoppedMemory(size_t nbytes) { ignorePoppedMemory_ = nbytes; }
53 
59  };
60 
61 private:
63  StateNormalizer::Ptr normalizer_;
65  bool ignoreTerminalBranches_;
66 
67 public:
70 public:
76  : ignoreTerminalBranches_(true) {}
77 
80  : cpu_(cpu), normalizer_(StateNormalizer::instance()), ignoreTerminalBranches_(true) {}
81 
86 
98  StateNormalizer::Ptr stateNormalizer() const { return normalizer_; }
99  void stateNormalizer(const StateNormalizer::Ptr &f) { normalizer_ = f; }
108  const Sawyer::Optional<rose_addr_t> initialStackPointer() const { return initialSp_; }
109  void initialStackPointer(const Sawyer::Optional<rose_addr_t> &v) { initialSp_ = v; }
118  bool ignoreTerminalBranches() const { return ignoreTerminalBranches_; }
119  void ignoreTerminalBranches(bool b) { ignoreTerminalBranches_ = b; }
123  bool isNoop(SgAsmInstruction*) const;
124 
126  bool isNoop(const std::vector<SgAsmInstruction*>&) const;
127 
129  IndexIntervals findNoopSubsequences(const std::vector<SgAsmInstruction*>&) const;
130 
138  static IndexIntervals largestEarliestNonOverlapping(const IndexIntervals&);
139 
144  static std::vector<bool> toVector(const IndexIntervals&, size_t size=0);
145 
147  static void initDiagnostics();
148 
149 protected:
151  std::string normalizeState(const InstructionSemantics2::BaseSemantics::StatePtr&) const;
152 };
153 
154 } // namespace
155 } // namespace
156 
157 #endif
158 #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:1606
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
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< 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:64
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:50
bool ignoreTerminalBranches() const
Property: Whether terminal branches can be no-ops.
Sawyer::SharedPointer< StateNormalizer > Ptr
Shared ownership pointer to a StateNormalizer.