ROSE 0.11.145.237
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#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
19#include <boost/serialization/access.hpp>
20#include <boost/serialization/string.hpp>
21#include <boost/serialization/version.hpp>
22#endif
23
24// REG_SP possibly defined on __sun
25// REG_LINK possibly defined on Windows
26#undef REG_SP
27#undef REG_LINK
28
29namespace Rose {
30namespace BinaryAnalysis {
31namespace Disassembler {
32
52 // Types
54public:
55 using Ptr = BasePtr;
56
58 // Data members
60private:
61 Architecture::BaseConstPtr architecture_;
62
63protected:
64 RegisterDescriptor REG_IP, REG_SP, REG_SS, REG_SF, REG_LINK;
67public:
68
69
71 // Serialization
73#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
74private:
75 friend class boost::serialization::access;
76
77 template<class S>
78 void serialize(S &s, const unsigned version) {
79 s & BOOST_SERIALIZATION_NVP(REG_IP);
80 s & BOOST_SERIALIZATION_NVP(REG_SS);
81 if (version >= 1)
82 s & BOOST_SERIALIZATION_NVP(REG_SF);
83 if (version >= 2)
84 s & BOOST_SERIALIZATION_NVP(instructionAlignment_);
85 }
86#endif
87
88
90 // Constructors
92protected:
93 explicit Base(const Architecture::BaseConstPtr&);
94
95public:
96 virtual ~Base();
97
101 virtual Ptr clone() const = 0;
102
103
104 /***************************************************************************************************************************
105 * Disassembler properties and settings
106 ***************************************************************************************************************************/
107public:
112
116 virtual const std::string& name() const;
117
119 virtual size_t bytesPerWord() const;
120
123
129
133 size_t instructionAlignment() const;
134
135
136 /***************************************************************************************************************************
137 * Instruction disassembly functions
138 ***************************************************************************************************************************/
139public:
150 virtual SgAsmInstruction *disassembleOne(const MemoryMap::Ptr &map, Address start_va, AddressSet *successors=NULL) = 0;
151
158 SgAsmInstruction *disassembleOne(const unsigned char *buf, Address buf_va, size_t buf_size, Address start_va,
159 AddressSet *successors=NULL);
160
161
162 /***************************************************************************************************************************
163 * Miscellaneous methods
164 ***************************************************************************************************************************/
165public:
170
175
181 AddressSet get_block_successors(const InstructionMap&, bool &complete/*out*/);
182
189
191 // Deprecated [Robb Matzke 2023-11-24]
193public:
194 size_t wordSizeBytes() const ROSE_DEPRECATED("use bytesPerWord()");
195 RegisterDictionaryPtr registerDictionary() const ROSE_DEPRECATED("use architecture()");
196 virtual RegisterDescriptor instructionPointerRegister() const ROSE_DEPRECATED("use architecture()");
197 virtual RegisterDescriptor stackPointerRegister() const ROSE_DEPRECATED("use architecture()");
198 virtual RegisterDescriptor stackFrameRegister() const ROSE_DEPRECATED("use architecture()");
199 virtual RegisterDescriptor stackSegmentRegister() const ROSE_DEPRECATED("use architecture()");
200 virtual RegisterDescriptor callReturnRegister() const ROSE_DEPRECATED("use architecture()");
201};
202
203} // namespace
204} // namespace
205} // namespace
206
207// Class versions must be at global scope
208#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
209BOOST_CLASS_VERSION(Rose::BinaryAnalysis::Disassembler::Base, 3);
210#endif
211
212#endif
213#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 SgAsmInstruction * disassembleOne(const MemoryMap::Ptr &map, Address start_va, AddressSet *successors=NULL)=0
This is the lowest level disassembly function and is implemented in the architecture-specific subclas...
virtual const std::string & name() const
Property: Name.
SgAsmInstruction * disassembleOne(const unsigned char *buf, Address buf_va, size_t buf_size, Address start_va, AddressSet *successors=NULL)
Similar in functionality to the disassembleOne method that takes a MemoryMap argument,...
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.
static SgAsmInstruction * find_instruction_containing(const InstructionMap &insns, Address va)
Finds the highest-address instruction that contains the byte at the specified virtual address.
Architecture::BaseConstPtr architecture() const
Property: Architecture.
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.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.