ROSE 0.11.145.147
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Rose::BinaryAnalysis::SRecord Class Reference

Description

S-Record hexadecimal data formats.

An S-Record is a simple ASCII-based format for conveying binary information, usually used for loading code and data onto an embedded processor. Multiple versions of S-Record formats exist, with the most popular being a Motorola syntax and an Intel syntax.

The Motorola S-Record format is also known as SRECORD, SREC, S19, S28, and S37. The "S19" name comes from the fact that record types 1 and 9 are used, allowing for 16-bit addresses; "s28" are record types 2 and 8 which allow 24-bit addresses; and "s37" are record types 3 and 7 which allow 32-bit addresses.

The Intel HEX format is another variant of S-Records. The sub-formats "I8HEX", "I16HEX", and "I32HEX" describe the address sizes that are supported, namely 16-bit, 20-bit, and 32-bit (note that the number in the format name doesn't actually match the address width in the first two cases).

ROSE's S-Record parser doesn't restrict which record types can appear within a file – it just parses whatever you hand it and returns a vector of SRecord objects. In fact, it will even allow the input to contain a mixture of Motorola and Intel syntax, although it will mark the less frequently-occuring syntax as errors. If any parsing errors are encountered, they are indicated within the individual SRecord objects.

Definition at line 37 of file SRecord.h.

#include <Rose/BinaryAnalysis/SRecord.h>

Classes

class  RunLengthEncoding
 Run-length encoding information. More...
 

Public Types

enum  Syntax {
  SREC_MOTOROLA ,
  SREC_INTEL ,
  SREC_UNKNOWN_SYNTAX
}
 Syntax of the S-Record. More...
 
enum  Type {
  SREC_M_HEADER ,
  SREC_M_DATA16 ,
  SREC_M_DATA24 ,
  SREC_M_DATA32 ,
  SREC_M_RESERVED ,
  SREC_M_COUNT16 ,
  SREC_M_COUNT24 ,
  SREC_M_START32 ,
  SREC_M_START24 ,
  SREC_M_START16 ,
  SREC_I_DATA ,
  SREC_I_END ,
  SREC_I_EXTENDED_SA ,
  SREC_I_START_SA ,
  SREC_I_EXTENDED_LA ,
  SREC_I_START_LA ,
  SREC_UNKNOWN_TYPE
}
 Type of S-Record. More...
 

Public Member Functions

 SRecord ()
 Construct an empty S-Record.
 
std::string toString () const
 Convert an S-Record to a string.
 
Syntax syntax () const
 Property: syntax family.
 
 SRecord (Type type, rose_addr_t addr, const std::vector< uint8_t > data)
 Construct an S-Record with data.
 
 SRecord (Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
 Construct an S-Record with data.
 
Type type () const
 Property: record type.
 
SRecordtype (Type type)
 Property: record type.
 
rose_addr_t address () const
 Property: record starting address.
 
SRecordaddress (rose_addr_t addr)
 Property: record starting address.
 
const std::vector< uint8_t > & data () const
 Property: record data.
 
std::vector< uint8_t > & data ()
 Property: record data.
 
SRecorddata (const std::vector< uint8_t > &data)
 Property: record data.
 
const std::string & error () const
 Property: record error messsage.
 
SRecorderror (const std::string &error)
 Property: record error messsage.
 

Static Public Member Functions

static SRecord parse (const std::string &)
 Construct an S-Record by parsing a string.
 
static std::vector< SRecordparse (std::istream &)
 Construct S-Records by parsing a file.
 
static AddressIntervalSet dataAddresses (const std::vector< SRecord > &)
 Addresses occupied by all data.
 
static AddressIntervalSet createSegments (const std::vector< SRecord > &, const MemoryMapPtr &map, rose_addr_t alignment, unsigned accessPermissions, const std::string &segmentName, MemoryMap::Clobber clobber)
 Create segments for S-Records.
 
static Sawyer::Optional< rose_addr_t > load (const std::vector< SRecord > &, const MemoryMapPtr &)
 Load S-Records into a memory map.
 
static Sawyer::Optional< rose_addr_t > load (const std::vector< SRecord > &, const MemoryMapPtr &, rose_addr_t alignment, unsigned accessPerms, const std::string &name, MemoryMap::Clobber)
 Load S-Records into a memory map, creating segments if necessary.
 
static std::vector< SRecordcreate (const MemoryMapPtr &, Syntax, size_t bytesPerRecord=28, size_t preferredAddrSize=4)
 Create S-Records from a memory map.
 
static SRecord parseMotorola (const std::string &)
 Construct a Motorola S-Record by parsing a string.
 
static SRecord parseIntel (const std::string &)
 Construct an Intel S-Record by parsing a string.
 
static Sawyer::Optional< rose_addr_t > parseBigEndianInteger (const std::string &, size_t start, size_t nChars)
 Parse a hexadecimal string to an unsigned integer.
 
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.
 
static size_t addressNBytes (Type)
 Size of address in bytes.
 
static uint8_t checksum (Syntax, const std::string &, size_t start, size_t n)
 Compute a checksum for part of a record.
 
void print (std::ostream &) const
 Print an S-Record to a stream.
 

Member Enumeration Documentation

◆ Syntax

Syntax of the S-Record.

Enumerator
SREC_MOTOROLA 

Motorola syntax S-Record.

SREC_INTEL 

Intel syntax S-Record.

SREC_UNKNOWN_SYNTAX 

Unknown or no syntax.

Definition at line 40 of file SRecord.h.

◆ Type

Type of S-Record.

Enumerator
SREC_M_HEADER 

Motorola vendor-specific header, usually NUL-terminated ASCII.

SREC_M_DATA16 

Motorola data with 16-bit address.

SREC_M_DATA24 

Motorola data with 24-bit address.

SREC_M_DATA32 

Motorola data with 32-bit address.

SREC_M_RESERVED 

Motorola reserved.

SREC_M_COUNT16 

Motorola 16-bit count of data records.

SREC_M_COUNT24 

Motorola 24-bit count of data records.

SREC_M_START32 

Motorola 32-bit starting address.

SREC_M_START24 

Motorola 24-bit starting address.

SREC_M_START16 

Motorola 16-bit starting address.

SREC_I_DATA 

Intel data record.

SREC_I_END 

Intel end record.

SREC_I_EXTENDED_SA 

Intel extended segment address.

SREC_I_START_SA 

Intel starting segment address.

SREC_I_EXTENDED_LA 

Intel extended linear address.

SREC_I_START_LA 

Intel starting linear address.

SREC_UNKNOWN_TYPE 

Not a valid S-Record.

Definition at line 47 of file SRecord.h.

Constructor & Destructor Documentation

◆ SRecord() [1/3]

Rose::BinaryAnalysis::SRecord::SRecord ( )
inline

Construct an empty S-Record.

Definition at line 82 of file SRecord.h.

◆ SRecord() [2/3]

Rose::BinaryAnalysis::SRecord::SRecord ( Type  type,
rose_addr_t  addr,
const std::vector< uint8_t >  data 
)
inline

Construct an S-Record with data.

Definition at line 87 of file SRecord.h.

◆ SRecord() [3/3]

Rose::BinaryAnalysis::SRecord::SRecord ( Type  type,
rose_addr_t  addr,
const uint8_t *  buffer,
size_t  bufsz 
)
inline

Construct an S-Record with data.

Definition at line 89 of file SRecord.h.

Member Function Documentation

◆ parse() [1/2]

static SRecord Rose::BinaryAnalysis::SRecord::parse ( const std::string &  )
static

Construct an S-Record by parsing a string.

This parses either a Motorola or Intel syntax S-Record.

◆ parse() [2/2]

static std::vector< SRecord > Rose::BinaryAnalysis::SRecord::parse ( std::istream &  )
static

Construct S-Records by parsing a file.

Returns a vector with one element per line of input. Lines that did not contain an S-Record or which had trailing characters other than white space are reported as SRecord objects of type SREC_NONE and an error message.

◆ dataAddresses()

static AddressIntervalSet Rose::BinaryAnalysis::SRecord::dataAddresses ( const std::vector< SRecord > &  )
static

Addresses occupied by all data.

The specified S-Records are scanned in order to create the set of memory addresses that the data will occupy, and this set is returned.

◆ createSegments()

static AddressIntervalSet Rose::BinaryAnalysis::SRecord::createSegments ( const std::vector< SRecord > &  ,
const MemoryMapPtr map,
rose_addr_t  alignment,
unsigned  accessPermissions,
const std::string &  segmentName,
MemoryMap::Clobber  clobber 
)
static

Create segments for S-Records.

The specified memory map is modified to create mapped regions for the specified S-Records using the minimum possible number of segments. First, the S-Records are scanned to obtain a list of addresses. These addresses are expanded by aligning their beginning and ending locations. Then a temporary memory map is created that contains the minimum number of aligned segments necessary to represent all the S-Record data. The created segments have the specified access permissions and names. Finally, the segments are copied into the original map by calling MemoryMap::linkTo and passing the specified clobber flag. The temporary map is deleted, but since buffers are reference counted, they will continue to exist if referenced by the specified map.

The return value is the set of addresses that were added to the map.

◆ load() [1/2]

static Sawyer::Optional< rose_addr_t > Rose::BinaryAnalysis::SRecord::load ( const std::vector< SRecord > &  ,
const MemoryMapPtr  
)
static

Load S-Records into a memory map.

The data from the specified S-Records are loaded into the specified memory map. The map must contains segments at all S-Record addresses or else a MemoryMap::NotMapped exception is thrown. The return value is the execution starting address contained in the S-Records, if any.

◆ load() [2/2]

static Sawyer::Optional< rose_addr_t > Rose::BinaryAnalysis::SRecord::load ( const std::vector< SRecord > &  ,
const MemoryMapPtr ,
rose_addr_t  alignment,
unsigned  accessPerms,
const std::string &  name,
MemoryMap::Clobber   
)
static

Load S-Records into a memory map, creating segments if necessary.

This is a convenience function that calls createSegments in order to create any necessary segments in the memory map, and then calls the two-argument version of load in order to load the S-Record data into those segments. Therefore, the arguments are the union of the arguments for those two functions.

◆ syntax()

Syntax Rose::BinaryAnalysis::SRecord::syntax ( ) const

Property: syntax family.

This is a read-only property computed from the record type.

◆ type() [1/2]

Type Rose::BinaryAnalysis::SRecord::type ( ) const
inline

Property: record type.

Definition at line 170 of file SRecord.h.

◆ type() [2/2]

SRecord & Rose::BinaryAnalysis::SRecord::type ( Type  type)
inline

Property: record type.

Definition at line 171 of file SRecord.h.

References type().

Referenced by type().

◆ address() [1/2]

rose_addr_t Rose::BinaryAnalysis::SRecord::address ( ) const
inline

Property: record starting address.

Note that Intel S-Record addresses are only partially specified in the individual S-Records; the actual full address depends on the S-Records that came before it. This property is only the partial address for Intel S-Records.

See also, RunLengthEncoding::dataAddress to get the fully specified address.

Definition at line 182 of file SRecord.h.

◆ address() [2/2]

SRecord & Rose::BinaryAnalysis::SRecord::address ( rose_addr_t  addr)
inline

Property: record starting address.

Note that Intel S-Record addresses are only partially specified in the individual S-Records; the actual full address depends on the S-Records that came before it. This property is only the partial address for Intel S-Records.

See also, RunLengthEncoding::dataAddress to get the fully specified address.

Definition at line 183 of file SRecord.h.

◆ data() [1/3]

const std::vector< uint8_t > & Rose::BinaryAnalysis::SRecord::data ( ) const
inline

Property: record data.

Definition at line 189 of file SRecord.h.

◆ data() [2/3]

std::vector< uint8_t > & Rose::BinaryAnalysis::SRecord::data ( )
inline

Property: record data.

Definition at line 190 of file SRecord.h.

◆ data() [3/3]

SRecord & Rose::BinaryAnalysis::SRecord::data ( const std::vector< uint8_t > &  data)
inline

Property: record data.

Definition at line 191 of file SRecord.h.

References data().

Referenced by data().

◆ error() [1/2]

const std::string & Rose::BinaryAnalysis::SRecord::error ( ) const
inline

Property: record error messsage.

Definition at line 197 of file SRecord.h.

◆ error() [2/2]

SRecord & Rose::BinaryAnalysis::SRecord::error ( const std::string &  error)
inline

Property: record error messsage.

Definition at line 198 of file SRecord.h.

References error().

Referenced by error().

◆ parseBigEndianInteger()

static Sawyer::Optional< rose_addr_t > Rose::BinaryAnalysis::SRecord::parseBigEndianInteger ( const std::string &  ,
size_t  start,
size_t  nChars 
)
static

Parse a hexadecimal string to an unsigned integer.

The parsing looks at characters of the string starting at the specified offset and continuing for the specified number of characters. Each character in that range must be a valid hexadecimal digit representing four bits of the result in big-endian order. Returns the unsigned value if successful, or nothing if a syntax error, short read, or overflow is encountered.

◆ addressNBytes()

static size_t Rose::BinaryAnalysis::SRecord::addressNBytes ( Type  )
static

Size of address in bytes.

The address is encoded in twice as many ASCII characters.

◆ checksum()

static uint8_t Rose::BinaryAnalysis::SRecord::checksum ( Syntax  ,
const std::string &  ,
size_t  start,
size_t  n 
)
static

Compute a checksum for part of a record.

Given a string, compute the checksum for the hexadecimal characters starting with the specified start offset and continuing for n characters. All characters in the range must be hexadecimal digits, and n must be even.


The documentation for this class was generated from the following file: