1 #ifndef ROSE_BinaryAnalysis_Disassembler_H
2 #define ROSE_BinaryAnalysis_Disassembler_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/CallingConvention.h>
7 #include <Rose/BinaryAnalysis/Unparser/Settings.h>
8 #include <Rose/Diagnostics.h>
9 #include <Rose/BinaryAnalysis/MemoryMap.h>
10 #include <Rose/BinaryAnalysis/Registers.h>
11 #include "Rose/Exception.h"
12 #include "integerOps.h"
14 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics.h>
16 #include <boost/serialization/access.hpp>
17 #include <boost/serialization/string.hpp>
18 #include <boost/serialization/version.hpp>
26 namespace BinaryAnalysis {
66 Exception(
const std::string &reason, rose_addr_t
ip,
const SgUnsignedCharList &raw_data,
size_t bit)
77 void print(std::ostream&)
const;
78 friend std::ostream& operator<<(std::ostream &o,
const Exception &e);
118 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
120 friend class boost::serialization::access;
123 void serialize(S &s,
const unsigned version) {
124 s & BOOST_SERIALIZATION_NVP(p_registers);
125 s & BOOST_SERIALIZATION_NVP(REG_IP);
126 s & BOOST_SERIALIZATION_NVP(REG_SS);
128 s & BOOST_SERIALIZATION_NVP(REG_SF);
129 s & BOOST_SERIALIZATION_NVP(p_byteOrder);
130 s & BOOST_SERIALIZATION_NVP(p_wordSizeBytes);
131 s & BOOST_SERIALIZATION_NVP(p_name);
133 s & BOOST_SERIALIZATION_NVP(instructionAlignment_);
142 Disassembler(): p_registers(NULL), p_byteOrder(
ByteOrder::ORDER_LSB), p_wordSizeBytes(4), instructionAlignment_(1) {}
143 virtual ~Disassembler() {}
176 const std::string&
name()
const {
179 void name(
const std::string &s) {
188 static std::vector<std::string>
isaNames();
224 void byteOrder(ByteOrder::Endianness sex) { p_byteOrder = sex; }
269 ASSERT_forbid(REG_IP.
isEmpty());
275 ASSERT_forbid(REG_SP.
isEmpty());
358 static void initclass();
359 static void initclassHelper();
366 static SgAsmInstruction *find_instruction_containing(
const InstructionMap &insns, rose_addr_t va);
void registerDictionary(const RegisterDictionary *rdict)
Properties: Register dictionary.
virtual SgAsmInstruction * makeUnknownInstruction(const Exception &)=0
Makes an unknown instruction from an exception.
size_t wordSizeBytes() const
Property: Basic word size in bytes.
AddressSet get_block_successors(const InstructionMap &, bool &complete)
Calculates the successor addresses of a basic block and adds them to a successors set...
const RegisterDictionary * registerDictionary() const
Properties: Register dictionary.
rose_addr_t ip
Virtual address where failure occurred; zero if no associated instruction.
Map< rose_addr_t, SgAsmInstruction * > InstructionMap
The InstructionMap is a mapping from (absolute) virtual address to disassembled instruction.
Base class for machine instructions.
static Sawyer::Message::Facility mlog
Disassembler diagnostic streams.
size_t bit
Bit offset in instruction byte sequence where disassembly failed (bit/8 is the index into the "bytes"...
ByteOrder::Endianness p_byteOrder
Byte order of instructions in memory.
void mark_referenced_instructions(SgAsmInterpretation *, const MemoryMap::Ptr &, const InstructionMap &)
Marks parts of the file that correspond to instructions as having been referenced.
const std::string & name() const
Property: Name by which disassembler is registered.
const RegisterDictionary * p_registers
Description of registers available for this platform.
SgAsmInstruction * insn
Instruction associated with an assembly error.
virtual RegisterDescriptor stackFrameRegister() const
Returns the register that ponts to the stack frame.
Main namespace for the ROSE library.
virtual RegisterDescriptor stackSegmentRegister() const
Returns the segment register for accessing the stack.
Exception(const std::string &reason, SgAsmInstruction *insn)
An exception bound to a particular instruction being assembled.
Exception(const std::string &reason, rose_addr_t ip, const SgUnsignedCharList &raw_data, size_t bit)
An exception bound to a particular instruction being disassembled.
void callingConventions(const CallingConvention::Dictionary &d)
Properties: Register dictionary.
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...
ByteOrder::Endianness byteOrder() const
Property: Byte order of instructions in memory.
static std::vector< std::string > isaNames()
List of names recognized by lookup.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
size_t instructionAlignment() const
Property: Instruction alignment requirement.
virtual RegisterDescriptor instructionPointerRegister() const
Returns the register that points to instructions.
virtual RegisterDescriptor callReturnRegister() const
Returns the register that holds the return address for a function.
InstructionSemantics2::BaseSemantics::DispatcherPtr p_proto_dispatcher
Prototypical dispatcher for creating real dispatchers.
std::vector< Definition::Ptr > Dictionary
A ordered collection of calling convention definitions.
Exception(const std::string &reason)
A bare exception not bound to any particular instruction.
virtual Disassembler * clone() const =0
Creates a new copy of a disassembler.
std::string p_name
Name by which this dissassembler is registered.
Describes (part of) a physical CPU register.
size_t p_wordSizeBytes
Basic word size in bytes.
size_t instructionAlignment_
Positive alignment constraint for instruction addresses.
Exception(const std::string &reason, rose_addr_t ip)
An exception bound to a virtual address but no raw data or instruction.
static Disassembler * lookup(SgAsmGenericHeader *)
Finds a suitable disassembler.
virtual bool canDisassemble(SgAsmGenericHeader *) const =0
Predicate determining the suitability of a disassembler for a specific file header.
RegisterDescriptor REG_LINK
Register descriptors initialized during construction.
void byteOrder(ByteOrder::Endianness sex)
Property: Byte order of instructions in memory.
const CallingConvention::Dictionary & callingConventions() const
Property: Calling convention dictionary.
CallingConvention::Dictionary & callingConventions()
Properties: Register dictionary.
const Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::DispatcherPtr & dispatcher() const
Return an instruction semantics dispatcher if possible.
static void registerSubclass(Disassembler *)
Register a disassembler instance.
SgUnsignedCharList bytes
Bytes (partial) of failed disassembly, including byte at failure.
Exception thrown by the disassemblers.
Defines registers available for a particular architecture.
static std::vector< Disassembler * > disassemblers
List of disassembler subclasses.
virtual RegisterDescriptor stackPointerRegister() const
Returns the register that points to the stack.
Base class for all ROSE exceptions.
bool isEmpty() const
Predicate returns true if the width is zero.
Represents an interpretation of a binary container.
Virtual base class for instruction disassemblers.
void wordSizeBytes(size_t nbytes)
Property: Basic word size in bytes.
static void initDiagnostics()
Initializes and registers disassembler diagnostic streams.
void name(const std::string &s)
Property: Name by which disassembler is registered.
virtual Unparser::BasePtr unparser() const =0
Unparser.