ROSE 0.11.145.147
CallingConvention/Analysis.h
1#ifndef ROSE_BinaryAnalysis_CallingConvention_Analysis_H
2#define ROSE_BinaryAnalysis_CallingConvention_Analysis_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/CallingConvention/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/RegisterParts.h>
8#include <Rose/BinaryAnalysis/Variables.h>
9
10#include <Sawyer/Optional.h>
11
12namespace Rose {
13namespace BinaryAnalysis {
14namespace CallingConvention {
15
19class Analysis {
20private:
22 RegisterDictionaryPtr regDict_; // Names for the register parts
23 DefinitionPtr defaultCc_; // Default calling convention for called functions
24
25 bool hasResults_; // Are the following data members initialized?
26 bool didConverge_; // Are the following data members valid (else only approximations)?
27 RegisterParts restoredRegisters_; // Registers accessed but restored
28 RegisterParts inputRegisters_; // Registers that serve as possible input parameters
29 RegisterParts outputRegisters_; // Registers that hold possible return values
30 Variables::StackVariables inputStackParameters_; // Stack variables serving as function inputs
31 Variables::StackVariables outputStackParameters_; // Stack variables serving as possible return values
32 Sawyer::Optional<int64_t> stackDelta_; // Change in stack across entire function
33 // Don't forget to update clearResults() and serialize() if you add more.
34
35#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
36private:
37 friend class boost::serialization::access;
38
39 template<class S>
40 void serialize(S &s, const unsigned /*version*/) {
41 s & BOOST_SERIALIZATION_NVP(cpu_);
42 s & BOOST_SERIALIZATION_NVP(regDict_);
43 s & BOOST_SERIALIZATION_NVP(defaultCc_);
44 s & BOOST_SERIALIZATION_NVP(hasResults_);
45 s & BOOST_SERIALIZATION_NVP(didConverge_);
46 s & BOOST_SERIALIZATION_NVP(restoredRegisters_);
47 s & BOOST_SERIALIZATION_NVP(inputRegisters_);
48 s & BOOST_SERIALIZATION_NVP(outputRegisters_);
49 s & BOOST_SERIALIZATION_NVP(inputStackParameters_);
50 s & BOOST_SERIALIZATION_NVP(outputStackParameters_);
51 s & BOOST_SERIALIZATION_NVP(stackDelta_);
52 }
53#endif
54
55public:
62 ~Analysis();
63
68
76
94
99 bool hasResults() const { return hasResults_; }
100
105 bool didConverge() const { return didConverge_; }
106
112
118
134 const RegisterParts& calleeSavedRegisters() const { return restoredRegisters_; }
135
140 const RegisterParts& inputRegisters() const { return inputRegisters_; }
141
146 const RegisterParts& outputRegisters() const { return outputRegisters_; }
147
151 const Variables::StackVariables& inputStackParameters() const { return inputStackParameters_; }
152
156 const Variables::StackVariables& outputStackParameters() const { return outputStackParameters_; }
157
162 Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
163
167 bool match(const DefinitionPtr&) const;
168
175
180 void print(std::ostream&, bool multiLine=false) const;
181
182private:
183 // Finish constructing
184 void init(const Disassembler::BasePtr&);
185
186 // Recompute the restoredRegisters_ data member.
187 void updateRestoredRegisters(const InstructionSemantics::BaseSemantics::StatePtr &initialState,
189
190 // Recompute the inputRegisters_ data member after updateRestoredRegisters is computed.
191 void updateInputRegisters(const InstructionSemantics::BaseSemantics::StatePtr &state);
192
193 // Recompute the outputRegisters_ data member after updateRestoredRegisters is computed.
194 void updateOutputRegisters(const InstructionSemantics::BaseSemantics::StatePtr &state);
195
196 // Recompute the input and output stack variables
197 void updateStackParameters(const Partitioner2::FunctionPtr &function,
200
201 // Recomputes the stack delta
202 void updateStackDelta(const InstructionSemantics::BaseSemantics::StatePtr &initialState,
204};
205
206} // namespace
207} // namespace
208} // namespace
209
210#endif
211#endif
const RegisterParts & inputRegisters() const
Input registers.
const Variables::StackVariables & inputStackParameters() const
Input stack parameters.
void print(std::ostream &, bool multiLine=false) const
Print information about the analysis results.
const RegisterParts & calleeSavedRegisters() const
Callee-saved registers.
void defaultCallingConvention(const DefinitionPtr &)
Property: Default calling convention.
bool match(const DefinitionPtr &) const
Determine whether a definition matches.
void registerDictionary(const RegisterDictionaryPtr &d)
Property: Register dictionary.
Sawyer::Optional< int64_t > stackDelta() const
Concrete stack delta.
void analyzeFunction(const Partitioner2::PartitionerConstPtr &, const Sawyer::SharedPointer< Partitioner2::Function > &)
Analyze one function.
const RegisterParts & outputRegisters() const
Output registers.
void clearResults()
Clear analysis results.
bool didConverge() const
Whether the analysis results are valid.
DefinitionPtr defaultCallingConvention() const
Property: Default calling convention.
void clearNonResults()
Clears everything but results.
Dictionary match(const Dictionary &) const
Find matching calling convention definitions.
bool hasResults() const
Whether a function has been analyzed.
Analysis(const InstructionSemantics::BaseSemantics::DispatcherPtr &)
Construct an analysis using a specified dispatcher.
Analysis(const Disassembler::BasePtr &)
Construct an analyzer using a specified disassembler.
RegisterDictionaryPtr registerDictionary() const
Property: Register dictionary.
const Variables::StackVariables & outputStackParameters() const
Output stack parameters.
Holds a set of registers without regard for register boundaries.
Holds a value or nothing.
Definition Optional.h:56
std::vector< DefinitionPtr > Dictionary
An ordered collection of calling convention definitions.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
The ROSE library.