ROSE 0.11.145.147
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
10namespace Rose {
11namespace BinaryAnalysis {
12
15public:
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
60private:
62 StateNormalizer::Ptr normalizer_;
64 bool ignoreTerminalBranches_ = true;
65
66public:
69public:
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; }
122
124 bool isNoop(const std::vector<SgAsmInstruction*>&) const;
125
127 IndexIntervals findNoopSubsequences(const std::vector<SgAsmInstruction*>&) const;
128
137
142 static std::vector<bool> toVector(const IndexIntervals&, size_t size=0);
143
145 static void initDiagnostics();
146
147protected:
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
virtual InstructionSemantics::BaseSemantics::StatePtr initialState(const InstructionSemantics::BaseSemantics::DispatcherPtr &, SgAsmInstruction *firstInsn)
Constructs an initial state.
static Ptr instance()
Allocating constructor.
Definition NoOperation.h:34
Sawyer::SharedPointer< StateNormalizer > Ptr
Shared ownership pointer to a NoOperation::StateNormalizer.
Definition NoOperation.h:31
virtual std::string toString(const InstructionSemantics::BaseSemantics::DispatcherPtr &, const InstructionSemantics::BaseSemantics::StatePtr &)
Takes a state and returns a normalized string.
size_t ignorePoppedMemory() const
Property: ignore recently popped memory.
Definition NoOperation.h:45
void ignorePoppedMemory(size_t nbytes)
Property: ignore recently popped memory.
Definition NoOperation.h:46
Analysis that looks for no-op equivalents.
Definition NoOperation.h:14
NoOperation(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu)
Construct a new analysis with specified virtual CPU.
Definition NoOperation.h:77
bool isNoop(SgAsmInstruction *) const
Determines if an instruction is a no-op.
Sawyer::Container::Interval< size_t > IndexInterval
An interval of instruction indices.
Definition NoOperation.h:17
bool ignoreTerminalBranches() const
Property: Whether terminal branches can be no-ops.
IndexIntervals findNoopSubsequences(const std::vector< SgAsmInstruction * > &) const
Finds all sequences of instructions that are equivalent to no-operation.
void ignoreTerminalBranches(bool b)
Property: Whether terminal branches can be no-ops.
const Sawyer::Optional< rose_addr_t > initialStackPointer() const
Property: initial concrete value for stack pointer.
std::vector< IndexInterval > IndexIntervals
A vector of instruction indices.
Definition NoOperation.h:20
static IndexIntervals largestEarliestNonOverlapping(const IndexIntervals &)
Select certain no-op sequences.
static void initDiagnostics()
Initializes and registers disassembler diagnostic streams.
NoOperation()
Default constructor.
bool isNoop(const std::vector< SgAsmInstruction * > &) const
Determines if a sequence of instructions is a no-op.
NoOperation(const BinaryAnalysis::Disassembler::BasePtr &)
Construct a new analysis for a specific disassembler.
void initialStackPointer(const Sawyer::Optional< rose_addr_t > &v)
Property: initial concrete value for stack pointer.
StateNormalizer::Ptr stateNormalizer() const
Property: state normalizer.
Definition NoOperation.h:96
static std::vector< bool > toVector(const IndexIntervals &, size_t size=0)
Return a boolean vector.
static Sawyer::Message::Facility mlog
Diagnostic streams.
Definition NoOperation.h:67
void stateNormalizer(const StateNormalizer::Ptr &f)
Property: state normalizer.
Definition NoOperation.h:97
Range of values delimited by endpoints.
Definition Interval.h:31
Collection of streams.
Definition Message.h:1606
Holds a value or nothing.
Definition Optional.h:56
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Base class for machine instructions.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
The ROSE library.