1 #ifndef ROSE_BinaryAnalysis_InstructionProvider_H
2 #define ROSE_BinaryAnalysis_InstructionProvider_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/CallingConvention.h>
8 #include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
9 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
10 #include "AstSerialization.h"
12 #include <boost/serialization/access.hpp>
13 #include <Sawyer/Assert.h>
14 #include <Sawyer/HashMap.h>
15 #include <Sawyer/SharedPointer.h>
18 namespace BinaryAnalysis {
43 mutable InsnMap insnMap_;
44 bool useDisassembler_;
46 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
48 friend class boost::serialization::access;
51 void save(S &s,
const unsigned )
const {
52 roseAstSerializationRegistration(s);
53 bool hasDisassembler = disassembler_ != NULL;
54 s <<BOOST_SERIALIZATION_NVP(hasDisassembler);
55 s <<BOOST_SERIALIZATION_NVP(useDisassembler_);
56 s <<BOOST_SERIALIZATION_NVP(memMap_);
58 const size_t mapSize = insnMap_.
size();
59 s <<BOOST_SERIALIZATION_NVP(mapSize);
60 for (
const auto &insn: insnMap_.
values())
63 if (hasDisassembler) {
65 s <<BOOST_SERIALIZATION_NVP(disName);
70 void load(S &s,
const unsigned ) {
71 roseAstSerializationRegistration(s);
72 bool hasDisassembler =
false;
73 s >>BOOST_SERIALIZATION_NVP(hasDisassembler);
74 s >>BOOST_SERIALIZATION_NVP(useDisassembler_);
75 s >>BOOST_SERIALIZATION_NVP(memMap_);
78 s >>BOOST_SERIALIZATION_NVP(mapSize);
79 for (
size_t i = 0; i < mapSize; ++i) {
80 SgNode *node = restoreAst(s);
81 auto insn = isSgAsmInstruction(node);
82 ASSERT_require(!node || insn);
83 insnMap_.
insert(insn->get_address(), insn);
86 if (hasDisassembler) {
88 s >>BOOST_SERIALIZATION_NVP(disName);
90 ASSERT_not_null2(disassembler_,
"disassembler name=" + disName);
94 BOOST_SERIALIZATION_SPLIT_MEMBER();
98 InstructionProvider();
103 ~InstructionProvider();
126 return useDisassembler_;
130 useDisassembler_ =
false;
RegisterDescriptor instructionPointerRegister() const
Register used as the instruction pointer.
InstructionSemantics::BaseSemantics::DispatcherPtr dispatcher() const
Instruction dispatcher.
Sawyer::Container::HashMap< rose_addr_t, SgAsmInstruction * > InsnMap
Mapping from address to instruction.
boost::iterator_range< ValueIterator > values()
Iterators for container values.
const CallingConvention::Dictionary & callingConventions() const
Returns the calling convention dictionary.
void disableDisassembler()
Enable or disable the disassembler.
RegisterDescriptor stackSegmentRegister() const
Register used as a segment to access stack memory.
size_t wordSize() const
Word size in bits.
void showStatistics() const
Print some partitioner performance statistics.
Base class for machine instructions.
Provides and caches instructions.
RegisterDescriptor stackPointerRegister() const
Register used as a user-mode stack pointer.
Disassembler::BasePtr disassembler() const
Returns the disassembler.
Main namespace for the ROSE library.
RegisterDescriptor stackFrameRegister() const
Register used for function call frames.
ByteOrder::Endianness defaultByteOrder() const
Default memory byte order.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
size_t size() const
Number of nodes, keys, or values in this container.
RegisterDescriptor callReturnRegister() const
Register holding a function call's return address.
MemoryMapPtr Ptr
Reference counting pointer.
std::vector< Definition::Ptr > Dictionary
A ordered collection of calling convention definitions.
HashMap & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Describes (part of) a physical CPU register.
This class represents the base class for all IR nodes within Sage III.
static Ptr instance(const Disassembler::BasePtr &disassembler, const MemoryMap::Ptr &map)
Static allocating Constructor.
bool isDisassemblerEnabled() const
Enable or disable the disassembler.
RegisterDictionaryPtr registerDictionary() const
Returns the register dictionary.
Sawyer::SharedPointer< InstructionProvider > Ptr
Shared-ownership pointer.
void insert(SgAsmInstruction *)
Insert an instruction into the cache.
const std::string & name(const BasePtr &)
Disassembler name free function.
Base class for reference counted objects.
BasePtr lookup(SgAsmGenericHeader *)
Finds a suitable disassembler for a file header.
void enableDisassembler(bool enable=true)
Enable or disable the disassembler.
Sawyer::SharedPointer< Base > BasePtr
Reference counted pointer for disassemblers.
SgAsmInstruction * operator[](rose_addr_t va) const
Returns the instruction at the specified virtual address, or null.
size_t instructionAlignment() const
Alignment requirement for instructions.
size_t nCached() const
Returns number of cached starting addresses.