ROSE  0.9.13.72
SRecord.h
1 #ifndef ROSE_BinaryFormats_SRecord_H
2 #define ROSE_BinaryFormats_SRecord_H
3 
4 namespace Rose {
5 namespace BinaryAnalysis {
6 
25 class SRecord {
26 public:
28  enum Syntax {
32  };
33 
35  enum Type {
36  // Motorola
48  // Intel
57  };
58 
59 private:
60  Type type_;
61  rose_addr_t addr_;
62  std::vector<uint8_t> data_;
63  std::string error_;
64 
66  // Constructors, etc.
68 public:
70  SRecord(): type_(SREC_UNKNOWN_TYPE), addr_(0) {}
71 
75  SRecord(Type type, rose_addr_t addr, const std::vector<uint8_t> data)
76  : type_(type), addr_(addr), data_(data) {}
77  SRecord(Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
78  : type_(type), addr_(addr), data_(buffer+0, buffer+bufsz) {}
82  // High-level functions.
85 public:
89  static SRecord parse(const std::string&);
90 
95  static std::vector<SRecord> parse(std::istream&);
96 
101  static AddressIntervalSet dataAddresses(const std::vector<SRecord>&);
102 
114  load(const std::vector<SRecord>&, const MemoryMap::Ptr&, bool createSegments=true,
115  unsigned accessPerms=MemoryMap::READABLE|MemoryMap::WRITABLE|MemoryMap::EXECUTABLE,
116  const std::string &newSegmentNames = "S-Records");
117 
119  static std::vector<SRecord> create(const MemoryMap::Ptr&, Syntax, size_t bytesPerRecord=28, size_t preferredAddrSize=4);
120 
122  std::string toString() const;
123 
127  void print(std::ostream&) const;
128  friend std::ostream& operator<<(std::ostream&, const SRecord&);
131  // S-Record properties.
134 public:
138  Syntax syntax() const;
139 
143  Type type() const { return type_; }
144  SRecord& type(Type type) { type_ = type; return *this; }
155  rose_addr_t address() const { return addr_; }
156  SRecord& address(rose_addr_t addr) { addr_ = addr; return *this; }
162  const std::vector<uint8_t>& data() const { return data_; }
163  std::vector<uint8_t>& data() { return data_; }
164  SRecord& data(const std::vector<uint8_t>& data) { data_ = data; return *this; }
170  const std::string& error() const { return error_; }
171  SRecord& error(const std::string &error) { error_ = error; return *this; }
176  // Low-level functions.
179 public:
182  Sawyer::Optional<rose_addr_t> dataVa_, executionVa_;
183  size_t nDataRecords_;
184  public:
187  : nDataRecords_(0) {}
188 
192  void insert(const SRecord&);
193 
196 
200  rose_addr_t baseDataAddress() const;
201 
204 
206  size_t nDataRecords() const { return nDataRecords_; }
207  };
208 
210  static SRecord parseMotorola(const std::string&);
211 
213  static SRecord parseIntel(const std::string&);
214 
221  static Sawyer::Optional<rose_addr_t> parseBigEndianInteger(const std::string&, size_t start, size_t nChars);
222 
224  static unsigned bigEndian(const std::vector<uint8_t> &data, size_t nBytes);
225 
229  static size_t addressNBytes(Type);
230 
235  static uint8_t checksum(Syntax, const std::string&, size_t start, size_t n);
236 };
237 
238 } // namespace
239 } // namespace
240 
241 #endif
static Sawyer::Optional< rose_addr_t > parseBigEndianInteger(const std::string &, size_t start, size_t nChars)
Parse a hexadecimal string to an unsigned integer.
const std::string & error() const
Property: record error messsage.
Definition: SRecord.h:170
Motorola 16-bit count of data records.
Definition: SRecord.h:42
Motorola 24-bit starting address.
Definition: SRecord.h:45
static unsigned bigEndian(const std::vector< uint8_t > &data, size_t nBytes)
Convert the first few bytes of the buffer to a big-endian integer.
rose_addr_t address() const
Property: record starting address.
Definition: SRecord.h:155
void print(std::ostream &) const
Print an S-Record to a stream.
SRecord & address(rose_addr_t addr)
Property: record starting address.
Definition: SRecord.h:156
static SRecord parse(const std::string &)
Construct an S-Record by parsing a string.
Intel starting linear address.
Definition: SRecord.h:54
Intel extended linear address.
Definition: SRecord.h:53
const std::vector< uint8_t > & data() const
Property: record data.
Definition: SRecord.h:162
Motorola 32-bit starting address.
Definition: SRecord.h:44
Motorola data with 16-bit address.
Definition: SRecord.h:38
Motorola data with 32-bit address.
Definition: SRecord.h:40
static size_t addressNBytes(Type)
Size of address in bytes.
static SRecord parseMotorola(const std::string &)
Construct a Motorola S-Record by parsing a string.
SRecord()
Construct an empty S-Record.
Definition: SRecord.h:70
Main namespace for the ROSE library.
static std::vector< SRecord > create(const MemoryMap::Ptr &, Syntax, size_t bytesPerRecord=28, size_t preferredAddrSize=4)
Create S-Records from a memory map.
Motorola data with 24-bit address.
Definition: SRecord.h:39
friend std::ostream & operator<<(std::ostream &, const SRecord &)
Print an S-Record to a stream.
Motorola 24-bit count of data records.
Definition: SRecord.h:43
Sawyer::Optional< rose_addr_t > executionAddress() const
Returns the execution starting address if one was specified.
Intel extended segment address.
Definition: SRecord.h:51
S-Record hexadecimal data formats.
Definition: SRecord.h:25
std::vector< uint8_t > & data()
Property: record data.
Definition: SRecord.h:163
Syntax syntax() const
Property: syntax family.
Intel starting segment address.
Definition: SRecord.h:52
static Sawyer::Optional< rose_addr_t > load(const std::vector< SRecord > &, const MemoryMap::Ptr &, bool createSegments=true, unsigned accessPerms=MemoryMap::READABLE|MemoryMap::WRITABLE|MemoryMap::EXECUTABLE, const std::string &newSegmentNames="S-Records")
Load S-Records into a memory map.
static uint8_t checksum(Syntax, const std::string &, size_t start, size_t n)
Compute a checksum for part of a record.
Motorola 16-bit starting address.
Definition: SRecord.h:46
Sawyer::Optional< rose_addr_t > dataAddress(const SRecord &) const
Returns the memory address for the start of a data record, or nothing.
Motorola syntax S-Record.
Definition: SRecord.h:29
Type
Type of S-Record.
Definition: SRecord.h:35
SRecord & error(const std::string &error)
Property: record error messsage.
Definition: SRecord.h:171
std::string toString() const
Convert an S-Record to a string.
SRecord(Type type, rose_addr_t addr, const std::vector< uint8_t > data)
Construct an S-Record with data.
Definition: SRecord.h:75
static AddressIntervalSet dataAddresses(const std::vector< SRecord > &)
Addresses occupied by all data.
SRecord(Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
Construct an S-Record with data.
Definition: SRecord.h:77
SRecord & data(const std::vector< uint8_t > &data)
Property: record data.
Definition: SRecord.h:164
Run-length encoding information.
Definition: SRecord.h:181
void insert(const SRecord &)
Insert an S-Record into the data sumarized by this class.
static SRecord parseIntel(const std::string &)
Construct an Intel S-Record by parsing a string.
Type type() const
Property: record type.
Definition: SRecord.h:143
SRecord & type(Type type)
Property: record type.
Definition: SRecord.h:144
size_t nDataRecords() const
Number of data records seen.
Definition: SRecord.h:206
rose_addr_t baseDataAddress() const
Base data address.
Syntax
Syntax of the S-Record.
Definition: SRecord.h:28
Motorola vendor-specific header, usually NUL-terminated ASCII.
Definition: SRecord.h:37