1 #ifndef ROSE_BinaryAnalysis_Variables_H
2 #define ROSE_BinaryAnalysis_Variables_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <BaseSemanticsTypes.h>
7 #include <boost/serialization/access.hpp>
8 #include <boost/serialization/split_member.hpp>
9 #include <MemoryCellState.h>
10 #include <Partitioner2/BasicTypes.h>
11 #include <Sawyer/IntervalMap.h>
12 #include <Sawyer/Message.h>
13 #include <Sawyer/Optional.h>
14 #include <Sawyer/Set.h>
56 std::string
sizeStr(uint64_t size);
64 rose_addr_t maxSizeBytes_;
69 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
71 friend class boost::serialization::access;
74 void serialize(S &s,
const unsigned ) {
75 s & BOOST_SERIALIZATION_NVP(maxSizeBytes_);
76 s & BOOST_SERIALIZATION_NVP(insnVas_);
77 s & BOOST_SERIALIZATION_NVP(ioProperties_);
78 s & BOOST_SERIALIZATION_NVP(name_);
93 : maxSizeBytes_(
std::min(maxSizeBytes, ((size_t)(1) << (8*sizeof(size_t)-1))-1)),
94 insnVas_(definingInstructionVas), name_(name) {}
134 const std::string&
name()
const {
return name_; }
135 void name(
const std::string &s) { name_ = s; }
146 int64_t frameOffset_;
148 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
150 friend class boost::serialization::access;
153 void serialize(S &s,
const unsigned ) {
155 s & BOOST_SERIALIZATION_NVP(function_);
156 s & BOOST_SERIALIZATION_NVP(frameOffset_);
213 void print(std::ostream&)
const;
236 rose_addr_t address_;
238 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
240 friend class boost::serialization::access;
243 void serialize(S &s,
const unsigned ) {
245 s & BOOST_SERIALIZATION_NVP(address_);
268 rose_addr_t
address()
const {
return address_; }
269 void address(rose_addr_t va) { address_ = va; }
292 void print(std::ostream&)
const;
std::string toString() const
Printing global variable.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::StackVariable &)
Print local variable descriptor.
const Settings & settings() const
Settings for this analysis.
const AddressSet & definingInstructionVas() const
Property: Addresses of instructions related to this variable.
static RegisterDescriptor frameOrStackPointer(const Partitioner2::Partitioner &)
The register typically used as local variable base address.
Description of a global variable.
boost::shared_ptr< class MemoryCellState > MemoryCellStatePtr
Shared-ownership pointer to a cell-based memory state.
VariableFinder(const Settings &settings=Settings())
Construct a new analyzer.
Sawyer::Message::Facility mlog
Diagnostic facility.
Base class for machine instructions.
AddressInterval interval() const
Location of variable in memory.
Analysis to find variable locations.
Describes a local or global variable.
const std::string & name() const
Property: Optional variable name.
InstructionSemantics2::BaseSemantics::InputOutputPropertySet & ioProperties()
Property: I/O properties.
void address(rose_addr_t va)
Property: Starting address.
const std::string & setDefaultName()
Give variable a defult name.
void evict(const Partitioner2::FunctionPtr &)
Removed cached information.
AddressToAddresses findGlobalVariableVas(const Partitioner2::Partitioner &)
Find global variable addresses.
friend std::ostream & operator<<(std::ostream &, const Rose::BinaryAnalysis::Variables::GlobalVariable &)
Print global variable descriptor.
bool operator==(const StackVariable &other) const
Compare two local variables.
void name(const std::string &s)
Property: Optional variable name.
void print(const StackVariables &, const Partitioner2::Partitioner &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
void initDiagnostics()
Initialize diagnostic output.
Main namespace for the ROSE library.
std::map< rose_addr_t, AddressSet > AddressToAddresses
Mapping from addresses to address sets.
StackVariable()
Default constructor.
rose_addr_t address() const
Property: Starting address.
GlobalVariable()
Default constructor.
OffsetInterval interval() const
Location within the function stack frame.
void ioProperties(const InstructionSemantics2::BaseSemantics::InputOutputPropertySet &set)
Property: I/O properties.
std::string sizeStr(uint64_t size)
Format size as a string.
BaseVariable()
Default constructor.
void definingInstructionVas(const AddressSet &vas)
Property: Addresses of instructions related to this variable.
void print(std::ostream &) const
Printing global variable.
std::map< int64_t, AddressSet > OffsetToAddresses
Mapping from stack offsets to address sets.
std::set< SymbolicExpr::Ptr > getMemoryAddresses(const InstructionSemantics2::BaseSemantics::MemoryCellStatePtr &)
Find addresses in memory state.
Describes (part of) a physical CPU register.
const InstructionSemantics2::BaseSemantics::InputOutputPropertySet & ioProperties() const
Property: I/O properties.
BaseVariable(size_t maxSizeBytes, const AddressSet &definingInstructionVas, const std::string &name)
Construct a variable with a given maximum size.
bool isCached(const Partitioner2::FunctionPtr &)
Test whether local variable information is cached.
OffsetInterval referencedFrameArea(const Partitioner2::Partitioner &, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &, const SymbolicExpr::Ptr &address, size_t nBytes)
Find frame location for address.
rose_addr_t maxSizeBytes() const
Property: Maximum variable size in bytes.
std::set< rose_addr_t > findConstants(const SymbolicExpr::Ptr &)
Find address constants in an expression.
std::string offsetStr(int64_t offset)
Format a stack offset as a string.
Settings that control this analysis.
const std::string & setDefaultName()
Give variable a defult name.
bool operator!=(const StackVariable &other) const
Compare two local variables.
InstructionSemantics2::BaseSemantics::SValuePtr symbolicAddress(const Partitioner2::Partitioner &, const StackVariable &, const InstructionSemantics2::BaseSemantics::RiscOperatorsPtr &)
Return symbolic address of stack variable.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of addresses.
std::string toString() const
Printing local variable.
Sawyer::Optional< uint64_t > functionFrameSize(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Figure out the amount of stack space reserved by this function for local variables.
Range of values delimited by endpoints.
void frameOffset(int64_t offset)
Property: Frame offset.
int64_t frameOffset() const
Property: Frame offset.
void print(std::ostream &) const
Printing local variable.
AddressSet & definingInstructionVas()
Property: Addresses of instructions related to this variable.
Partitions instructions into basic blocks and functions.
Sawyer::Container::IntervalMap< AddressInterval, GlobalVariable > GlobalVariables
Maps virtual addresses to global variables.
Partitioner2::FunctionPtr functionForInstruction(const Partitioner2::Partitioner &, SgAsmInstruction *)
Function that owns an instruction.
std::set< rose_addr_t > findAddressConstants(const InstructionSemantics2::BaseSemantics::MemoryCellStatePtr &)
Find constants in memory.
Sawyer::Container::Interval< int64_t > OffsetInterval
Interval of signed offsets.
std::set< int64_t > findStackOffsets(const Partitioner2::Partitioner &, SgAsmInstruction *)
Find stack variable addresses.
StackVariables findStackVariables(const Partitioner2::Partitioner &, const Partitioner2::FunctionPtr &)
Find local variables in a function.
GlobalVariables findGlobalVariables(const Partitioner2::Partitioner &)
Find global variables.
Description of a local stack variable within a function.
Settings & settings()
Settings for this analysis.
Sawyer::Container::IntervalMap< OffsetInterval, StackVariable > StackVariables
Collection of local variables.
bool operator!=(const GlobalVariable &other) const
Compare two global variable descriptors.
bool operator==(const GlobalVariable &other) const
Compare two global variable descriptors.