ROSE 0.11.145.147
StackDelta.h
1#ifndef ROSE_BinaryAnalysis_StackDelta_H
2#define ROSE_BinaryAnalysis_StackDelta_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
9#include <Sawyer/Map.h>
10
11#include <boost/serialization/access.hpp>
12#include <boost/serialization/split_member.hpp>
13
14namespace Rose {
15namespace BinaryAnalysis {
16
17// Forwards
18namespace Partitioner2 {
19 namespace DataFlow {
21 }
22}
23
27namespace StackDelta {
28
32// FIXME[Robb Matzke 2015-11-17]: add to Diagnostics.C and dummy functions.
34
39
55class Analysis {
56public:
61
62private:
64 Sawyer::Optional<rose_addr_t> initialConcreteStackPointer_; // where to start
65
66 bool hasResults_; // Are the following data members initialized?
67 bool didConverge_; // Are the following data membeers valid (else only approximations)?
68
69 SValuePair functionStackPtrs_; // Initial and final stack pointers
70 InstructionSemantics::BaseSemantics::SValuePtr functionDelta_; // Stack delta for entire function
71
72 SValuePairPerAddress bblockStackPtrs_; // Per-basic block initial and final stack pointers
73 DeltasPerAddress bblockDeltas_; // Stack delta per basic block (net effect of BB on stack ptr)
74
75 SValuePairPerAddress insnStackPtrs_; // Per-instruction initial and final stack pointers
76 DeltasPerAddress insnDeltas_; // Stack delta per instruction (net effect of insn on stack ptr)
77
78#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
79private:
80 friend class boost::serialization::access;
81
82 template<class S>
83 void serializeCommon(S &s, const unsigned version) {
84 if (version < 1)
85 s & BOOST_SERIALIZATION_NVP(cpu_);
86 s & BOOST_SERIALIZATION_NVP(initialConcreteStackPointer_);
87 s & BOOST_SERIALIZATION_NVP(hasResults_);
88 s & BOOST_SERIALIZATION_NVP(didConverge_);
89 s & BOOST_SERIALIZATION_NVP(functionStackPtrs_);
90 s & BOOST_SERIALIZATION_NVP(functionDelta_);
91 s & BOOST_SERIALIZATION_NVP(bblockStackPtrs_);
92 s & BOOST_SERIALIZATION_NVP(bblockDeltas_);
93 s & BOOST_SERIALIZATION_NVP(insnStackPtrs_);
94 s & BOOST_SERIALIZATION_NVP(insnDeltas_);
95 }
96
97 template<class S>
98 void save(S &s, const unsigned version) const {
99 const_cast<Analysis*>(this)->serializeCommon(s, version);
100 if (version >= 1) {
101 std::string archName;
103 if (cpu_) {
104 archName = Architecture::name(cpu_->architecture());
105 ops = cpu_->operators();
106 }
107 s & BOOST_SERIALIZATION_NVP(archName);
108 s & BOOST_SERIALIZATION_NVP(ops);
109 }
110 }
111
112 template<class S>
113 void load(S &s, const unsigned version) {
114 serializeCommon(s, version);
115 if (version >= 1) {
116 std::string archName;
118 s & BOOST_SERIALIZATION_NVP(archName);
119 s & BOOST_SERIALIZATION_NVP(ops);
120 if (!archName.empty())
121 cpu_ = Architecture::newInstructionDispatcher(archName, ops);
122 }
123 }
124
125 BOOST_SERIALIZATION_SPLIT_MEMBER();
126#endif
127
128public:
135 : hasResults_(false), didConverge_(false) {}
136
141 : hasResults_(false), didConverge_(false) {
142 init(d);
143 }
144
153 : cpu_(cpu), hasResults_(false), didConverge_(false) {}
154
162 Sawyer::Optional<rose_addr_t> initialConcreteStackPointer() const { return initialConcreteStackPointer_; }
163 void initialConcreteStackPointer(const Sawyer::Optional<rose_addr_t> &val) { initialConcreteStackPointer_ = val; }
171 void
174
179 bool hasResults() const { return hasResults_; }
180
185 bool didConverge() const { return didConverge_; }
186
192
197
202
208
213 SValuePair functionStackPointers() const { return functionStackPtrs_; }
214
220
226
231 SValuePair basicBlockStackPointers(rose_addr_t basicBlockAddress) const;
232
238
253 int64_t basicBlockStackDeltaConcrete(rose_addr_t basicBlockAddress) const;
254
260
267
283
290
295
301
307
309 void print(std::ostream&) const;
310
311public:
312 // Used internally. Do not document with doxygen.
313 void adjustInstruction(SgAsmInstruction*,
317
318private:
319 void init(const Disassembler::BasePtr&);
320};
321
322std::ostream& operator<<(std::ostream&, const Analysis&);
323
324} // namespace
325} // namespace
326} // namespace
327
328// Class versions must be at global scope
329BOOST_CLASS_VERSION(Rose::BinaryAnalysis::StackDelta::Analysis, 1);
330
331#endif
332#endif
Various tools for data-flow analysis.
Definition DataFlow.h:72
Predicate that decides when to use inter-procedural data-flow.
InstructionSemantics::BaseSemantics::SValuePtr instructionInputStackDeltaWrtFunction(SgAsmInstruction *) const
Stack delta for instruction w.r.t.
SValuePair instructionStackPointers(SgAsmInstruction *) const
Initial and final stack ponters for an analyzed instruction.
void analyzeFunction(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, Partitioner2::DataFlow::InterproceduralPredicate &)
Analyze one function.
void clearStackDeltas()
Clear stack deltas, not pointers.
InstructionSemantics::BaseSemantics::SValuePtr instructionStackDelta(SgAsmInstruction *) const
Stack delta for an instruction.
Sawyer::Optional< rose_addr_t > initialConcreteStackPointer() const
Property: Initial value to use for stack pointers.
Definition StackDelta.h:162
SValuePair functionStackPointers() const
Initial and final stack pointers for an analyzed function.
Definition StackDelta.h:213
int64_t instructionStackDeltaConcrete(SgAsmInstruction *) const
Concrete stack delta for an instruction.
void print(std::ostream &) const
Print multi-line value to specified stream.
void initialConcreteStackPointer(const Sawyer::Optional< rose_addr_t > &val)
Property: Initial value to use for stack pointers.
Definition StackDelta.h:163
void saveAnalysisResults(SgAsmFunction *) const
Update AST with analysis results.
static void clearAstStackDeltas(SgNode *)
Clear AST stack deltas.
InstructionSemantics::BaseSemantics::SValuePtr functionStackDelta() const
Stack delta for an analyzed function.
Definition StackDelta.h:219
InstructionSemantics::BaseSemantics::SValuePtr basicBlockOutputStackDeltaWrtFunction(rose_addr_t basicBlockAddress) const
Stack delta for block w.r.t.
int64_t functionStackDeltaConcrete() const
Concrete stack delta for an analyzed function.
InstructionSemantics::BaseSemantics::SValuePtr basicBlockStackDelta(rose_addr_t basicBlockAddress) const
Stack delta for an analyzed basic block.
InstructionSemantics::BaseSemantics::SValuePtr instructionOutputStackDeltaWrtFunction(SgAsmInstruction *) const
Stack delta for instruction w.r.t.
void clearNonResults()
Clears everything but results.
static int64_t toInt(const InstructionSemantics::BaseSemantics::SValuePtr &)
Convert a symbolic value to an integer.
Analysis(const InstructionSemantics::BaseSemantics::DispatcherPtr &cpu)
Construct an analysis using a specified dispatcher.
Definition StackDelta.h:152
int64_t basicBlockStackDeltaConcrete(rose_addr_t basicBlockAddress) const
Concrete stack delta for an analyzed basic block.
void clearStackPointers()
Clear stack pointers, not deltas.
InstructionSemantics::BaseSemantics::DispatcherPtr cpu() const
Virtual CPU used for analysis.
Definition StackDelta.h:300
bool hasResults() const
Whether a function has been analyzed.
Definition StackDelta.h:179
SValuePair basicBlockStackPointers(rose_addr_t basicBlockAddress) const
Initial and final stack pointers for a basic block.
void clearResults()
Clear analysis results.
Analysis(const Disassembler::BasePtr &d)
Construct an analyzer using a specified disassembler.
Definition StackDelta.h:140
InstructionSemantics::BaseSemantics::SValuePtr basicBlockInputStackDeltaWrtFunction(rose_addr_t basicBlockAddress) const
Stack delta for block w.r.t.
bool didConverge() const
Whether the analysis results are valid.
Definition StackDelta.h:185
Container associating values with keys.
Definition Sawyer/Map.h:72
Collection of streams.
Definition Message.h:1606
Holds a value or nothing.
Definition Optional.h:56
Represents a synthesized function.
Base class for machine instructions.
This class represents the base class for all IR nodes within Sage III.
InstructionSemantics::BaseSemantics::DispatcherPtr newInstructionDispatcher(const std::string &name, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &)
Create a new instruction dispatcher by name.
const std::string & name(const BaseConstPtr &)
Architecture name free function.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
Sawyer::Message::Facility mlog
Facility for diagnostic output.
void initDiagnostics()
Initialize diagnostics.
The ROSE library.