ROSE  0.9.9.139
SRecord.h
1 #ifndef ROSE_BinaryFormats_SRecord_H
2 #define ROSE_BinaryFormats_SRecord_H
3 
4 namespace Rose {
5 namespace BinaryAnalysis {
6 
15 class SRecord {
16 public:
18  enum Type {
19  // The values listed explicitly are important as they are part of a standard.
31  };
32 
33 private:
34  Type type_;
35  rose_addr_t addr_;
36  std::vector<uint8_t> data_;
37  std::string error_;
38 
39 public:
41  SRecord(): type_(SREC_NONE), addr_(0) {}
42 
46  SRecord(Type type, rose_addr_t addr, const std::vector<uint8_t> data)
47  : type_(type), addr_(addr), data_(data) {}
48  SRecord(Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
49  : type_(type), addr_(addr), data_(buffer+0, buffer+bufsz) {}
54  static SRecord parse(const std::string&);
55 
60  static std::vector<SRecord> parse(std::istream&);
61 
65  Type type() const { return type_; }
66  SRecord& type(Type type) { type_ = type; return *this; }
72  rose_addr_t address() const { return addr_; }
73  SRecord& address(rose_addr_t addr) { addr_ = addr; return *this; }
79  const std::vector<uint8_t>& data() const { return data_; }
80  std::vector<uint8_t>& data() { return data_; }
81  SRecord& data(const std::vector<uint8_t>& data) { data_ = data; return *this; }
87  const std::string& error() const { return error_; }
88  SRecord& error(const std::string &error) { error_ = error; return *this; }
94  static size_t addressNBytes(Type);
95 
100  size_t encodedSize() const;
101 
109  static rose_addr_t load(const std::vector<SRecord>&, const MemoryMap::Ptr&, bool createSegments=true,
110  unsigned accessPerms=MemoryMap::READABLE|MemoryMap::WRITABLE|MemoryMap::EXECUTABLE,
111  const std::string &newSegmentNames = "S-Records");
112 
116  uint8_t checksum() const;
117 
121  void print(std::ostream&) const;
122  friend std::ostream& operator<<(std::ostream&, const SRecord&);
132  static size_t dump(const MemoryMap::Ptr&, std::ostream&, size_t addrSize=4);
133 };
134 
135 } // namespace
136 } // namespace
137 
138 #endif
Data with 16-bit address.
Definition: SRecord.h:21
const std::string & error() const
Accessor for the S-Record error message.
Definition: SRecord.h:87
rose_addr_t address() const
Accessor for the S-Record address.
Definition: SRecord.h:72
void print(std::ostream &) const
Print an S-Record to a stream.
SRecord & address(rose_addr_t addr)
Accessor for the S-Record address.
Definition: SRecord.h:73
static SRecord parse(const std::string &)
Construct an S-Record by parsing a string.
const std::vector< uint8_t > & data() const
Accessor for the S-Record data.
Definition: SRecord.h:79
uint8_t checksum() const
Compute the checksum for the data.
static 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 size_t addressNBytes(Type)
Size of address in bytes.
Data with 32-bit address.
Definition: SRecord.h:23
SRecord()
Construct an empty S-Record.
Definition: SRecord.h:41
Main namespace for the ROSE library.
friend std::ostream & operator<<(std::ostream &, const SRecord &)
Print an S-Record to a stream.
Motorola S-Record.
Definition: SRecord.h:15
std::vector< uint8_t > & data()
Accessor for the S-Record data.
Definition: SRecord.h:80
24-bit count of data records.
Definition: SRecord.h:26
32-bit starting address.
Definition: SRecord.h:27
Type
Type of S-Record.
Definition: SRecord.h:18
SRecord & error(const std::string &error)
Accessor for the S-Record error message.
Definition: SRecord.h:88
SRecord(Type type, rose_addr_t addr, const std::vector< uint8_t > data)
Construct an S-Record with data.
Definition: SRecord.h:46
static size_t dump(const MemoryMap::Ptr &, std::ostream &, size_t addrSize=4)
Dump a memory map as S-Records.
SRecord(Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
Construct an S-Record with data.
Definition: SRecord.h:48
SRecord & data(const std::vector< uint8_t > &data)
Accessor for the S-Record data.
Definition: SRecord.h:81
16-bit count of data records.
Definition: SRecord.h:25
Vendor-specific header, usually NUL-terminated ASCII.
Definition: SRecord.h:20
Data with 24-bit address.
Definition: SRecord.h:22
Type type() const
Accessor for the S-Record type.
Definition: SRecord.h:65
SRecord & type(Type type)
Accessor for the S-Record type.
Definition: SRecord.h:66
size_t encodedSize() const
Size of encoded S-Record in characters.
16-bit starting address.
Definition: SRecord.h:29
24-bit starting address.
Definition: SRecord.h:28