ROSE 0.11.145.147
Disassembler/Base.h
1#ifndef ROSE_BinaryAnalysis_Disassembler_Base_H
2#define ROSE_BinaryAnalysis_Disassembler_Base_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Disassembler/BasicTypes.h>
8#include <Rose/BinaryAnalysis/Disassembler/Exception.h>
9#include <Rose/BinaryAnalysis/InstructionMap.h>
10#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
11#include <Rose/BinaryAnalysis/MemoryMap.h>
12#include <Rose/BinaryAnalysis/Unparser/Settings.h>
13#include <Rose/Diagnostics.h>
14
15#include "integerOps.h"
16#include "Map.h"
17
18#include <boost/serialization/access.hpp>
19#include <boost/serialization/string.hpp>
20#include <boost/serialization/version.hpp>
21
22// REG_SP possibly defined on __sun
23// REG_LINK possibly defined on Windows
24#undef REG_SP
25#undef REG_LINK
26
27namespace Rose {
28namespace BinaryAnalysis {
29namespace Disassembler {
30
50 // Types
52public:
53 using Ptr = BasePtr;
54
56 // Data members
58private:
59 Architecture::BaseConstPtr architecture_;
60
61protected:
62 RegisterDescriptor REG_IP, REG_SP, REG_SS, REG_SF, REG_LINK;
65public:
66
67
69 // Serialization
71#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
72private:
73 friend class boost::serialization::access;
74
75 template<class S>
76 void serialize(S &s, const unsigned version) {
77 s & BOOST_SERIALIZATION_NVP(REG_IP);
78 s & BOOST_SERIALIZATION_NVP(REG_SS);
79 if (version >= 1)
80 s & BOOST_SERIALIZATION_NVP(REG_SF);
81 if (version >= 2)
82 s & BOOST_SERIALIZATION_NVP(instructionAlignment_);
83 }
84#endif
85
86
88 // Constructors
90protected:
91 explicit Base(const Architecture::BaseConstPtr&);
92
93public:
94 virtual ~Base();
95
99 virtual Ptr clone() const = 0;
100
101
102 /***************************************************************************************************************************
103 * Disassembler properties and settings
104 ***************************************************************************************************************************/
105public:
110
114 virtual const std::string& name() const;
115
117 virtual size_t bytesPerWord() const;
118
121
127
131 size_t instructionAlignment() const;
132
133
134 /***************************************************************************************************************************
135 * Instruction disassembly functions
136 ***************************************************************************************************************************/
137public:
148 virtual SgAsmInstruction *disassembleOne(const MemoryMap::Ptr &map, rose_addr_t start_va, AddressSet *successors=NULL) = 0;
149
156 SgAsmInstruction *disassembleOne(const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va,
157 AddressSet *successors=NULL);
158
159
160 /***************************************************************************************************************************
161 * Miscellaneous methods
162 ***************************************************************************************************************************/
163public:
168
173
179 AddressSet get_block_successors(const InstructionMap&, bool &complete/*out*/);
180
186 static SgAsmInstruction *find_instruction_containing(const InstructionMap &insns, rose_addr_t va);
187
189 // Deprecated [Robb Matzke 2023-11-24]
191public:
192 size_t wordSizeBytes() const ROSE_DEPRECATED("use bytesPerWord()");
193 RegisterDictionaryPtr registerDictionary() const ROSE_DEPRECATED("use architecture()");
194 virtual RegisterDescriptor instructionPointerRegister() const ROSE_DEPRECATED("use architecture()");
195 virtual RegisterDescriptor stackPointerRegister() const ROSE_DEPRECATED("use architecture()");
196 virtual RegisterDescriptor stackFrameRegister() const ROSE_DEPRECATED("use architecture()");
197 virtual RegisterDescriptor stackSegmentRegister() const ROSE_DEPRECATED("use architecture()");
198 virtual RegisterDescriptor callReturnRegister() const ROSE_DEPRECATED("use architecture()");
199};
200
201} // namespace
202} // namespace
203} // namespace
204
205// Class versions must be at global scope
206BOOST_CLASS_VERSION(Rose::BinaryAnalysis::Disassembler::Base, 3);
207
208#endif
209#endif
Virtual base class for instruction disassemblers.
size_t instructionAlignment() const
Property: Instruction alignment requirement.
virtual SgAsmInstruction * makeUnknownInstruction(const Exception &)=0
Makes an unknown instruction from an exception.
virtual const std::string & name() const
Property: Name.
Unparser::BasePtr unparser() const
Unparser.
size_t instructionAlignment_
Positive alignment constraint for instruction addresses.
virtual Ptr clone() const =0
Creates a new copy of a disassembler.
virtual size_t bytesPerWord() const
Property: Bytes per word for the architecture.
SgAsmInstruction * disassembleOne(const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL)
Similar in functionality to the disassembleOne method that takes a MemoryMap argument,...
Architecture::BaseConstPtr architecture() const
Property: Architecture.
virtual SgAsmInstruction * disassembleOne(const MemoryMap::Ptr &map, rose_addr_t start_va, AddressSet *successors=NULL)=0
This is the lowest level disassembly function and is implemented in the architecture-specific subclas...
static SgAsmInstruction * find_instruction_containing(const InstructionMap &insns, rose_addr_t va)
Finds the highest-address instruction that contains the byte at the specified virtual address.
RegisterDescriptor REG_LINK
Register descriptors initialized during construction.
void mark_referenced_instructions(SgAsmInterpretation *, const MemoryMap::Ptr &, const InstructionMap &)
Marks parts of the file that correspond to instructions as having been referenced.
virtual ByteOrder::Endianness byteOrder() const
Property: Byte order of memory.
AddressSet get_block_successors(const InstructionMap &, bool &complete)
Calculates the successor addresses of a basic block and adds them to a successors set.
Describes (part of) a physical CPU register.
Base class for reference counted objects.
Base class for machine instructions.
Represents an interpretation of a binary container.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
The ROSE library.