1#ifndef ROSE_BinaryAnalysis_Variables_H
2#define ROSE_BinaryAnalysis_Variables_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
8#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
9#include <Rose/BinaryAnalysis/SymbolicExpression.h>
11#include <Sawyer/IntervalMap.h>
12#include <Sawyer/Message.h>
13#include <Sawyer/Optional.h>
14#include <Sawyer/Set.h>
16#include <boost/serialization/access.hpp>
17#include <boost/serialization/split_member.hpp>
27namespace BinaryAnalysis {
74 rose_addr_t maxSizeBytes_ = 0;
79#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
81 friend class boost::serialization::access;
84 void serialize(S &s,
const unsigned ) {
85 s & BOOST_SERIALIZATION_NVP(maxSizeBytes_);
86 s & BOOST_SERIALIZATION_NVP(insnVas_);
87 s & BOOST_SERIALIZATION_NVP(ioProperties_);
88 s & BOOST_SERIALIZATION_NVP(name_);
143 const std::string&
name()
const;
144 void name(
const std::string &s);
180 int64_t frameOffset_ = 0;
183#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
185 friend class boost::serialization::access;
188 void serialize(S &s,
const unsigned version) {
190 s & BOOST_SERIALIZATION_NVP(function_);
191 s & BOOST_SERIALIZATION_NVP(frameOffset_);
193 s & BOOST_SERIALIZATION_NVP(purpose_);
273 explicit operator bool()
const {
303 rose_addr_t address_ = 0;
305#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
307 friend class boost::serialization::access;
310 void serialize(S &s,
const unsigned ) {
312 s & BOOST_SERIALIZATION_NVP(address_);
369 explicit operator bool()
const {
563 OffsetInterval referencedFrameArea(const Partitioner2::Partitioner&,
639 InstructionSemantics::BaseSemantics::SValuePtr
Partitions instructions into basic blocks and functions.
Describes (part of) a physical CPU register.
Describes a local or global variable.
BaseVariable()
Default constructor.
AddressSet & definingInstructionVas()
Property: Addresses of instructions related to this variable.
void maxSizeBytes(rose_addr_t size)
Property: Maximum variable size in bytes.
InstructionSemantics::BaseSemantics::InputOutputPropertySet & ioProperties()
Property: I/O properties.
BaseVariable(size_t maxSizeBytes, const AddressSet &definingInstructionVas, const std::string &name)
Construct a variable with a given maximum size.
void ioProperties(const InstructionSemantics::BaseSemantics::InputOutputPropertySet &set)
Property: I/O properties.
void name(const std::string &s)
Property: Optional variable name.
rose_addr_t maxSizeBytes() const
Property: Maximum variable size in bytes.
const AddressSet & definingInstructionVas() const
Property: Addresses of instructions related to this variable.
const InstructionSemantics::BaseSemantics::InputOutputPropertySet & ioProperties() const
Property: I/O properties.
void definingInstructionVas(const AddressSet &vas)
Property: Addresses of instructions related to this variable.
const std::string & name() const
Property: Optional variable name.
Description of a global variable.
bool operator!=(const GlobalVariable &other) const
Compare two global variable descriptors.
GlobalVariable(rose_addr_t startingAddress, rose_addr_t maxSizeBytes, const AddressSet &definingInstructionVas=AddressSet(), const std::string &name="")
Constructor.
bool operator==(const GlobalVariable &other) const
Compare two global variable descriptors.
std::string toString() const
Printing global variable.
const std::string & setDefaultName()
Give variable a defult name.
void address(rose_addr_t va)
Property: Starting address.
AddressInterval interval() const
Location of variable in memory.
bool operator!() const
Predicate to test whether variable is invalid.
void print(std::ostream &) const
Printing global variable.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::GlobalVariable &)
Print global variable descriptor.
GlobalVariable()
Default constructor.
rose_addr_t address() const
Property: Starting address.
Information about a stack frame.
Sawyer::Optional< int64_t > maxOffset
Maximum frame offset w.r.t.
RegisterDescriptor framePointerRegister
Optional descriptor for register pointing to latest frame.
Sawyer::Optional< uint64_t > size
Size of the frame in bytes if known.
Sawyer::Optional< int64_t > minOffset
Minimum frame offset w.r.t.
std::string rule
Informal rule name used to detect frame characteristics.
@ GROWS_UP
New frames are added at higher addresses than old frames.
@ GROWS_DOWN
New frames are added at lower addresses than old frames.
Direction growthDirection
Direction that the stack grows when pushing a new frame.
Description of a local stack variable within a function.
std::string toString() const
Printing local variable.
OffsetInterval interval() const
Location within the function stack frame.
const std::string & setDefaultName()
Give variable a defult name.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::StackVariable &)
Print local variable descriptor.
bool operator==(const StackVariable &other) const
Compare two local variables.
bool operator!=(const StackVariable &other) const
Compare two local variables.
static Boundary & insertBoundary(Boundaries &, int64_t frameOffset, rose_addr_t insnVa)
Insert a new boundary or adjust an existing boundary.
std::vector< Boundary > Boundaries
List of boundaries.
Purpose purpose() const
Property: Purpose.
void print(std::ostream &) const
Printing local variable.
Purpose
Purpose of variable.
@ OTHER
None of the above purposes.
@ NORMAL
Normal source code level variable.
@ UNKNOWN
Purpose is unknown.
@ RETURN_ADDRESS
Possible or known return address.
@ SPILL_AREA
Callee-saved registers.
@ FRAME_POINTER
Pointer to previous stack frame.
void frameOffset(int64_t offset)
Property: Frame offset.
StackVariable()
Default constructor.
StackVariable(const Partitioner2::FunctionPtr &, int64_t frameOffset, rose_addr_t maxSizeBytes, Purpose, const AddressSet &definingInstructionVas=AddressSet(), const std::string &name="")
Construct a variable descriptor.
void purpose(Purpose p)
Property: Purpose.
void function(const Partitioner2::FunctionPtr &)
Property: Function owning the variable.
int64_t frameOffset() const
Property: Frame offset.
bool operator!() const
Predicate to test whether variable is invalid.
Partitioner2::FunctionPtr function() const
Property: Function owning the variable.
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< rose_addr_t > findAddressConstants(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find constants in memory.
StackFrame detectFrameAttributes(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Figure out attributes describing the stack frame for the specified function.
std::set< int64_t > findFrameOffsets(const StackFrame &, const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *)
Find stack variable addresses.
void evict(const Partitioner2::PartitionerConstPtr &)
Removed cached information.
void removeOutliers(const StackFrame &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &sortedBoundaries)
Remove boundaries that are outside a stack frame.
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 initializeFrameBoundaries(const StackFrame &, const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, StackVariable::Boundaries &boundaries)
Initilialize offsets for function prologue.
std::set< SymbolicExpression::Ptr > getMemoryAddresses(const InstructionSemantics::BaseSemantics::MemoryCellStatePtr &)
Find addresses in memory state.
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.
GlobalVariables findGlobalVariables(const Partitioner2::PartitionerConstPtr &)
Find global variables.
std::set< rose_addr_t > findConstants(SgAsmInstruction *)
Find constants syntactically in an instruction.
bool isCached(const Partitioner2::FunctionPtr &)
Test whether local variable information is cached.
void evict(const Partitioner2::FunctionPtr &)
Removed cached information.
std::set< rose_addr_t > findConstants(const SymbolicExpression::Ptr &)
Find address constants in an expression.
StackVariables findStackVariables(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Find local variables in a function.
AddressToAddresses findGlobalVariableVas(const Partitioner2::PartitionerConstPtr &)
Find global variable addresses.
Partitioner2::FunctionPtr functionForInstruction(const Partitioner2::PartitionerConstPtr &, SgAsmInstruction *)
Function that owns an instruction.
static bool regionIsFullyMapped(const Partitioner2::PartitionerConstPtr &, const AddressInterval &)
True if memory region is fully mapped.
Range of values delimited by endpoints.
bool isEmpty() const
True if interval is empty.
Converts text to messages.
Holds a value or nothing.
Base class for reference counted objects.
Base class for machine instructions.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< class MemoryCellState > MemoryCellStatePtr
Shared-ownership pointer to a cell-based memory state.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of addresses.
void initDiagnostics()
Initialize diagnostic output.
std::map< rose_addr_t, AddressSet > AddressToAddresses
Mapping from addresses to address sets.
std::string offsetStr(int64_t offset)
Format a stack offset as a string.
Sawyer::Container::IntervalMap< AddressInterval, GlobalVariable > GlobalVariables
Maps virtual addresses to global variables.
std::map< int64_t, AddressSet > OffsetToAddresses
Mapping from stack offsets to address sets.
void print(const StackVariables &, const Partitioner2::PartitionerConstPtr &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
void erase(GlobalVariables &, const AddressInterval &toErase)
Erase some global variables.
Sawyer::Message::Facility mlog
Diagnostic facility.
std::string sizeStr(uint64_t size)
Format size as a string.
Sawyer::SharedPointer< VariableFinder > VariableFinderPtr
Reference counting pointer.
AddressInterval isInconsistent(const GlobalVariables &, Sawyer::Message::Stream &)
Check that the map is consistent.
Sawyer::Container::Interval< int64_t > OffsetInterval
Interval of signed offsets.
Boundary between stack variables.
Purpose purpose
Purpose of addresses above this boundary.
int64_t frameOffset
Address of boundary with respect to frame pointer.
AddressSet definingInsns
Instructions that define this boundary.
Settings that control this analysis.
std::chrono::seconds gvarMethod1MaxTimePerFunction
Max time to spend in Method 1 global variable analysis per function.