ROSE 0.11.145.192
VariableFinder.h
1#ifndef ROSE_BinaryAnalysis_Variables_VariableFinder_H
2#define ROSE_BinaryAnalysis_Variables_VariableFinder_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Variables/GlobalVariable.h>
8#include <Rose/BinaryAnalysis/Variables/StackVariable.h>
9
10#include <Sawyer/CommandLine.h>
11
12#include <chrono>
13
15
16namespace Rose {
17namespace BinaryAnalysis {
18namespace Variables {
19
24public:
26 struct Settings {
28 std::chrono::seconds gvarMethod1MaxTimePerFunction;
29
30 Settings()
32 };
33
41private:
42 Settings settings_;
43
44protected:
45 explicit VariableFinder(const Settings&);
46public:
48
49public:
52
56 const Settings& settings() const { return settings_; }
57 Settings& settings() { return settings_; }
65
100
116
119 StackVariable::Boundaries&/*in,out*/);
120
121// /** Initilialize offsets for function prologue.
122// *
123// * At the start of a function, we sometimes know where certain things are on the stack and their sizes. For instance, for
124// * powerpc after the function prologue sets up the stack frame, we know that the stack frame header contain two 4-byte
125// * quantities: the pointer to the parent frame, and the LR save area for callees and therefore we can add the three offsets
126// * that delimit the boundaries of these two "variables". */
127// void initializeFrameBoundaries(const StackFrame&, const Partitioner2::PartitionerConstPtr&, const Partitioner2::FunctionPtr&,
128// StackVariable::Boundaries &boundaries /*in,out*/);
129//
130// /** Find stack variable addresses.
131// *
132// * Given an instruction, look for operand subexpressions that reference memory based from a stack frame pointer, such as
133// * x86 "mov eax, [ebp - 12]". Returns the set of offsets from the frame pointer. */
134// std::set<int64_t> findFrameOffsets(const StackFrame&, const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*);
135//
136// /** Function that owns an instruction.
137// *
138// * Given an instruction, return one of the owning functions chosen arbitrarily. This is the method used by the version
139// * of @ref findStackVariables that takes an instruction argument. */
140// Partitioner2::FunctionPtr functionForInstruction(const Partitioner2::PartitionerConstPtr&, SgAsmInstruction*);
141//
178
182 std::set<Address> findConstants(const SymbolicExpression::Ptr&);
183
185 std::set<Address> findConstants(SgAsmInstruction*);
186
191
196
204 void removeOutliers(const StackFrame&, StackVariable::Boundaries &sortedBoundaries /*in,out*/);
205
208
211
214
215private:
216 // Searches for global variables using a per-function data-flow analysis and distinguishing between global variable
217 // addresses based on which instructions wrote to those addresses. The data-flow is inter-procedural only for calls to
218 // certain functions (such as the x86 get_pc_thunk variety of functions).
219 //
220 // The return value is a list of global variable addresses and the instructions at which each global variable address
221 // was detected.
222 AddressToAddresses findGlobalVariableVasMethod1(const Partitioner2::PartitionerConstPtr&);
223
224 // Searches for global variables by running each instruction individually in symbolic semantics and then searching
225 // the memory state addresses. All constants found in address expressions are gathered together.
226 //
227 // The return value is a list of global variable addresses and the instructions at which each global address was detected.
228 AddressToAddresses findGlobalVariableVasMethod2(const Partitioner2::PartitionerConstPtr&);
229
230 // Searches for global variables by looking for constants in instruction ASTs.
231 //
232 // The retun value is the list of constants and the instructions in which each constant appeared.
233 AddressToAddresses findGlobalVariableVasMethod3(const Partitioner2::PartitionerConstPtr&);
234
235 // Merge one set of addresses and their defining instructions into another.
236 static void merge(AddressToAddresses&, const AddressToAddresses&);
237};
238
239} // namespace
240} // namespace
241} // namespace
242
243#endif
244#endif
Information about a stack frame.
Definition StackFrame.h:35
std::vector< Boundary > Boundaries
List of boundaries.
Analysis to find variable locations.
static bool regionIsFullyReadWrite(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region is fully mapped with read and write access.
std::set< Address > findConstants(SgAsmInstruction *)
Find constants syntactically in an instruction.
VariableFinderPtr Ptr
Shared ownership pointer for VariableFinder.
void evict(const Partitioner2::PartitionerConstPtr &)
Removed cached information.
StackVariables findStackVariables(const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *)
Find local variables in a function.
const Settings & settings() const
Settings for this analysis.
Settings & settings()
Settings for this analysis.
void removeOutliers(const StackFrame &, StackVariable::Boundaries &sortedBoundaries)
Remove boundaries that are outside a stack frame.
std::set< Address > findAddressConstants(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find constants in memory.
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &)
Command-line switches for analysis settings.
StackFrame detectFrameAttributes(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &)
Figure out attributes describing the stack frame for the specified function.
std::set< SymbolicExpression::Ptr > getMemoryAddresses(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find addresses in memory state.
std::set< Address > findConstants(const SymbolicExpression::Ptr &)
Find address constants in an expression.
static Ptr instance(const Settings &settings=Settings())
Allocating constructor.
static bool regionContainsInstructions(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region contains any decoded instructions.
VariableFinderConstPtr ConstPtr
Shared ownership pointer for VariableFinder.
GlobalVariables findGlobalVariables(const Partitioner2::PartitionerConstPtr &)
Find global variables.
bool isCached(const Partitioner2::FunctionPtr &)
Test whether local variable information is cached.
void evict(const Partitioner2::FunctionPtr &)
Removed cached information.
StackVariables findStackVariables(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Find local variables in a function.
AddressToAddresses findGlobalVariableVas(const Partitioner2::PartitionerConstPtr &)
Find global variable addresses.
static bool regionIsFullyMapped(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region is fully mapped.
A collection of related switch declarations.
Base class for machine instructions.
boost::shared_ptr< class MemoryCellState > MemoryCellStatePtr
Shared-ownership pointer to a cell-based memory state.
std::map< Address, AddressSet > AddressToAddresses
Mapping from addresses to address sets.
std::shared_ptr< const VariableFinder > VariableFinderConstPtr
Shared ownership pointer to VariableFinder.
std::shared_ptr< VariableFinder > VariableFinderPtr
Shared ownership pointer to VariableFinder.
The ROSE library.
std::chrono::seconds gvarMethod1MaxTimePerFunction
Max time to spend in Method 1 global variable analysis per function.